The “Lookup table” macro is the ideal macro if you have installed one container across your domain and multiple sub-domains with each one having its own Google analytic property.
According to Google a Lookup Table macro “allows you to create a macro for which the value varies according to the value in another macro. This is useful if your website is set up in such a way that the appropriate value (for example, a conversion tracking ID) can be mapped to the URL or another aspect of the page. In this example, a macro named Conversion ID is being created. If the URL is “/thanks/buy1.html”, the value is set to “12345”; if the URL is “thanks/buy2.html”, the value is set to “34567”. There is no limit to the number of rows in the lookup table“.
This is very common within large organisations where different product owners set different profiles only relevant to what they are assigned to do (for example your development team having their own exclusive environment or your content team running the blog of the site on a subdomain) or even to small businesses with multiple subdomains such as blog.yourwebsite.com or product.yourwebsite.com.
Instead of creating different constant string macros for each property separately (as shown in our previous article here) you can use one lookup table macro for all your google analytic properties.
Here is a detailed explanation in how to do this:
Go to your Google tag manager interface and select “New Macro” and under the macro type, select “Lookup table”.
Then click on the {not set} icon and select {{url hostname}} as shown below
Name your macro something you will remember such as “GApropertyIDs” and then collect all your URL and the Google analytic property ID assigned to them in your Google analytics account. Please make sure that you have the exact URLs of all your domains as any mispell or variation will prevent the tag to fire.
On the first column start adding the domains and subdomains you wish to track (in our example lets assume the web site URL, the blog subdomain and the development subdomain0 and on the second column assign the relevant Google analytics profile id.
Once you are done and have listed all your properties, save the macro and go back to your Google Analytic Universal tag and use your new macro in the Tracking ID field.
Save the tag and that’s it. You now have three different Google analytic properties populated separately with the use of one tag.