You have a website. Google Analytics code is hard-coded on the back-end, per the out-of-the-box GA installation instructions. And it’s working! You’re getting channel data, reporting on insights, and can tell which landing pages are best.
Why would you want to change your configuration?
Google Tag Manager (GTM), or other tag management solutions, can provide additional data and expand on your reporting. If you’re not convinced about using a tag management solution yet, read this first.
GTM can measure data such as clicks, form conversions, and other specific engagement metrics relevant to your business.
If you’re already using Google Analytics and Google Tag Manager (or want to start using Google Tag Manager), you’re a good candidate for this solution: implementing Google Analytics code through Google Tag Manager.
This post will outline how to launch Google Analytics code through Google Tag Manager.
Benefits of Launching Google Analytics Through Google Tag Manager
There are a number of technical benefits to hosting Google Analytics code in Google Tag Manager.
Append Data in GTM Before Sending It to GA
By capturing data in GTM before sending it into GA, you can append and manage data collection, so that it’s cleaner going into your GA platform.
For example, if you want to measure site search tracking, but your URLs aren’t configured with the correct query parameter structure, you can use GTM to intake URL data, and parse out internal site search terms in a way that the Google Analytics report can read them.
Custom Dimensions and Metrics
GA doesn’t have the dimension or metric you want? No problem. You can create them in Google Analytics, and use GTM to assign what data maps back to them.
Another common reporting pitfall is incomplete cross-domain tracking between domains. Check out GTM expert Oeuyown Kim‘s post, where she walks through how to build a cross-domain tracking solution if you want more info on that.
Google has provided additional documentation on features and configurations that can be utilized by launching Google Analytics through GTM.
How to Do It
Here’s what you’ll need to set up Google Analytics through GTM:
- Google Analytics code
- Edit/Publish access in your Google Tag Manager container
- Access to the back-end code of your website
You’ll want to start the process by opening Google Tag Manager.
Create a Custom Variable for Your UA Code
Under the “Variables” section of Tag Manager, click the “New” button at the top right corner of “User-Defined Variables.”
Select the “Google Analytics Settings” variable type.
Insert the Tracking ID from Google Analytics and Save.
Create a Google Analytics Tag
In the “Tags” section of GTM, select “New” to create a new tag. Click “Tag Configuration” and select “Google Analytics: Universal Analytics” as the tag type.
Select “Page View” as the Track Type, your custom Google Analytics Variable as the Google Analytics Settings, and set the tag to fire on “All Pages.”
DO NOT PUBLISH YET. Do you have Google Analytics code hard-coded on your website? If so, it must be removed first.
If GTM is published before Google Analytics code is removed, then there are two sets of code collecting data and sending it back to one Google Analytics profile. This can result in erroneous and incorrect data, such as:
- Double-counting events and metrics
- Artificially low bounce rate
- Some sessions are counted twice
For this reason, we recommend removing any hard-coded GA tracking from your website first.
Remove Hard-Coded Google Analytics Code From Your Website
If you don’t have access to the back-end of your website, coordinate this with your web developer or web administrator. Remember that if you remove GA code, and don’t publish your GTM container shortly after, you’ll lose data tracking for that time period. Therefore, you don’t want a big time gap between removing hard-coded GA code and publishing your GTM container.
This brings us to the final step…
Publish Your GTM Container
You’re ready to publish your GTM container! After you’ve published, monitor Google Analytics to ensure that data is still coming through.
There should be no gaps in your reporting, and all data should look the same in GA as it did before. Hosting GA code in GTM, rather than hard-coding it on your website, simply changes the data collection mechanism, not the data itself, and there should not be any difference in data trends.
And now, you have the added benefit of flexibility with configuring GA and web tracking from GTM. If you’re feeling ambitious, consider implementing some additional settings on your Google Analytics tag for improved reporting!