trackEvent

The trackEvent method and API events that you create in Event Builder provide a way to indicate that something important has happened on your site. This method can be called multiple times per page. However, Monetate only collects data once per event per page. For example, you can track when a customer's mouse pointer hovers over a navigation item by reporting a nav_hover event each time this occurs. Nevertheless, the Monetate platform only tracks the first instance on each page.

Monetate Inspector Example

The Monetate Inspector browser plug-in doesn't show custom events that you push with the trackEvent method unless you first create an API event in Event Builder. See Create API Events for the steps to create this type of event.

The Events panel of Monetate Inspector, with a trackAPI event in the 'Page Event' row

Code Samples

Once you create the API event in Event Builder with the appropriate event key, the code snippet below explains how to trigger the event.

An event key is a string composed of alphanumeric characters (a–z, 0–9) and select special characters (spaces, underscores, and hyphens). Ensure that you give an event key a descriptive name so that you can easily understand what it references in the code.

// Initialize the monetateQ object. If the monetateQ object is 
// already present on the page, you don't have to do this again. 

window.monetateQ = window.monetateQ || [];

// Send the event key when the event occurs
// "Event Key" is the name of the key that you want to send.

window.monetateQ.push(["trackEvent", ["Event Key"]]);

This code sample shows a typical call to track an event.

window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "trackEvent", ["reached_platinum"]
]);

You can make these calls from anywhere in your site's code to signify when a custom event has occurred.

// trackEvent Method
window.monetateQ = window.monetateQ || [];
window.monetateQ.push([
  "trackEvent", ["reached_platinum"]
]);