Ralf
Ralf

Reputation: 255

Can I add Google Tag Manager to two domains, being flexible on the ID?

I have two domains, a .nl and a .be domain. Both have their own Google Analytics IDs. Currently I have the analytic code on the website and, depending on the domain, the correct ID is inserted into the code. The tracking works correctly on both sites.

Now I want to implement the Google Tag Manager, to get more flexibility for Javascript. The struggle is now how get to the same result, without implementing the Google Tag Manager twice (or more if more domains are added).

How can I achieve this? I tried with the rules in combination with a regex on the {{url}}, but without any success.

Upvotes: 0

Views: 149

Answers (1)

Eike Pierstorff
Eike Pierstorff

Reputation: 32760

The best way if you want to prepare for more domains would be a lookup table macro.

First create a url type macro that return the hostname. Then create a macro of the type lookup table - that is a macro that returns a value based on the value of another macro. It should look something like this ( {{url hostname}} is the macro that holds, well, the hostname) :

enter image description here

Then insert the macro name ( {{Google ID}} in the example in the screenshot) in the "Tracking ID" field in you Google Analytics Tag and it will be set according to the domain name. If you want more domains just add a row to the lookup table.

Upvotes: 2

Related Questions