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.

If you are interested in this example of integration, please contact us at: [email protected].

How can I use my Segment data on Batch?

You can create a custom Destination Function to send attributes and events to Batch.

If you are a Batch Omnichannel or Email client, the sample code will allow you to set up flows to send project-level data using the Profile API.

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.

Segment's testing module
Segment’s testing module

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 or batchProjectApiKey. The REST API Key is sensitive; you must declare it as such.

The Project API Key is optional. It is only necessary if you need to call project-level APIs (e.g., the Profile API).

Settings tab in Segment Functions interface
Settings tab in Segment Functions interface
  • 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.

Batch is now registered as a Destination.
Batch is registered as a Destination

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 :

  1. Create your Destination Function

  2. Create your Destination

  3. 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”

  4. Create your Segment Audience and send its events to the Batch Destination

Steps 1, 2 & 3 must be done only once for the technical setup. Then, your marketing teams only need to follow step 4 to create new audiences.

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).

Segment’s testing module

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 or batchProjectApiKey. The REST API Key is sensitive, you must declare it as such.

The Project API Key is optional. It is only necessary if you need to call project-level APIs (e.g., the Profile API).

Settings tab in Segment Functions interface
  • 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:

creating an audience in progress
Create an audience

🎉 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.

Batch is a Destination of the Audience.
Batch is a Destination of the Audience.

Last updated

Was this helpful?