How to connect Batch to Segment?
Send attributes, events, custom audiences and more from Segment to Batch.
Segment.com is a customer data platform that simplifies data collection by providing a central point for storing and transferring data. We provide an example of integration with Segment so you can send your data directly from Segment to Batch.
This integration uses a Segment feature called Destination Function.
How can I use my Segment data on Batch?
You can create a custom Destination Function to send attributes and events to Batch.
Create a Destination Function
Destination functions allow you to handle your Segment events and send them to any external tool or API, through JavaScript functions, without having to set up an infrastructure.
To create a Destination Function in Segment, navigate through Connections > Catalog > Functions > Destination Functions.
Then, we suggest you use our pre-built script to create your function and adapt it to your use cases.
Segment has a built-in testing module that will help you understand if your Function calls Batch APIs as expected. Try it using your events payloads.

Deploy as a Destination
Once your script is ready, you can Save & Deploy your function to a destination.
Pick one source. It could be any of your sources: iOS, Android, Web, or other.
Declare settings. They are a good option to store your API Keys. To ensure that the script recognizes the API keys, please name them as follows:
batchRestApiKey
,batchLiveApiKey
orbatchProjectApiKey
. The REST API Key is sensitive; you must declare it as such.

Activate the Destination so that data starts flowing between Segment and Batch.
You should note that a Destination is an instance of a Destination Function.
If you have several sources plugged into Segment, you must create one Destination per source. However, you can use the same Function for all Destinations, as long as your events are handled correctly within the Function.

How to send audiences from Segment to Batch?
Here is how you can create a custom Destination Function to send custom audiences to Batch.
You must follow the following steps in that order :
Create your Destination Function
Create your Destination
Create a filter in your Destination. Filter out all events that are not of event type “Track”. You can use “Only Send Event” > “Event Type is track”
Create your Segment Audience and send its events to the Batch Destination
Create a Destination Function
Destination functions allow you to handle your Segment events and send them to any external tool or API, through JavaScript functions and without having to set up an infrastructure.
To create a Destination Function in Segment, navigate through Connections > Catalog > Functions > Destination Functions.
Then we suggest you use our pre-built script to create your function and adapt it to your use cases.
Segment has a built-in testing module that will help you understand if your Function calls Batch APIs as expected. Try it using your audience events payloads (Track and Identify).

Deploy as a Destination
Once your script is ready, you can Save & Deploy your function to a destination.
Pick one source. It could be any of your sources: iOS, Android, Web, or other.
Declare settings. They are a good option to store your API Keys. To ensure that the script recognizes the API keys, please name them as follows:
batchRestApiKey
,batchLiveApiKey
orbatchProjectApiKey
. The REST API Key is sensitive, you must declare it as such.

Activate the Destination so that data starts flowing between Segment and Batch.
You need to deploy one destination for each Batch app (e.g., one destination for the iOS app and one destination for the Android app).
Create your Segment Audience
Pre-requisite: To create Audiences, you need to have created a Unify / Personas space and declared data sources.
In Engage > Audiences, create an audience with the audience builder. You can target events from your data sources and create your audiences accordingly. There are several computing methods available. Please refer to Segment’s Audience Documentation to understand it better.
Once your audience is designed, choose to send events to one or multiple Batch Destinations created beforehand.
In the menu that opens, select "Send Track". Note: The values of the "Enter Event" and "Exit Event" fields don't matter.
Give your audience a name, and the audience creation will be complete:

🎉 Your audience will be initialized in Segment and created in Batch immediately. The audience will be updated in Batch each time a user enters or leaves it.

Last updated
Was this helpful?