In most situations, you’re fine just installing Google Analytics using one hardcoded Google Measurement ID ( former Google Analytics ID ) either in code or in the GA Tag in Tealium. But what if you need a different Google Analytics measurement ID for each website subdomain? Or if you have the same Tealium profile installed on more than one domain? Let’s see how to dynamically set Google measurement ID with Tealium first and then how to do this in an environment where you don’t use any Tag Management System ( GTM or Tealium ).
When could you need more than one Google Measurement ID?
First, let’s see some use cases for which you’d need conditionally set more than one GA ID.
- The same Tealium profile installed on the Sandbox version of the website – QA/DEV environment
- The same Tealium profile is installed on different websites
- Different Measurement IDs for each subdomain ( I.E. blog.website.com )
- Multilingual website with different data streams for each language
- Web and Apps share the same Tealium profile
Set GA measurement ID dynamically in the Tealium TagHere we are, now we’ll see how to conditionally set the GA IDs using the GA 4 tag offered by Tealium:
- Add the GA4 tag to your Tealium profile
- Leave blank the “Measurement ID” section.
- Create a variable holding the GA measurement value that should dynamically change
- Create a lookup table extension and set the previously created variable based on a variable you’d use to identify the domain ( or you can use “ut.env” to identify the Tealium environment you’re in ).
- In general, I suggest using these concatenated variables to get the most specification possible: <website_host>:<tealium_environment>:<platform>.
- Why also <Platform>? What if you have also Apps sharing the same Tealium profile? Surely it will come in handy.
Set GA measurement ID dynamically in your codebase
But, what if you don’t have any Tag Management System installed? We got you covered here. Let’s follow the steps also in that case:
- Create a function in which you’ll conditionally assign a GA Measurement ID based on the Website host and Website environment ( DEV or QA )
- Let the function run before the tag installation code on every page
- Instead of using the GA ID suggested by the installation code you have copied from Google Analytics, use your variable.
Even if the procedure is quite straightforward that can always be edge use cases not covered by the post. If you have a particular use case you want to show us let’s schedule a free 15-minute consultation call to see how we can help you!