Integrate with Segment.com
Learn how to integrate Flagship 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.
# Flagship campaign activation
fsVisitor.ActivateModification("my_flag")
# Get Flagship campaign information and send it to Segment
modifInfos, _ := fsVisitor.GetModificationInfo("my_flag")
data := analytics.Track{
UserId: fsVisitor.ID,
Event: "Flagship_Source_Go",
Properties: analytics.NewProperties().
Set("cid", modifInfos.CampaignID).
Set("vgid", modifInfos.VariationGroupID).
Set("vid", modifInfos.VariationID).
Set("isref", modifInfos.IsReference).
Set("val", modifInfos.Value),
}
segmentClient.Enqueue(data)
// Flagship campaign activation
Flagship.Companion.activateModification("my_flag")
// Get Flagship campaign information, map it, and send it to Segment
JSONObject json = Flagship.Companion.getModificationInfo("my_flag");
if (json != null) {
Iterator<String> iterator = json.keys();
HashMap<String, Object> values = new HashMap<>();
while (iterator.hasNext()){
String name = iterator.next();
values.put(name, json.opt(name));
}
Properties properties = new Properties();
properties.putAll(values);
Analytics.with(appContext).track("Flagship_Source_Java", properties);
}
// Flagship campaign activation
fsVisitorInstance.activateModifications([
{ key: "my_flag" }
]);
// Get Flagship campaign information and send it to Segment
fsVisitorInstance.getModificationInfo("my_flag")
.then(campaignInfo => {
analytics.track("#User123", "Flagship_Source_JS", campaignInfo)
})
.catch(error => {
// Process error
});
// Flagship campaign activation
Flagship.activateModification("my_flag")
// Get Flagship campaign information, map it, and send it to Segment
val campaignInfo = Flagship.getModificationInfo("my_flag")
campaignInfo?.keys()?.asSequence()?.associateWith { campaignInfo[it]}?.let { map ->
val properties = Properties()
properties.putAll(map)
Analytics.with(appContext).track("Flagship_Source_Android", properties)
}
// Flagship campaign activation
[[Flagship sharedInstance] activateModificationWithKey:@"my_flag"];
//Get Flagship campaign information and send it to Segment
NSDictionary * campaign_info = [[Flagship sharedInstance] getModificationInfoWithKey:@"my_flag"];
if(campaign_info != nil){
[[SEGAnalytics sharedAnalytics] track:@"Flagship_Source_Objc" properties:campaign_info];
}
# Flagship campaign activation
flagship_visitor.activate_modification("my_flag")
# Get Flagship campaign information and send it to Segment
campaign_info = flagship_visitor.get_modification_info("my_flag")
analytics.track("#User123", "Flagship_Source_Python", campaign_info)
import { useFsActivate } from "@flagship.io/react-sdk";
import { useFsModifications } from "@flagship.io/react-sdk";
// Flagship campaign activation
useFsActivate(["my_flag"]);
// Get Flagship campaign information and send it to Segment
const { my_flag } = useFsModifications([
{
key: "my_flag",
defaultValue: default_value,
activate: true,
},
]);
analytics.track("#User123", "Flagship_Source_React", my_flag)
// Flagship campaign activation
const {getModificationInfo: fsGetInfo} = useFlagship();
useFsActivate(["my_flag"]);
// Get Flagship campaign information and send it to Segment
if (fsGetInfo != null) {
fsGetInfo("my_flag")
.then((infos) => {
if (infos != null) {
analytics.track('Flagship_Source_ReactNative',infos)
}
})
.catch((error) => {
console.log(error);
return;
});
}
// Flagship campaign activation
Flagship.sharedInstance.activateModification(key: "my_flag")
//Get Flagship campaign information and send it to Segment
if let campaign_info = Flagship.sharedInstance.getModificationInfo(key:"my_flag"){
Analytics.shared().track("Flagship_Source_ios", properties:campaign_info)
}
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!
Updated 5 months ago