Utilities to manage data layer tracking. You probably don't want to use these utilities directly. Instead, use the wrapper utilities provided in ./index.js that will also take care of other types of tracking
Members
-
<static, constant> dataLayerCustomEvent
-
Tracks a custom event. All custom events have been given the same name (see GTM_CUSTOM_EVENT const above) so we can define a trigger in the GTM admin console to respond to these events. For more information about the parameters passed to this util, see The Anatomy of Events
-
<static, constant> dataLayerPageView
-
Tracks a custom page view event to the data layer. The attributes of the event can be mapped in the GTM admin console. Currently, not all of them are being used.
-
<static, constant> dataLayerTimingEvent
-
Tracks a timing event in GTM. This is a custom event trigger, but it has been structured to match a timing event in Google Analytics so they can easily be mapped to GA in the GTM admin console. See https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings for more info.
-
<constant> DATA_LAYER_WINDOW_VAR :string
-
Variable name of the data layer on window
Type:
- string
-
<constant> GTM_CUSTOM_EVENT :string
-
Event name for custom (non page-view) events
Type:
- string
-
<constant> GTM_PAGE_VIEW :string
-
Event name for custom page view events
Type:
- string
-
<constant> GTM_TIMING_EVENT :string
-
Event name for tracking timings
Type:
- string
-
lastPushed :object
-
Stores lastPushed pageEvent variables
Type:
- object
Methods
-
<static> dataLayerPush(items)
-
Pushes the given items to the dataLayer. Verifies that the dataLayer variable exists on window and skips the push on the NodeJS side.
Parameters:
Name Type Argument Description itemsobject <repeatable>
The items to push to the array. These arguments are the same as if you would call window.dataLayer.push( ... )
Returns:
True if the items were pushed (in the browser), false if it has been skipped (on the NodeJS side).
- Type
- boolean
-
dataLayerEvent(event [, attributes] [, state])
-
Push a new event to the data layer. This is a lower-level helper and should not be used directly. To track custom events, use the dataLayerCustomEvent() util.
Parameters:
Name Type Argument Default Description eventstring The name of the event to push
attributesobject <optional>
{} Attributes to add to the event
stateobject <optional>
The current redux state, used to get tracking meta properties