Using a GTM Constant String Variable for GA Property ID
If you use Google Tag Manager and Google Analytics, you’ll know that with every new analytics tag you create, you need to enter in your Google Analytics property ID (what’s a property ID?). If you are creating multiple tags, this can be a pain and can also lead to possible typos/errors that will cause your tags to fail later on since you won’t be sending data to the right GA accounts.
There is a very quick and easy way to make this better! And more importantly, scalable. To do so, I’m going to show you how to use a constant string user-defined variable for your Property ID.
This is only 2 easy steps. First, you’ll need to create the new user-defined variable. To do so, select variables, new User-Defined Variable, and then select ‘Constant’ from the ‘Create Variable’ menu.
To configure the variable, I recommend you name this ‘gaProperty’ to be clear that this variable references your Google Analytics Property ID. In the value field, enter your GA Property ID in the format UA-XXXXXX-X where X is the unique numbers for your property. You can find your property ID under the Admin —> property settings page in your GA account. How to find your Property ID using the new GA dev tools Account Explorer.
Once you’ve created this variable, the final step is to use it in the Property ID field in all GA tags you build in GTM, as seen below. If you already have tags that use a hard-coded property ID they will continue to work, but I’d recommend replacing the hard-coded number with your new gaProperty variable.
This also has the added benefit of universal changes – any change to the gaProperty variable will propagate to all tags using that variable – very useful if you need to change IDs down the road!
Happy tagging!
Dan
Thanks for sharing, very helpful. In the new version of Tag Manager it’s a little bit different but still the same concept.