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.
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)
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.
Now you should be able to use the Lookup table variable as your Tracking ID in your Google Analytics Tag.
You should of course set constant variables with your Google Analytics Property IDs for debug and live mode.