Segment
With this integration, you can seamlessly connect Kameleoon with Segment to:
- Use Kameleoon as a source to push campaign exposure event data (campaign name and variation name) to Segment, which can then be used by other platforms available in the Segment marketplace.
- Use Kameleoon as a destination to:
- import Segment events, which you can use in Kameleoon experiments and web personalizations.
- import Segment personas, traits, and groups, and use them in our Segment Builder throughout custom data.
Key benefits:
- Automatically send any data, including KPIs, from Segment to Kameleoon to create highly tracked and targeted optimization campaigns.
- Enhance targeting and analyze the results of your A/B/n tests with Segment event data.
- Analyze the effect of test campaigns on the entire customer journey.
- Reach visitors exposed to an online campaign on other channels (for example, email marketing campaigns, mobile apps) using Segment events sent by Kameleoon.
Push Kameleoon exposure events into Segment
Enable Segment integration on Kameleoon
- Log in to the Kameleoon app.
- Click Admin > Integrations > Install the tool.
- Select the projects on which you want to configure Segment.
- Click Validate.
You will then see an ON toggle on the right of the tool's line, and the number of projects the tool is configured on.
Ensure the Segment script (analytics.js) is installed on your pages, as Kameleoon will send campaign exposure events to Segment using the Segment JavaScript API.
Associate Segment as reporting tool in a Kameleoon experiment or personalization
Once the integration is activated on the Integrations page, you can select it as a reporting tool in the Integrations tab of the Graphic/Code Editor's finalization panel.
When you have activated and defined Segment as a reporting tool in a campaign, an event called "Experiment viewed" will be automatically sent every time a visitor sees a variation of an active Kameleoon A/B experiment.
If you need to send exposure events for feature flags, you must enable Hybrid capabilities.
Import Segment events, traits, groups and personas into Kameleoon
This section is about the non-Actions Kameleoon destination, which will soon be deprecated. We recommend using the Actions-framework Kameleoon Segment destination, which is documented here.
With this Segment x Kameleoon integration:
- Every event that is triggered by Segment is automatically sent to Kameleoon. Page, Screen and Track events are automatically collected as a Kameleoon custom goal, and you can use any of them in your campaigns or to target users.
- Track events of type Audience Entered or Audience exited are collected as a Kameleoon custom data to be used in our Segment builder to target user personas.
- Track events of type identify with traits are collected as Kameleoon custom data to be used in our Segment builder to target users with specific traits.
- Track events of type group are collected as Kameleoon custom data to be used in our Segment builder to target a group ID.
Generate API Credentials
You must enable API Credentials to use this integration. To generate your API Key:
- Get your client ID and client secret. You can find them in your profile page.
- Use your client ID and client secret with the following URL to generate your API Key:
https://customers.kameleoon.com/kameleoon/segmentio/getapikey?id=[CLIENT_ID]&secret=[CLIENT_SECRET]
Get your project sitecode
You will also need to get your sitecode in your Kameleoon account.
To learn how to find your sitecode, please read this documentation.
Enter this information when setting up the Kameleoon as a destination in your Segment app
- From the Destinations Catalog in the Segment app, click Add Destination.
- Search for Kameleoon in the Destinations Catalog, and select the Kameleoon destination.
- Click Configure Kameleoon.
- Choose the Source (for example, app or website) that will send data to the Kameleoon destination.
- Enter the API Key and the sitecode in the Kameleoon destination settings in Segment.
Matching Users between Kameleoon and Segment
The integration requires that you use the same system of identifiers for both tools, meaning the userId
value you pass to Segment should be the same value as Kameleoon uses to identify a "visitor".
If you use Kameleoon Web Experiment, Kameleoon places a cookie that contains an anonymous unique identifier, called the Kameleoon visitorCode
, randomly assigned to a visitor. This ID is used to uniquely identify a user in a browser. You have several options available:
- You can pass our
visitorCode
in theuserId
property of the Segment identify call to ensure Kameleoon can attribute all events data received from Segment to the right visitor. - You can pass our
visitorCode
in an additional Segment call as follows:analytics.track('Kameleoon identifier', {'k_visitorCode': Kameleoon.API.Visitor.code})
. Kameleoon will automatically link the Segment user ID or anonymous ID to our ownvisitorCode
. Ensure you call it only once per session. For instance, if you use Kameleoon Web Experimentation, or have implemented our Kameleoon application file (kameleoon.js) to benefit from hybrid experimentation capabilities, you can use the code example below in the Global custom script section of the Kameleoon Project property.
Kameleoon.API.Core.runWhenConditionTrue(
() => window.analytics && window.analytics.track && window.analytics.user,
() => {
const kSegmentioIdentifier = window.localStorage.getItem('k_segmentio_identifier');
if(kSegmentioIdentifier && kSegmentioIdentifier === window.analytics.user().anonymousId()) return;
window.localStorage.setItem('k_segmentio_identifier', window.analytics.user().anonymousId());
window.analytics.track('Kameleoon identifier', {'k_visitorCode': Kameleoon.API.Visitor.code})
}
);
If you use Kameleoon Feature Experimentation, please refer to the Kameleoon SDK documentation as you can set your own ID instead of using a generated Kameleoon Visitor Code and have the exact same ID between Segment and Kameleoon.
Supported Segment events and Personas
Kameleoon supports the following methods: Track, Identify, Page, Screen, and Group, as specified in the Segment Spec.
If the Segment event name matches the name of an existing goal in your Kameleoon account, a conversion for this goal will be associated with the visitor. If the goal does not exist, Kameleoon will create a custom goal by using the Segment event name and associate the conversion with the visitor. The goal will appear in the Kameleoon goals page with the naming convention SegmentIO [eventType] - [eventName]
. Once the goal has been created, you can use them in any of your campaigns.
Segment track calls of type Audience Entered, Audience Exited, Identify, and Group. These are collected as a Kameleoon custom data.
Segment uses our Data API map endpoint to send data to Kameleoon.
Personas, traits and group
Kameleoon lets you target users based on their Segment persona, group, or specific properties.
To use personas, traits, and group IDs in our Segment builder, you must set up a custom data in your Kameleoon account for the project of your choice.
Personas
You can name your persona (for example, SegmentIO personas), and the custom data must be of type List of string.
Please follow the guidelines below for Web Experimentation only.
You can use the code below in the custom data acquisition method:
window.k_segmentIO = window.k_segmentIO || {};
if(!window.k_segmentIO.runtime)
{
window.k_segmentIO.runtime = true;
Depending on your setup, you must determine the appropriate logic for obtaining the user ID.
If you've been using a track event call to send our visitor code, use the following line:
const user_id = Kameleoon.API.Visitor.code;
Alternatively, if you use our Visitor Code as the Segment user ID or need to retrieve the user ID from Segment's analytics object, use the following code:
const user_id = window.analytics.user().id() || window.analytics.user().anonymousId();
Kameleoon.API.Data.retrieveDataFromRemoteSource(`COHORTS_${user_id}`, cohorts => { window.k_segmentIO.cohorts = cohorts && cohorts !== '{}' ? Object.keys(cohorts).filter(key => cohorts[key]) : []; });``
}
if(!window.k_segmentIO.cohorts || !window.k_segmentIO.cohorts.length) return;
return {"value": window.k_segmentIO.cohorts, "overwrite": true};
To use Segment personas in server-side experiments or feature flags, you can consult the guidelines outlined in each SDK's documentation.
Our SDKs employ the getRemoteData()
method. This method fetches data stored by Segment in our servers and make it accessible in your backend code.
The "key" value to use as the first parameter should follow this format: COHORTS_{user_id}
.
Fetch Segment Persona names in Kameleoon
Click Next and activate the Save the values for the targeting condition associated with the custom data point option. Add the JS code below and replace XXXXXXXXX
with the Kameleoon Sitecode. To find it, please follow this documentation.
var xhr = new XMLHttpRequest();
xhr.open("GET", '[https://api-data.kameleoon.com/data?key=common&siteCode=XXXXXXXXX](https://api-data.kameleoon.com/data?key=common&siteCode=XXXXXXXXX)', false);
var SegmentIOPersonas = [];
xhr.onreadystatechange = function() {
if(this.readyState === 4) {
var segmentIOcohorts = JSON.parse(xhr.response);
if (segmentIOcohorts && segmentIOcohorts.cohorts) {
segmentIOcohorts.cohorts.forEach(persona => SegmentIOPersonas.push({value: persona, label: persona}) );
}
}
}
xhr.send();
return SegmentIOPersonas;
Click Validate to create the Custom Data.
That's it! You can now use Segment Personas in our Segment builder. The list of available personas is available when you choose the operator is among the values.
Traits
To use traits in our segment builder, you must create one custom data per trait type. Let's say you want to target users based on the plan they have subscribed to on your website, and you have three different plans: freemium, scale, and enterprise. You need to set up a custom data called "Subscribed Plan," and the custom data must be of type "string".
Please follow the guidelines below for Web Experimentation only.
You can use the code below in the custom data acquisition method:
window.k_segmentIO = window.k_segmentIO || {};
if(!window.k_segmentIO.runtime)
{
window.k_segmentIO.runtime = true;
Depending on your setup, you'll need to determine the appropriate logic for obtaining the user ID.
If you've been using a track event call to send our visitor code, use the following line:
const user_id = Kameleoon.API.Visitor.code;
Alternatively, if you use our Visitor Code as the Segment user ID or need to retrieve the user ID from Segment's analytics object, use the following line:
const user_id = window.analytics.user().id() || window.analytics.user().anonymousId();
Kameleoon.API.Data.retrieveDataFromRemoteSource(`IDENTIFY_${user_id}`, segment_identify_properties => {
if(segment_identify_properties && segment_identify_properties.traits && segment_identify_properties.traits.plan){
window.k_segmentIO.plan = segment_identify_properties.traits.plan;
}
});
}
if(!window.k_segmentIO.plan) return;
return {"value": window.k_segmentIO.plan, "overwrite": true};
To use traits in server-side experiments or feature flags, you can consult the guidelines outlined in each SDK's documentation.
Our SDKs employ the getRemoteData()
method. This method fetches data stored by Segment on our servers and makes it accessible in your backend code.
The "key" value to use as the first parameter should follow this format: IDENTIFY_{user_id}
.
You can follow the same guidelines for every trait property you would like to use in Kameleoon's Segment builder.
Group IDs
To use group IDs in our Segment builder to target your campaigns, you must set up a custom data called "Group ID," and the custom data must be a string type.
Please follow the guidelines below for Web Experimentation only.
You can use the code below in the custom data acquisition method:
window.k_segmentIO = window.k_segmentIO || {};
if(!window.k_segmentIO.runtime)
{
window.k_segmentIO.runtime = true;
Depending on your setup, you'll need to determine the appropriate logic for obtaining the user ID.
If you've been using a track event call to send our visitor code, use the following line:
const user_id = Kameleoon.API.Visitor.code;
Alternatively, if you use our Visitor Code as the Segment user ID or need to retrieve the user ID from Segment's analytics object, use the following line:
const user_id = window.analytics.user().id() || window.analytics.user().anonymousId();
Kameleoon.API.Data.retrieveDataFromRemoteSource(`IDENTIFY_${user_id}`, segment_identify_properties => {
if(segment_identify_properties && segment_identify_properties.groupId){
window.k_segmentIO.groupId = segment_identify_properties.groupId;
}
});
}
if(!window.k_segmentIO.groupId) return;
return {"value": window.k_segmentIO.groupId, "overwrite": true};
To use traits in server-side experiments or feature flags, you can consult the guidelines outlined in each SDK's documentation.
Our SDKs employ the getRemoteData()
method. This method fetches data stored by Segment on our servers and makes it accessible in your backend code.
The "key" value to use as the first parameter should follow this format: IDENTIFY_{user_id}
.