Use constant string user-defined variables

Before progressing too far in your Google Tag Manager implementation, we recommend that you set up a couple of reusable user-defined variables. These will save you a lot of time and possibly prevent errors later on.


The gaProperty variable is a quick way to add your Tracking ID to new tags. Rather than typing out your Tracking ID every time you create a new tag, just select the gaProperty variable. In the example below, you’d replace UA-XXXXXXXX-X with your own analytics Tracking ID.

Create Variable screen: Setting up a gaProperty variable


The gaDomain variable is an easy way to ensure that your domain is always set to auto (Automatic Cookie Domain Configuration is a best practice for Universal Analytics; read more on the Developers site). To set this up, just create a new Constant variable and set the domain to auto, as in the screenshot below.

Create Variable screen: Setting up a gaDomain variable


If you have traffic moving between multiple web properties tracked under the same analytics account, you’ll want to set up Cross Domain tracking. This constant string variable (gaCrossDomains) will make that easier. Rather than typing in your comma-separated list of URLs each time in the Cross Domain Tracking setting for all of your analytics tags, you can just reference one variable.

This also makes it much simpler to edit and update your list of owned domains under the same Analytics tracking code, because you can update a single variable instead of updating each individual tag.

To set the gaCrossDomains variable, first you’ll need a full list of all of your unique top-level domains (not subdomains). For this example, we’ll use,, and Simply enter these values as a comma-separated list into the constant string variable. See example below.

Note that the cross-domains that you'll enter here will be loaded into the autoLink plugin when you enable cross-domain tracking in your Google Analytics tag via this constant string variable. This checks whether the domains of the link clicked (or optionally form submitted) contain any of the array entries as substrings. For example, you may have,,,, etc. Entering "SiteA" into the gaCrossDomains variable will handle all of these domains.

Create Variable screen: Setting up a gaCrossDomains variable
Domain names are case-sensitive. If you use and, you’ll want to add both to your list.

Previous: Naming conventions and setup tips | Next: Data layer or Google Tag Manager UI?

Was this article helpful?
How can we improve it?