JavaScript Events

With the predefined JavaScript Event Integrations it is possible that ABlyft triggers functions on your website or executes any JavaScript.
Unlike custom integrations, the code to execute is not hosted and executed at ABlyft, but triggers an event that you can listen to from your side.

ablyft-javascript-event-callbacks

Two hooks are available which can be used for this purpose:

userBucketed The event is fired when a user is assigned to a variant. This happens once.
experimentViewed The event is fired every time the experiment is running for the user (e.g. at every page request, if the targeting conditions are met).

How do you listen to the event?

//Bind Event for "userBucketed"
document.addEventListener('userBucketed', function(e){
    console.info("The Variation ID is: ", e.detail.variationId);
});

//Bind Event for "viewedExperiment"
document.addEventListener('viewedExperiment', function(e){
    console.info("The Variation ID is: ", e.detail.variationId);
});

What variables are available in it?

The values are available under the object e.detail. See the example above.

  • projectId
  • projectName
  • experimentId
  • experimentName
  • variationId
  • variationName

Example

Console Output
{
    experimentId: 123456789,
    experimentName: "Dummy Experiment",
    projectId: 987654321,
    projectName: "Dummy Project",
    variationId: 987612345,
    variationName: "Dummy Variation"
}
//Bind Event for "viewedExperiment"
document.addEventListener('viewedExperiment', function(e){
    console.log(e.detail);
})