Integrate with Segment.com

How to integrate with Segment.com?

We already have the possibility to natively retrieve analytics information from Segment. This means that you will get all your tracking information (track/screen/page method) inside your Flagship reports depending on your visitors' assignment. You can follow our support article to better know how our native Segment.com integration works.

Now, you might also want to send data from Flagship to Segment.com, to retrieve them into other tools. Hopefully, the method we're providing will help you reach that goal.

📘 Reminder

The following custom integration isn’t under maintenance. It has been design to be generic, to work on the largest set of cases and codebase. As a Yoda Master developer, you are the king of your own code.

The following code example takes into account that you already started your Flagship SDK and synchronized your user to get the flag (the modification) he should be assigned to. The user is now seeing the flag, and you need to activate it, to alert us and count one more user in the corresponding report. When activating it with our Flagship method, you will trigger the Segment method at the same time and send the information you need to, like in the code example below.

It also implies that you imported the Segment library before calling their method.// ... some other codes

// ... some other codes

Flagship.start("<ENV_ID>", "<API_KEY>", {
  onVisitorExposed: ({ exposedVisitor, fromFlag }) => {
    analytics.track(exposedVisitor.id, 'Flagship_Source_JS', fromFlag.metadata)
  }
})

//... do some stuff

// Then Calling flag.getValue() or flag.visitorExposed() anywhere will trigger onVisitorExposed callback

How to verify the hit in Segment?

After you successfully integrate with Segment, you can check in your Segment's Source Debugger if the hit is correctly sent with all the information needed.

An example of properties passed for an iOS application:

Any feedback? We would be really happy to have a quick chat!

Last updated

Was this helpful?