GuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

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.

Parameter

Type

Description

trackEvent
required

object

The data relevant to the trackEvent event.

trackEvent.type
required

string

analytics

trackEvent.name
optional

string

trackEvent

trackEvent.data
optional

object

Data associated to this event. You can use this object to determine which event was triggered.

trackEvent.data.type
optional

string

The type of the tracked event (e.g. "custom" for custom events, "pageview" for Page activated events).

trackEvent.data.name
optional

string

The name of the tracked event.

trackEvent.data.apiName
optional

string

The apiName of the tracked event. Note that for "pageview" events, this is the api_name of the Page.

trackEvent.data.category
optional

string

The category of the tracked event or page.

trackEvent.data.metrics
optional

object

Metrics attached to the event, if any.

trackEvent.data.metrics.revenue
optional

number or unidentified

Revenue value associated with the event, if any.

trackEvent.data.tags
optional

object

Map of tag name to tag value.