Segment is a powerful tool that allows you to track the usage of your customers, providing valuable insights that can help you make data-driven decisions. This data can be sent to Lago, our usage-based billing platform, to automate your billing process and ensure accurate invoicing for your customers.
Here’s a step-by-step guide to help you get started:
In Lago:
In Segment:
To accomplish this, you’ll need to create a custom Function in Segment. This can be done by following these simple steps:
Segment Functions
Make sure to select the Destination function, as you want to send data from Segment to Lago.
Destinations function
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.
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
Let’s take back the example from the code written above. We decided to hide the API Key and mark it as sensitive information. By setting this as a variable, you make sure not to hard code your private key in the function.
To create Settings variables:
Hide sensitive data with settings variables
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
If easier, please find a demo video explaining the full setup of custom functions to send event from Segment.com to Lago.
Segment is a powerful tool that allows you to track the usage of your customers, providing valuable insights that can help you make data-driven decisions. This data can be sent to Lago, our usage-based billing platform, to automate your billing process and ensure accurate invoicing for your customers.
Here’s a step-by-step guide to help you get started:
In Lago:
In Segment:
To accomplish this, you’ll need to create a custom Function in Segment. This can be done by following these simple steps:
Segment Functions
Make sure to select the Destination function, as you want to send data from Segment to Lago.
Destinations function
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.
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
Let’s take back the example from the code written above. We decided to hide the API Key and mark it as sensitive information. By setting this as a variable, you make sure not to hard code your private key in the function.
To create Settings variables:
Hide sensitive data with settings variables
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
If easier, please find a demo video explaining the full setup of custom functions to send event from Segment.com to Lago.