Category: AB Testing
What to expect
This integration will allow you to analyze AB Test campaigns directly in Experience Analytics and easily discover and explore customer behavior across all digital channels and devices in order to build and test ever-better customer experiences. For instance, you can segment all sessions that experienced an AB test variation from the Analysis Context in Contentsquare and see corresponding metrics in the Zone-based Heatmaps and Session Replay modules in order to deeply understand UX behaviors and the corresponding performance.
What we collect
Dynamic Variables
| Key | Value | Data Type |
| AB_LD_{Campaign Name} | True | Text |
Implementation
Implementation Steps
Step 1
Go to the section How to request an integration to see the instructions to enable this integration. You can then return here once completed.
If you have already completed the step above then continue below.
Step 2
1. You will need to install and use one of the client side SDKs provided by LaunchDarkly.
2. Create a function to send flag evaluation data to Contentsquare. This function will be called by the LaunchDarkly SDK every time it evaluates a feature flag.
const sendCSAnalyticsEvent = (flagKey, flagDetail) => {
const { value, variationIndex, reason } = flagDetail;
// Making sure the flag is part of an experiment by checking the value of `flagDetail > reason > inExperiment` is `true`
if (!!reason && !!reason.inExperiment && typeof value != "undefined") {
/**
* Calls the ContentSquare integration handler with the flag evaluation data.
*
* Arguments:
* flagKey (string): The key of the evaluated flag.
* value (string or number): The value of the served flag variation.
*/
function callCShandler() {
CS_CONF.integrations_handler.launchdarkly(flagKey, value);
}
if (
window.CS_CONF &&
window.CS_CONF.integrations_handler &&
window.CS_CONF.integrations_handler.launchdarkly
) {
callCShandler();
} else {
window.addEventListener("Contentsquare_LD_Integration_Launch", () => {
callCShandler();
});
}
}
};
The above code sends the relevant experiment evaluation data to a Contentsquare integrations handler function. If this function is available at the time when the LaunchDarkly SDK dispatches the event, it will extract the flag and variation info and pass it to Contentsquare. If the function is not yet loaded, the handler will register a listener to dispatch the information whenever the integrations handler function is loaded.
3. Next define/update the LaunchDarkly client configuration options by including the inspector that will trigger the integration function.
The 'inspectors' argument inside the config object accepts an array of objects which allow you to set up listeners for the selected SDK operations. Each object defines a single event listener and accepts the following arguments:
- type (string): Refers to a specific SDK operation that should be observer
- name (string): Identifies the inspector instance
- method (function): A method that is called when the SDK evaluates a feature flag as a result of calling the variation method. You can provide an in-line function or call a function defined elsewhere.
const ldConfigOptions = {
// Any other/existing configuration options
inspectors: [
{
type: 'flag-used',
name: 'Contentsquare-analytics-integration',
method: sendCSAnalyticsEvent
}
]
};
// Example initialization of the LaunchDarkly client
const client = LDClient.initialize('YOUR_CLIENT_SIDE_ID', ldContext, ldConfigOptions);
client.on('ready', () => {
console.log('LaunchDarkly client is ready');
});
Verifying it works
You can use the Contentsquare Tracking Setup Assistant chrome extension to check the dynamic variables are sent to Contentsquare.