Since October 2014, Google Tag Manager has included variables, which act as helper functions that tags and triggers can invoke to retrieve values. There are a number of built-in variables in Google Tag Manager, but for the most benefits, you should also create your own.
Built-in variables, located at the top of the Google Tag Manager screen, are non-customizable. Check or uncheck the boxes next to each one to activate or deactivate them.
For web containers, there are built-in containers for clicks, errors, forms, history, pages and utilities.
For AMP containers, you have variables for device and browser, interaction, page and content, pages, performance and utilities, as well as a few miscellaneous — AMP event, client timestamp, page client ID and page view ID.
For Android containers, there are variables for application, device, utilities, campaign event parameters and other event parameters. iOS containers have all the same, plus some for in-app purchase-event parameters and notification-event parameters.
There are also a few differences in the built-in variables according to whether they are for Android or iOS. For example, with the Advertiser Tracking Enabled variable for Android, the variable returns true if ad tracking is enabled and false if the user opted out of interest-based ads. It also returns false for SDK versions earlier than v4. For iOS 6 and above, the value is set to the advertisingTrackingEnabled property. For earlier versions, the version is set to true.
Finally, for legacy mobile containers, built-in variables are available for application, device and utilities.
Variable Types to Customize
1st Party Cookie
This retrieves the value of the cookie you specify in the Cookie Name field. If the cookie has the same name on multiple paths or multiple levels of the domain, the variable will use the first.
Container Version Number
This variable returns the live version number unless the container is in preview mode. If this is the case, it returns the preview version number.
The value is set to true whenever you view a container in debug mode.
You can create a lookup table to set a value. The first column is “when [select variable] equals.” The second column is “set [this variable] to.” In this way, you can create a variable where the value varies according to the value of another variable. You should use this if your website is set up to allow an appropriate value to map to a URL or another aspect of the page.
This variable allows you to parse and expose URL components in addition to the three instances Google Tag Manager automatically provides — full URL, hostname and path. For instance, you can create additional instances to expose different parts of the URL, using the components protocol, hostname, port, path, query or fragment. The input value set for variables is the URL of the current page of the user, but you can adjust the URL source setting to tell Google Tag Manager to use a different variable as the source of the URL value.
For mobile, you have:
The variable is set to the string you provide. However, as the string is always the same, this variable has limited uses. A possible purpose is to set a standard company name across your site. You can update the string in Google Tag Manager to see it across all tags using the variable.
Event Parameter and Firebase User Property
For the event parameter variable, the value is set to a logged Firebase Analytics event parameter for the given key, whereas for Firebase User Property it is the property value.
This returns the value of a call to a pre-registered function.
ID for Advertising
For Android v4 and above, the value is set to Advertising ID, whereas for iOS 6 and above, the value is set to identifier for advertising (IDFA). For older versions, the value is set to “(the empty string)”.
Operating System Version
The value is set to the version of the operating system where the application is installed.
The value is set to a random number ranging from 0 to 2147483647.