Search
Clear search
Close search
Google apps
Main menu

Built-in variables for web containers

Clicks

Click Element: Accesses the gtm.element key in the dataLayer, which is set by Click triggers. This will be a reference to the DOM element where the click occurred.

Click Classes: Accesses the gtm.elementClasses key in the dataLayer, which is set by Click triggers. This will be the string value of the classes attribute on the DOM element that was clicked.

Click ID: Accesses the gtm.elementId key in the dataLayer, which is set by Click triggers. This will be the string value of the id attribute on the DOM element that was clicked.

Click Target: Accesses the gtm.elementTarget key in the dataLayer, which is set by Click triggers.

Click URL: Accesses the gtm.elementUrl key in the dataLayer, which is set by Click triggers.

Click Text: Accesses the gtm.elementText key in the dataLayer, which is set by Click triggers.

Errors

Error Message: Accesses the gtm.errorMessage key in the dataLayer, which is set by JavaScript Error triggers. This will be a string containing the error message.

Error URL: Accesses the gtm.errorUrl key in the dataLayer, which is set by JavaScript Error triggers. This will be a string containing the URL where the error occurred.

Error Line: Accesses the gtm.errorLine key in the dataLayer, which is set by JavaScript Error triggers. This will be a number of the line in the URL where the error occurred.

Debug Mode: Returns true if the container is currently running in preview mode.

Forms

Form Classes: Accesses the gtm.elementClasses key in the dataLayer, which is set by Form triggers. This will be the string value of the classes attribute on the form.

Form Element: Accesses the gtm.element key in the dataLayer, which is set by Form triggers. This will be a reference to the form's DOM element.

Form ID: Accesses the gtm.elementId key in the dataLayer, which is set by Form triggers. This will be the string value of the id attribute on the form.

Form Target: Accesses the gtm.elementTarget key in the dataLayer, which is set by Form triggers.

Form Text: Accesses the gtm.elementText key in the dataLayer, which is set by Form triggers.

Form URL: Accesses the gtm.elementUrl key in the dataLayer, which is set by Form triggers.

History

History Source: Accesses the gtm.historyChangeSource key in the dataLayer, which is set by History Change triggers.

New History Fragment: Accesses the gtm.newUrlFragment key in the dataLayer, which is set by History Change triggers. Will be the string value of the fragment (aka hash) portion of the page's URL after the history event.

New History State: Accesses the gtm.newHistoryState key in the dataLayer, which is set by History Change triggers. Will be the state object that the page pushed onto the history to cause the history event.

Old History Fragment: Accesses the gtm.oldUrlFragment key in the dataLayer, which is set by History Change triggers. Will be the string value of the fragment (aka hash) portion of the page's URL before the history event.

Old History State: Accesses the gtm.oldHistoryState key in the dataLayer, which is set by History Change triggers. Will be the state object that was active before the history event took place.

Pages

Page Hostname: Provides the hostname portion of the current URL.

Page Path: Provides the path portion of the current URL.

Page URL: Provides the full URL of the current page.

Referrer: Provides the full referrer URL for the current page.

Scrolling

Scroll Depth Threshold: Accesses the gtm.scrollThreshold key in the dataLayer, which is set by Scroll Depth triggers. This will be a numeric value indicating the scroll depth that caused the trigger to fire. For percentage thresholds, this will be a numeric value (0-100). For pixels, this will be a numeric value representing the number of pixels specified as the threshold.

Scroll Depth Units: Accesses the gtm.scrollUnits key in the dataLayer, which is set by Scroll Depth triggers. This will be either ‘pixels’ or ‘percent’, indicating the unit specified for the threshold that caused the trigger to fire.

Scroll Direction: Accesses the gtm.scrollDirection key in the dataLayer, which is set by Scroll Depth triggers. This will be either ‘vertical’ or ‘horizontal’, indicating the direction of the threshold that caused the trigger to fire.

Utilities

Container ID: Provides the container's public ID. Example value: GTM-XKCD11

Container Version: Provides the version number of the container, as a string.

Environment Name: Returns the user-provided name of the current environment, if the container request was made from an environment "Share Preview" link or from an environment snippet. For the built-in environments, it will return "Live", "Latest", or "Now Editing". In all other cases including non-environment container requests, it returns an empty string.

Event: Accesses the event key in the dataLayer, which is the name of the current dataLayer event (e.g. gtm.js, gtm.dom, gtm.load, or custom event names).

HTML ID: Allows custom HTML tags to signal if they had succeeded or failed; used with tag sequencing.

Videos

Video Current Time: Accesses the gtm.videoCurrentTime key in the dataLayer, which is an integer representing the time in seconds at which an event occurred in the video.

Video Duration: Accesses the gtm.videoDuration key in the dataLayer, which is an integer representing the total duration of the video in seconds.

Video Percent: Accesses the gtm.VideoPercent key in the dataLayer, which is an integer (0-100) representing the percent of video played at which an event occurred.

Video Provider: Accesses the gtm.videoProvider key in the dataLayer, which is set by YouTube Video triggers. This will be the name of the video provider, i.e. 'YouTube'.

Video Status: Accesses the gtm.videoStatus key in the dataLayer, which is the state of the video when an event was detected, e.g. 'play', 'pause'.

Video Title: Access the gtm.videoTitle key in the dataLayer, which is set by YouTube Video triggers. This will be the title of the video.

Video URL: Access the gtm.videoUrl key in the dataLayer, which is set by YouTube Video triggers. This will be the URL of the video, e.g. ‘https://www.youtube.com/watch?v=gvHcXIF0rTU’.

Video Visible: Access the gtm.videoVisible key in the dataLayer, which is set by YouTube Video triggers. This will be set to true if the video is visible in the viewport, and false if it is not (e.g. below the fold, or playing in a background tab).

Visibility

Percent Visible: Accesses the gtm.visibleRatio key in the dataLayer, which is set by Element Visibility triggers. This will be a numeric value (0-100) indicating how much of the selected element is visible when the trigger fires.

On-Screen Duration: Accesses the gtm.visibleTime key in the dataLayer, which is set by Element Visibility triggers. This will be a numeric value indicating how many milliseconds the selected element has been visible for when the trigger fires.

Was this article helpful?
How can we improve it?