Prerequisites
In Lago:- Create a Lago organization to manage your billing and invoicing;
- Create a Billable metric to track the usage of your customers;
- Create a Plan and price the above billable metric to determine the billing rates for your customers; and
- Create a Customer and assign the Plan.
- Create a Segment account;
- 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:- Navigate to the Catalog in Segment;
- Click the Functions tab to access the custom Functions feature;
- Click Create 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 a request to Lago events
Replace the pre-written functions in the code editor with the code below. This example function, written by the Lago team, catches a Track event from Segment, targets the events endpoint in Lago, builds the body of the request, then posts the event.This function can be adapted with Identify, Group or Page events. Refer to Segment’s documentation for all available actions.
The
body structure of the event depends on your use case. Adapt it if needed, for example by adding or removing properties. You can also add conditions to send data to Lago only on specific events.Use the test mode editor
Use a sample event to preview the incoming data fetched from a Segment event. This helps you post a request for existing data, or debug the function.
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:- Go to the Settings tab;
- Click Add Setting;
- Define a Name and a Label for this setting;
- Define it as Required or Optional; and
- Mark it as Sensitive or not.

Hide sensitive data with settings variables