Track custom events in Optimizely Web Experimentation.
The event eventName is tracked and associated with the current visitor. The event method captures visitor behavior and additional data. You can track clicks and pageviews in Optimizely Web Experimentation without code, but this API call supports tracking other behaviors like watching a video. These events can be used for measuring the results of a campaign or for determining an audience based on behavior.
Syntax
window["optimizely"].push(event);
Parameters
| Parameter and Type | Child Attribute | Description |
|---|---|---|
| event EventObject | N/A | This is an event object. Required. |
| type string | Child attribute of type EventObject. | This is a static value that indicates that you're using the event function. Required. |
| eventName string | Child attribute of type EventObject. | The "API name" for an event created in Web Experimentation, for example, "add_to_cart". Required. |
| tags EventTag | Child attribute of type EventObject. | A flat object containing metadata about an event (for example, the SKU of the product being purchased). Some keys are reserved. See the following EventTag definition for the list of such keys. |
| revenue integer | Child attribute of type EventTag. | Used to submit values for the revenue metric. Values of this tag should be integers equal to 100 times the unit value of the relevant currency (for example, dollar, euro). For example, if a conversion results in $75.02 of revenue, then this tag should be included with value 7502. |
| value number | Child attribute of type EventTag. | Used to submit values for numeric metrics that are not revenue. If it is a number, it is included among both If the value is not a number, this tag is still included among the |
_string or integer | Child attribute of type EventTag. | You can specify additional properties of your choice. |
Example call
// ensures the optimizely object is defined globally
window['optimizely'] = window['optimizely'] || [];
window["optimizely"].push({
"type": "event",
"eventName": "watchedVideo",
"tags": {
"title": "Funny Cats",
"duration": 30,
"revenue": 5000
}
});