The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubNuGetDev CommunitySubmit a ticketLog In

Listen to a snippet lifecycle event.

Description

Listen to a specific event from somewhere in the snippet's execution. Your handler function will be invoked for each applicable lifecycle event that occurs after the handler is registered. It is not retroactively invoked for events that may have occurred prior to handler registration.

You can listen to the following types of events:

window.optimizelyEdge.push(addListener);
window.optimizelyEdge.push({
  "type": "addListener",
  "filter": {
    "type": "lifecycle",
    "name": "initialized"
  },
  "handler": function(event) {
    console.log("Project " + window["optimizely"].get("data").projectId + " is initialized");
  }
});

Parameters

This table provides general information about required and optional parameters.

ParameterTypeDescription
addListener
required
objectAn object with the type field set to addListener.

The other fields are the function arguments.
addListener.type
required
stringThe argument indicating that you are using the addListener function.
addListener.filter
optional
objectBy setting a filter, you can define for which type of events or what category of events the handler is called.
addListener.handler
optional
functionThe function that will be called when the event occurs.
addListener.filter.type
required
stringThe category of an event. Possible values: lifecycle and analytics.
addListener.filter.name
optional
stringThe name of the event type. The value can be: campaignDecided, pageActivated, initialized, originsSynced, or trackEvent.