Segment
Learn how to ingest events from Segment
What is Segment?
Segment is a Customer Data Platform (CDP). It simplifies collecting and using data from the users of your digital properties (websites, apps, etc.). It allows you to collect, transform, send, and archive your first-party customer data. You can also enrich the customer data you collect by connecting data from your other tools, and then aggregate it to monitor performance, inform decision-making processes, and create uniquely customized user experiences.
All this data can be easily sent to Hyperline to collect your customer’s usage and automate usage-based billing and invoicing.
Send usage from Segment to Hyperline
To facilitate the transmission of usage data to Hyperline, we will generate and use a custom Function within Segment.
Learn more about functions in Segment’s documentation.
Go to the Catalog in Segment, access the Functions tab and click Create Function
Select Destination as the function type and click Build Function
Post request to Hyperline API
Replace the pre-written onTrack
function in the code editor with the following code.
The provided code will catch a Track event from Segment, and post it on Hyperline with the required properties picked from the Segment event.
You can add any properties (with a value of type string, number, boolean, or array of the same types) you want to ingest in Hyperline by adding them in the record
object. The field my_property
is an exemple of an additional property pushed to Hyperline.
This code example will forward all event types to Hyperline. If you want to limit the events sent, you can use the Segment Destination Filters, or alternatively modify the code to filter out the data you don’t want to send.
Configure your secret settings
In the provided code snippet, the API key is a secret configured within the Settings tab on the right panel. This approach helps you refrain from hard-coding private variables directly into the function.
To implement this:
- Click on Add Setting
- Input
API Key
as the label (resulting in the generated nameapiKey
) - Choose the type
String
- Enter your Hyperline API key on the input on the right. You can generate a key with the following guide.
- Toggle the
Required
andSensitive
options - Save your setting
Finalize the creation of the function with a name (“Test Function” in the example below) and an optional description.
After creating the function, you can use it as a Destination of an existing source (in the example below it’s the Backend - Staging
source). Make sure to enable it to start receiving events from Segment in Hyperline.
Was this page helpful?