Custom analytics integration
Kameleoon provides built-in integrations with platforms such as Mixpanel, Amplitude, Snowplow, GA4, and Segment. These integrations work with any front-end or hybrid experiments.
If you use a platform that doesn't have an official Kameleoon integration, you can build your own integration using the Custom Analytics bridge feature. Follow the guidelines in the user manual to create a custom integration.
Alternatively, you can listen to custom DOM events fired by the Kameleoon JavaScript engine and send experiment or personalization events to the tool of your choice. Follow these steps:
- Obtain a list of all active experiments or personalizations on the page, then loop over the list and perform a given action, such as sending the experiment and variation IDs to your analytics platform using their API.
- Because the code can load and execute either before or after Kameleoon experiments trigger and activate, check the current active experiments at the start of your code AND stay informed of any new experiments that activate later.
Since experiments can activate at any time (such as only after the user has clicked on a specific button), never assume that your code has all the required information about the active Kameleoon experiments at any given moment when running. Always set up an event listener (as shown in the sample code below) to receive alerts about new experiments activated in the future.
Sample code
var processExperimentForMyTargetPlatform = function(experiment)
{
// Here you should implement your own logic, depending on the APIs of your target platform
// It can be something similar to:
myTargetPlatform.addExternalData({"experimentId": experiment.id, "experimentName": experiment.name, "variationId": experiment.associatedVariation.id, "variationName": experiment.associatedVariation.name});
}
// Loop over the experiments; apply the same logic for personalizations as well
Kameleoon.API.Experiments.getActive().forEach(processExperimentForMyTargetPlatform);
window.addEventListener("Kameleoon::ExperimentActivated", function(event) {
processExperimentForMyTargetPlatform(event.detail.experiment);
});
With this sample implementation, the data could be passed to your target platform several times for a single experiment if the experiment is active on multiple pages. Every page where the experiment is active results in the invocation of the processExperimentForMyTargetPlatform() function. You can improve the sample code to remember every experiment already processed, restricting the data passing to a single use. This approach typically removes unnecessary extra server calls to your target platform.