Last Updated on December 12, 2022 by Justin Clifton
Note: This article previously covered how to add Universal Analytics (UA) via GTM, but it has been updated to cover GA4. UA will stop processing new hits on July 1, 2023. It’s very important to make sure that you have a proper GA4 setup before that date.
There are many ways that you can add Google Analytics (GA4) to a site. After many years of freelancing as a web analytics expert, I’ve come across about every implementation imaginable. And oftentimes more than one implementation at the same time. One of my favorite ways to add GA4 to a site is with Google Tag Manager (GTM). It’s easy to setup and very flexible if you ever need to make customizations to your GA4 implementation. And it can be a lot more user-friendly than editing code. But before we get into how to add GA4 to GTM properly, let’s take a moment to go over the options for adding GA4 to a website.
- Some web platforms have built-in integrations for Analytics, you can add Analytics code directly to the backend of the platform. If your platform has a built-in integration, it’s typically best to use it.
- For WordPress users, there are many plugins you can use for adding Google Analytics to your site.
- You can directly add a Google Analytics JavaScript code snippet to your site. The modern version of this is called GTAG (Global site tag) which can also be used to send data to Google Ads.
- You can use a tag management system like Google Tag Manager.
It’s a best practice to choose between adding code directly to your site or using a tag management system for all or the majority of your tags. If you mix and match, it can be hard to remember if you added that one tag in GTM, added it directly to the site, used a plugin, etc. Try to stick to one main method in order to maintain good organization and consistency for the site tagging. It’s best to have everything in one place if possible. For your sake and for anyone else that works on the site. With that being covered, hopefully you’re ready to proceed with implementing GA4 via GTM.
Before you begin, make sure that you have appropriate account privileges in GA4 and GTM. If you can’t view or edit anything from the instructions, then you probably don’t have sufficient privileges.
Step 1: Finding Measurement ID In GA4
Navigate to your GA4 property on the Analytics site. Ensure you’re in a GA4 property and not a UA property. Once you’re in the right GA4 property follow these steps:
- Click on admin (gear at the bottom left)
- Click on data streams
- Click on your web stream
- Copy the measurement ID with the form G-XXXXXXXXXX
Step 2: Create A GA4 Configuration Tag
In the sidebar, click on Tags. Then click on new to create a tag. Name the tag “GA4 – All Pages” or “GA4 – Config” and click on the tag configuration box. Select “Google Analytics: GA4 Configuration” and then paste the measurement ID from step 1 in the field for measurement ID. Make sure that “Send a page view event when this configuration loads” is checked. The checkbox for “Send to server container” should be unchecked unless you want to implement server side tracking. Server side tracking is a much more complex setup that goes beyond the scope of this article. It has various pros and cons but the bottom line is that most people reading this article probably only need a vanilla GA4 web based setup which is what this article covers. For “Fields to Set”, “User properties”, and “Advanced Settings” just leave everything unchanged. Then for the trigger section add a page view trigger for all pages.
Step 3: Publish The GTM Container And Verify
Once you’ve completed steps 1 and 2, go ahead and publish your GTM container. Click on the submit button in the top right of GTM. The version name will depend on your personal preferences and if your container has been published previously. I typically just do V1, V2, V3, etc. for every time I publish the container. So if the current container is V4, I’ll publish it as V5 with the updates. Other people like to add in the date. At the end of the day, there’s many ways you can do this. Just pick a system that works for you and stick with it. Assuming the container has never been published before, just use V1. If you’re not sure if the container was published previously, click on versions at the top left of GTM. If you see some history there, then name your container accordingly. In the description for the version, you can describe any changes you made for the current version. It’s a good habit, but not strictly necessary.
Once the container is published, check to make sure GA4 is loading on your site properly. Again, there are multiple ways to do this. One way is to use the Google Tag Assistant which is a Google Chrome extension. After publishing, just go to your site, click on the extension, then click enable. You’ll be prompted to reload the page after activating the extension. Assuming you did everything correctly, you should see a GTM tag and an Analytics tag with your GA4 ID. You might see other tags depending on your GTM setup and any other tags which could be loading directly from the site. If you see the same GA4 ID multiple times, then you have another implementation of GA4 (perhaps from code directly added to the <head> section or via a plugin) which should be removed.
Warning
Sometimes I’ll come across client GTM accounts that are adding Analytics via a custom HTML tag with a GTAG snippet inside of it. They fire this custom HTML tag on all pages. While this will load Analytics on your site (assuming the GTAG is correct), it’s not the proper way to add Google Analytics via GTM. If you want to use the GTAG to load GA4 on your site, that’s fine. But add the GTAG Analytics code directly to the site in the <head> section, not in a custom HTML tag in GTM. If you’re going to add GA4 via GTM, this article covers the proper way to do it with the dedicated tag for GA4 in GTM.
As a technicality, there are cases when you might want to add a GTAG for Google Ads with a phone call conversion snippet as a custom HTML tag in GTM as described in this article. This is distinct from just adding a Google Analytics GTAG in a custom HTML for the sake of implementing GA4. Beyond that potential exception, you don’t need to add any GTAG code to custom HTML tags in GTM.
Conclusion
GA4 and GTM are both really amazing tools that any digital marketer or web developer should learn as much about as possible. This article is just scratching the surface, but it’s a great start nonetheless.