Event Tracking

This guide explains how to implement event tracking with analytics.js.

Overview

Events are user interactions with content that can be tracked independently from a web page or a screen load. Downloads, mobile ad clicks, gadgets, Flash elements, AJAX embedded elements, and video plays are all examples of actions you might want to track as Events.

If you're unfamiliar with events in Google Analytics you should first read the article About Events in the Analytics Help Center.

Implementation

Event hits can be sent using the send command and specifying a hitType of event. The send command has the following signature for the event hit type:

ga('send', 'event', [eventCategory], [eventAction], [eventLabel], [eventValue], [fieldsObject]);

Event fields

The following table summarizes the event fields:

Field Name Value Type Required Description
eventCategory text yes Typically the object that was interacted with (e.g. 'Video')
eventAction text yes The type of interaction (e.g. 'play')
eventLabel text no Useful for categorizing events (e.g. 'Fall Campaign')
eventValue integer no A numeric value associated with the event (e.g. 42)

For a more in-depth description of each of these fields, see Anatomy of an Event in the Analytics Help Center.

Examples:

The following command sends an event to Google Analytics indicating that the fall campaign promotional video was played:

ga('send', 'event', 'Videos', 'play', 'Fall Campaign');

Note that as with all send commands, the fields passed in the convenience parameters may also be specified in the fieldsObject. The above command could be rewritten as:

ga('send', {
  hitType: 'event',
  eventCategory: 'Videos',
  eventAction: 'play',
  eventLabel: 'Fall Campaign'
});

Non-interaction events

In some cases you might want to send an event as a non-interaction event. To do this, specify the nonInteraction field as true in the fieldsObject of the send command:

ga('send', 'event', 'Videos', 'play', 'Fall Campaign', {
  nonInteraction: true
});

For more information on non-interaction hits and when to use them, read about non-interaction events in the Analytics Help Center