---
title: trackEvent
slug: js-api/trackevent
description: Overview of the Monetate JavaScript API trackEvent method and how to use it
image:  https://archbee-image-uploads.s3.amazonaws.com/ceIfEvQHzQk1IVxoRWUh7/K9eTL4jKm7UQINb6zNziJ-20250912-181225.png
docTags: 
createdAt: 2024-04-30T18:45:17.577Z
---

:::CodeblockTabs
trackEvent Method

```javascript
// 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"]]);
```
:::

The `trackEvent` method and [API events](https://docs.monetate.com/docs/build-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 View

:::hint{type="info"}
The [Monetate Inspector browser plug-in](https://docs.monetate.com/docs/install-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 [Build API Events](https://docs.monetate.com/docs/build-api-events) in the Monetate Knowledge Base for the steps to create this type of event.
:::

![The Events panel of Monetate Inspector, with a trackAPI event in the 'Page Event' row](https://dyzz9obi78pm5.cloudfront.net/app/image/id/63d00b1a5e454337d4697465/n/monetate-inspector-components-tab-events-panel-trackapi.png)

## Code Sample

Once you create the API event in Event Builder with the appropriate [event key](https://docs.monetate.com/docs/build-api-events#custom-event-key), the code snippet below explains how to trigger the event.

:::hint{type="info"}
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.
:::

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

This code sample shows a typical call to track an event. It contains the method in use that results in the Monetate Inspector results shown in the previous screenshot.

:::CodeblockTabs
trackEvent Example

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

