Event Method: Track

Overview

The Track event method records information about specific actions users are taking on your digital property. It includes a name describing the action (e.g. Button Clicked or Product Purchased) and a list of Properties about the action which help describe it further detail (e.g. they clicked a “blue” button, the product purchased was $99, etc.).

How It Works

Unlike Page events, you must add Track event code for each action that you’d like to record. The function you will add to your website looks like this:

analytics.track("Product Viewed", {
  product_id: "286209051",
  name: "Acrux TR GTX Hiking Boots"
});

This call could produce the below payload, with common fields removed:

{
  "type": "track",
  "event": "Product Viewed",
  "properties": {
    product_id: "286209051",
	  name: "Acrux TR GTX Hiking Boots"
  }
}

With common fields, the event could look like this:

{
    "timestamp": "2024-01-26T22:54:45.961Z",
    "integrations": {},
    "userId": "[email protected]",
    "anonymousId": "f8cc0f85-cb4d-4f73-b16f-c251384fdf74",
    "event": "Product Viewed",
    "type": "track",
    "properties": {
        "product_id": "286209051",
        "name": "Acrux TR GTX Hiking Boots",
    },
    "context": {
        "traits": {},
        "page": {
            "path": "/shop",
            "referrer": "https://www.example.com/",
            "search": "",
            "title": "metashop",
            "url": "https://www.example.com/shop?"
        },
        "providers": {},
        "globalPrivacyControl": false,
        "consent": {
            "optOut": {
                "C0001": false,
                "C0002": false,
                "C0003": false,
                "C0004": false,
                "C0005": false
            }
        },
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
        "locale": "en-US",
        "library": {
            "name": "analytics.js",
            "version": "npm:next-1.51.3-mr.3"
        }
    },
    "messageId": "8178a621e0e88f10a0b0a74609df14c4",
    "writeKey": "example_writekey",
    "sentAt": "2024-01-26T22:54:45.972Z",
    "_metadata": {
        "bundled": [],
        "unbundled": [],
        "bundledIds": []
    }
}

Track events contain two fields specific to this type of call:

FieldRequired?TypeDescription
eventYesStringName of action being performed.
propertiesNoObjectDictionary of fields that describe the action.

Properties

Properties represent any additional information you might want to track about the actions users are taking on your digital property. Some properties are populated via the common fields, but you may also add your own custom properties as well if you would like to track anything else about the action being taken.

This is a list of common properties for all Track events. You can find more common properties for individual track events within our Recommended Industry Event Specs. We recommend using these whenever one of these fields covers what you are trying to track.

PropertyData TypeDescription
revenueNumberTotal amount of money that an event generated. Since this is a Number data type, ensure that the revenue is a decimal value.
currencyStringThe monetary type that revenue was recorded with. This will default to USD if not defined. Please ensure that currency is formatted to the ISO 4127 format.
valueNumberWhere revenue cannot be attributed to an action, use value to attribute an abstract value to the action. This is potentially helpful for situations like demo signups, newsletter signups, or other valuable actions.

Naming Track Events

Your organization should agree to standard naming conventions that will ensure your events are unique and recognizable to those responsible for mapping event data to your destinations within MetaRouter. Using best practices, like ensuring that event names are human-readable and formatted as object-action in past-tense, will allow your organization to quickly and easily make use of the event data you produce.

Additional Considerations

Like the Page method, the Track method can also accept parameters for options and callback functions.