Soren Dam
  • Blog
  • Contact

Dynamic Google Analytics Property ID in Google Tag Manager using Lookup Tables

June 24, 2015

By Søren Friis Dam

It is recommended to set the Google Analytics Property ID as a variable in so you can easily reuse it in Google Tag Manager. But what if you want track to a different property if you are in debug mode? You could then create a Debug Mode variable and use that in a Lookup Table to determine whether to use the live or debug Google Analytics Property ID.

Google Tag Manager Debug Lookup Google Analytics Property ID

Now, this is great for a lot of cases. But what if you are developing on localhost and have a staging server that you don’t want to be tracked in Google Anlytics as this could mess up your data?

The solution is another Lookup Table that has the Host Name as the input variable. We will not use it directly – more on that below. First, if the host name equals your live domain then output your Google Analytics Property ID for you live site. If the host name doesn’t match your live you set a default value to your Google Analytics Property ID for your development/staging site (and also for debug mode in Google Tag Manager)

Google Tag Manager Host Name Lookup Table

Now alter (or create) the Lookup Table that has the input variable as Debug Mode; if debug mode is true always return you Google Analytics Property ID for your development/staging site. If we are not in debug mode “ask” the Lookup table above if we are on the live domain. If we are, return the live Google Analytics Property ID. If we are not, return the debug Property ID.

Google Tag Manager Debug and Host Name Lookup

Now you should be able to use the Lookup table variable as your Tracking ID in your Google Analytics Tag.

Google Tag Manager Property ID as Lookup Table Variable

You should of course set constant variables with your Google Analytics Property IDs for debug and live mode.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Contact
  • © 2025 Søren Friis Dam