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.
Parameter | Type | Description |
---|---|---|
addListener required | object | An object with the The other fields are the function arguments. |
addListener.type | string | The argument indicating that you are using the addListener function. |
addListener.filter | object | By setting a filter, you can define for which type of events or what category of events the handler is called. |
addListener.handler | function | The function that will be called when the event occurs. |
addListener.filter.type | string | The category of an event. Possible values: |
addListener.filter.name | string | The name of the event type. The value can be: |