Search code examples
regexgoogle-analyticsgoogle-tag-manageruniversal-analytics

Implementing two Analytics property's in one container with GTM


I want to implement Google Tag Manager over two domains which contain the same website/cms/code but with different content language. Therefore I want to use one container (One GTM code) with two tags in it. One tag contain the UA snippet for domainA.com and the other for domainB.com.

Here's the problem. How can I say to GTM that the analytics tag for domainA.com only will fire on www.domainA.com, domainA.com with and without https and/or http. Same case for Domain B

I was thinking of using a firing rule with regex ^(https?://)?(www.)?mysite.com

Will above option work with GTM and is it best practice? Or should I use two different containers so that domainA en domainB has his unique GTM tag?


Solution

  • Create a url macro of the type "hostname". Create a lookup table macro that assigns a Property ID according to the value of "hostname". Plug this macro into your Universal Analytics template tag. Use the default "all pages" rule (it will fire on both http and https pages without problems). If you want to use the same configuration for both domains that's much less hassle than creating the tags twice with different ids and rule sets.