Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

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 TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
API Reference

Fires whenever an event has occurred.

Description

The trackEvent lifecycle event is fired whenever the visitor triggers an event.

You can use this API if you want to track conversions in an external analytics platform.

You can also use this to manually activate an experiment after a particular event has occurred.

var trackEvent = function(trackEvent);
function onTrackEvent(event) {
  console.log("The event " + event.data.name + " was tracked");
}

window.optimizelyEdge = window.optimizelyEdge || [];
window.optimizelyEdge.push({
  type: "addListener",
  filter: {
    type: "analytics",
    name: "trackEvent"
  },
  handler: onTrackEvent
});

Parameters

This table provides general information about required and optional parameters.

ParameterTypeDescription
trackEvent
required
objectThe data relevant to the trackEvent event.
trackEvent.type
required
stringanalytics
trackEvent.name
optional
stringtrackEvent
trackEvent.data
optional
objectData associated to this event. You can use this object to determine which event was triggered.
trackEvent.data.type
optional
stringThe type of the tracked event (e.g. "custom" for custom events, "pageview" for Page activated events).
trackEvent.data.name
optional
stringThe name of the tracked event.
trackEvent.data.apiName
optional
stringThe apiName of the tracked event. Note that for "pageview" events, this is the api_name of the Page.
trackEvent.data.category
optional
stringThe category of the tracked event or page.
trackEvent.data.metrics
optional
objectMetrics attached to the event, if any.
trackEvent.data.metrics.revenue
optional
number or unidentifiedRevenue value associated with the event, if any.
trackEvent.data.tags
optional
objectMap of tag name to tag value.