Skip to main content
Here is how to set it up:

Prerequisites

In Lago:
  1. Create a Lago organization to manage your billing and invoicing;
  2. Create a Billable metric to track the usage of your customers;
  3. Create a Plan and price the above billable metric to determine the billing rates for your customers; and
  4. Create a Customer and assign the Plan.
In Segment:
  1. Create a Segment account;
  2. Create a data source (ideally, product usage of your customer);

Send usage from Segment to Lago

Create a function

Create a custom Function in Segment:
  1. Navigate to the Catalog in Segment;
  2. Click the Functions tab to access the custom Functions feature;
  3. Choose to create your first function and follow the prompts to set it up.

Segment Functions

Use the Destination function

Make sure to select the Destination function, as you want to send data from Segment to Lago.

Destinations function

Post Request to Lago events

To successfully integrate Lago with Segment, you’ll need to replace the pre-written functions in the code editor with the following code. This example function, written by the Lago team, will catch a Track event from Segment, define the targeted endpoint (events) in Lago, build the body of the request, and finally post the event.
This function can be adapted with Identify, Group or Page events. Please, refer to Segment’s documentation for all available actions.
The body structure of the event depends on your use case. Please adapt it if needed (ie: remove or add properties). You can also add conditions if you want to send data to Lago only on specific events.

Use the test mode editor

By using a sample event, you can preview the incoming data fetched from a Segment event. This will help you post a request for existing data or debug.

Segment Sample Events

Hide sensitive data

In the code above, the API key is read from a setting rather than written into the function. Store it as a sensitive variable so your private key is never hard-coded. To create Settings variables:
  1. Go to the Settings tab;
  2. Add a new Setting;
  3. Define a Name and a Label for this Settings;
  4. Define it as Required or Optional; and
  5. Mark it as Sensitive or not.

Hide sensitive data with settings variables

Send usage events to Lago

By running the function in Segment, this will send a test usage to Lago events. You can retrieve this event in the events list. By finalizing the setup in Segment, the function will be automatically triggered based on your defined behavior

Segment to Lago demo video

This video walks through the full custom-function setup for sending events from Segment to Lago.