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 metered product on that metric, price it with a rate card, and add it to a plan.
- Create a customer and a contract for that customer.
- 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.
- Choose to create your first function and follow the prompts to set it up.

Segment Functions
Use the destination function
Select the Destination function, as you want to send data from Segment to Lago.
Destinations function
Post requests to Lago events
Replace the pre-written code in the editor with the function below. It catches a Track event from Segment, builds a Lago event body and posts it toPOST /api/v2/events. Each event targets a contract through external_contract_id.
transaction_id and code are required. code must match the code of a billable metric. external_contract_id must match the external_id of the contract you bill. The example reads it from a contract_id property on the Segment event. Map it from wherever your tracking plan stores it. For EU-hosted organizations, use https://api.eu.getlago.com/api/v2/events.This function can be adapted to Identify, Group or Page events. Refer to Segment’s documentation for all available actions. The
properties object depends on your billable metric. Add or remove properties, and add conditions to send only specific events to Lago.Use the test mode editor
Use a sample event in the Test panel to preview the data fetched from a Segment event and debug the function before you deploy it.Hide sensitive data
The function reads the API key from a setting instead of hard-coding it. Store it as a sensitive variable. To create Settings variables:- Go to the Settings tab.
- Add a new Setting.
- Define a Name and a Label for this Setting.
- Define it as Required or Optional.
- Mark it as Sensitive.

Hide sensitive data with settings variables
Send usage events to Lago
Run the function in Segment to send a test event to Lago. Check it in the events list or withGET /api/v2/events. Once the setup is finalized in Segment, the function triggers automatically on your defined behavior.
Segment to Lago demo video
This video was recorded with the legacy v1 events payload. Its Segment setup steps still apply. Use the V2 code above for the endpoint and the contract identifier.
Ingest usage
How events target a contract.
Ingest an event
POST /api/v2/events reference.