
December 7, 2022
How to Setup and Install Google Analytics 4 with Google Tag Manager
Updated: December 7th, 2022
If you want to measure the performance of your website, you must use some web analytics tool. Google Analytics 4 is one of them. It allows you to see things like the number of sessions, visitors, most popular traffic sources, etc.
To get started, first, you need to install GA4 on a website. And in this blog post, I will show you how to do that.
Here’s the process of how to install Google Analytics 4 with Google Tag Manager:
- Create a new GA4 property
- Create a data stream (in this blog post, I focused on the Web stream)
- Copy the Measurement ID
- Create a Google Analytics 4 Configuration tag
- Paste the Measurement ID and set the tag to fire on All Pages
- Preview/test the new tag
- Publish the changes in Google Tag Manager
As you can see, everything is pretty straightforward. So let’s dive in.
A Video Tutorial on How to install Google Analytics 4
If you prefer video content, I have recorded a quick tutorial on my Youtube channel. But if you want to learn some additional details, read this blog post as well.
You’ll learn the most if you do both: watch the video and read the tutorial.
If you are currently using the older version of Google Analytics
What if you already use the older version of Google Analytics on your website? Should you ditch it completely and replace it with Google Analytics 4? Should you use them both?
To answer that, I have published another blog post (and a video tutorial) on this topic.
In a nutshell, Google Analytics 3 (Universal Analytics) stops collecting data on July 1st, 2023. That’s why you have to switch to another tool (e.g. GA4) as soon as possible.
This article is your first step of the migration process.
Create a Google Analytics 4 Property & Data Stream
If you want to create a new Google Analytics 4 property (and you are not using the Upgrade to GA4 option), then go to the Admin section of your Google Analytics interface (by clicking the Admin at the bottom-left corner) and then (in the Property section) click Create Property.
Then enter the name of your property. It might be the name of your website, of your company, a brand, etc. Choose your company’s country, reporting timezone, and the main currency in that your business operates in.
Then press Next, answer several questions, click Create, and your new property will be ready.
The next step to complete is to configure your first data stream. It is a data source from which events will be sent to your Google Analytics 4 property. You can have multiple data sources in a single property. For example, three web properties, 1 for Android app, and 1 for an iOS app.
In this blog post, I will focus on a Web stream. Select it.
Then enter the URL of your website (for example, https://www.mywebsite.com). Note that the protocol (https) is already selected. After that, enter the name of your website.
When you create a web data stream in Google Analytics 4, you have the option to enable/disable Enhanced Measurement. It is designed to help marketers get as many events in the reports as possible without the need to cooperate with developers or configure them in Google Tag Manager.
By default, this feature is enabled and will automatically track the following events:
- Page view (event name: page_view)
- Scroll (event name: scroll)
- Outbound link click (event name: click with the parameter outbound: true)
- Site search (event name: view_search_results)
- Video Engagement (events: video_start, video_progress, video_complete)
- File Download (event name: file_download)
- Form events (form_start, form_submit)
If you want, you can disable/enable events individually. You can do that by clicking the gear icon in the Enhanced Measurement section and then clicking the toggle buttons.
When you’re ready, press the Create stream button.
Install Google Analytics 4 with Google Tag Manager
When you create a data stream (web), you will see a Measurement ID.
At the top-right corner, you will see the tracking ID of your new property. Copy it. We’ll need to use it in Google Tag Manager.
By the way, if you ever get lost in the GA4 interface, and you need to revisit this page, go to Admin > Data Streams > choose your most recently created stream, and then you will return to the same window that I have displayed in the screenshot above.
Then go to your Google Tag Manager container (if you haven’t worked with it, here’s a tutorial on how to get started) > Tags > New and choose GA4 configuration.
In the Measurement ID field, enter the ID that you copied in the GA4 interface. Keep the Send a page view event when this configuration loads if you want to automatically track pageviews.
Usually, that’s ok keep it enabled. Still, in some situations, e.g. on single-page applications, it is more recommended to disable the pageview checkbox and create just a standalone configuration tag. You can read more about that here.
In the Triggering section, select All Pages and then name the tag, e.g. GA4 – Pageview.
Check the DebugView in Google Analytics 4
Enable the preview mode to test your changes.
Once you enable the preview mode, you should see the new GA4 tag among the tags that fired.
Once you configure your events, it’s time to test them. The primary feature built for debugging GA 4 data is the DebugView section.
Head over to your Google Analytics 4 account > Admin > Debugview.
Most likely, you will not see any data there (yet). That’s because that data in the DebugView is visible ONLY when the debug mode in GA4 is enabled. Do not mix this with the GTM Preview and Debug mode. They are two different beasts.
To enable the debug mode in GA4, you have several options (any of them will work):
- Enable the GA debugger Chrome extension
- Send a debug_mode parameter together with an event
- Have enabled Google Tag Manager’s Preview mode on a page that you’re debugging
In the case of the first option, install the extension here, and then click its icon (so you can see the ON ribbon). From this moment, you will start seeing your events coming into DebugView.
The other option is to send a debug_mode parameter with every event that you wish to see in the DebugView.
In Google Tag Manager, you can do that by opening the GA4 Configuration tag and adding the following parameter:
If the debug_mode parameter contains any value, the event will be seen in DebugView. If you are using a hardcoded gtag.js, here are the instructions for including the debug_mode parameter.
But since we are working with Google Tag Manager, having the GTM Preview mode enabled automatically sets the debug_mode to true. Thus the data will start appearing in the GA4 DebugView.
When you start seeing data in the DebugView, you can click on every individual event, and then a list of parameters will be displayed.
Click on that parameter to see the value that was received by GA4. Now that is some granular debugging!
However, I have noticed some delays between the event actually happening on a website and then appearing in DebugView. Sometimes, I have to wait for several minutes until the data come in. That’s a bit unfortunate, and hopefully, the team behind Google Analytics 4 will improve this in the future.
Sometimes, refreshing DebugView’s page helps too.
Also, ensure you have selected the correct Debug device in the top left corner.
If multiple visitors have enabled the debug view (e.g. they all have enabled the Chrome extension), you will see multiple devices there and it might require some time to find yourself. This especially applies to my blog, when many of my readers have enabled the GA Debugger Extension, and I have to guess which device (out of the other 15) is mine 🙂
Anyway, once you start seeing data in DebugView, things will look like this.
Publish your changes in Google Tag Manager
Once you made sure that the data is coming in and it is displayed properly, you should submit your GA4 changes in the GTM container and publish it.
You can do that by clicking the SUBMIT button in the top right corner and then completing all the other steps that the user interface asks you to do.
After that, you should soon start seeing the new data coming in your real-time reports as well.
Google Analytics 4 real-time reports
On the left sidebar of the Google Analytics 4 interface, go to Realtime. This is where you will see the data coming into your reports. Unlike in the previous version (Universal Analytics), the new report offers you capabilities to see the data on a much more granular level.
First, you will see a map and a bunch of cards with traffic sources, the most popular events, and the number of users in the last 30 minutes.
You can also take a look at the snapshot of an individual user. You can do that by clicking the View user snapshot button in the top right corner.
Then, you will see a stream of all events of that particular user, you can click on them (just like in the DebugView) to see things on a more granular level. If you wish to look at another user/visitor, you can click the button here:
To exit the snapshot, press the Exit snapshot button in the top right corner.
What’s next? More events!
I will not go into too much details here, but here are several things for you to configure next:
- Exclude your internal traffic
- Increase data retention to 14 months (because the default for most of the data is two months)
- Configure cross-domain tracking
You will also find additional migration tips in this free e-book. Also, you can watch this video.
Frequently Asked Questions
Here are some additional questions that you might have that I wanted to address.
What if I already have Universal Analytics installed on my site? Please refer to my blog post on how to upgrade to Google Analytics 4. But a short version is that you can use both GA versions simultaneously (as long as the old version still works).
What if I already have Google Analytics 4 tracking code hardcoded in the website’s source code? I would highly recommend implementing GA4 (or any other JavaScript-based marketing/analytics tool) via Google Tag Manager because of its flexibility. Click here to learn more about GTM benefits. But a short version goes like this: your developers should remove the hardcoded tracking code from your website, and you should implement Google Analytics 4 via Google Tag Manager. My Google Tag Manager Course for Beginners covers the process and tips on how to migrate hardcoded tools to Google Tag Manager.
If I already have Universal Analytics (GA3) implemented in Google Tag Manager, should I create a new GTM container for Google Analytics 4? No, you don’t need to create a new GTM container just for Google Analytics 4. Use your existing Google Tag Manager container for the new GA version as well. Google Analytics 4 requires completely different GA tags, but they can co-exist with Universal Analytics tags in the same container.
Final words on how to install Google Analytics 4
And that’s how you install Google Analytics 4 with Google Tag Manager on your website. The reason why this blog post was longer (than it should have been) is DebugView and real-time reports of GA4. I wanted to introduce them properly, and you must understand how they work.
Speaking of the process, here’s a summary:
- Create a new GA4 property
- Create a data stream (in this blog post, I focused on the Web stream)
- Copy the Measurement ID
- Create a Google Analytics 4 Configuration tag
- Paste the Measurement ID and set the tag to fire on All Pages
- Preview/test the new tag
- Publish your changes in Google Tag Manager
Got more questions? Feel free to ask in the comments below.
35 COMMENTS
Hey,
I wonder if it´s possible to anonymize IP in the configuration tag in GTM?
https://developers.google.com/analytics/devguides/collection/gtagjs/ip-anonymization
Is it done by adding a new field with anonymize_ip: true ?
Ga4 automatically anonymizes IP. Nothing to add.
Okay, thanks.
But in the config-tag I can still set the Same site cookie flag, right? (cookie_flags)
Hi Julius, great content.
One question, in GA4 if you want send custom data (like old custom dimensions, for example page_section) inside the page_view event, how do you have to add this data in GTM?
Thanks,
Hi, find my blog post about custom event tracking. You will find more information about custom parameters there
Hi Julius, what would you recommend for multi-country websites (different domains)? Several properties or 1 property with several data streams? Thanks in advance!
Hi Julius,
Thanks a lot for the content about GA4, it helped me make settings for my resource. But I still have a question about traffic acquisition. In the "Traffic Acquisition -> total" I see self-referrals, mydomain.com/referral. Could you suggest how to avoid self-referrals?
Hi,
Thanks for article found some things to fix at our initial installation of GA4. One thing I have been wondering is how would I set utm parameters for backend purchase conversion?
We are currently sending some basic data about conversions to ga4 but looks like all conversions have eg source/medium as (not set) / (not set). It seems not to be related to the previous events for the transaction from website either.
Hi guys, why in real time i not see the UTM, i have add in my url but i not see the params
Hello Julius,
Thank you for keeping posting awesome articles for GA4 implementation via GTM.
I have been encountering an embarrassing situation after trying lots of tests:
I am using the same GTM container to implement all recommended UA and GA4 events, so they share the same gtm.js, but we added separate dataLayer arrays for their events, odd thing is, while preview on GTM panel, for each UA event's dataLayer triggered will still succeed GA4 event's dataLayer, even though I don't see UA event's dataLayer triggered in GA4 event's dataLayer at the first stage.
I believe this will cause duplicate data issues for UA reporting, right?
Thank you for sharing your knowledge :)
While using the "existing Google Tag Manager container for the new GA version", we'll require to replicate tags/triggers for eCommerce tracking with GA4 configuration. Right?
It will fire two tags (two tags for the same/single purpose) on the website but data will be sent to two different analytics versions.
Triggers might be the same (but that depends on your current setup). But the rest you said is correct.
Hi Julius.
I set up just GA4 for a new client who had no Analytics. I did not see the option to add the old UA Property as well. The GA4 interface is not what I expected and a real let down as far as drilling down into the data. So I want to add a UA Property for the client as well.
Although I added a new UA Property on it's own after initially creating a GA4 and linked it to the GA4 ID it's not tracking anything. Do I have to add the UA-xxxxxxx-xx tracking code to the website in addition to the GTM tracking code or just add the Universal tracker to GTM?
Thanks in advance
Dave
Just the UA tag in GTM. And if you want to use GA4, have a separate GA4 config tag in GTM as well.
Hi. I prepare analytics for the newly created ecommerce. I want to use dual-tagging in GTM. I wonder if it is better to use the GA4 data layer or the UA?
If you also want to use Enhanced ecommerce, then it would make sense to use the EE data layer.
Or youcan have both data layer. One for EE and one for GA4.
Thanks for the reply. So I can't use GA4 ecommerce data layer for UA enhanced ecommerce events?
No
Hi.. I need your help in Ecommerce tracking in GA4.. I am very much confused .. Can you please help me out?
HI, The entire process of GA4 ecommerce setup with very detailed instructions is here https://www.analyticsmania.com/courses/intermediate-google-tag-manager-course/
Hi Julius,
If we already installed Universal Analytics using GTM, then if we want to install GA4 using tag manager, does it mean we have to create a new GTM account ? or can it be the same GTM account that we use to install Universal Analytics? I'm a bit confused there.
Use the same container
sorry Julius, i meant "new container", not account.
"same container" implies that the account will also be same :)
Hi Julius, when configuring a data stream on GA4 for a single page application, should I set the configuration triggers to All Pages AND history change? Would it make any difference on how it collects pageview data for the data stream? So far I've had one data stream firing only on All Pages, and it seems to be working okay, but I was wondering if adding the history change trigger on the configuration tag would do anything.
Thanks for your info by the way, I always refer to it for new GTM updates!
Hi again,
I have followed this steps.
Is it normal not seeing my GA4 measurement ID in the source code of the our website?
Thank you.
Yes, normal
Hi, Julius,
My question is, can I skip the dubug view section and just have GA4 installed via GTM?
I'm a bit lost about the debug view explanation there.
Thanks.
Not recommended
Hi Julius,
First of all - thanks so much for the content you're producing. It's extremely helpful!
I have a question, since my current e-comm runs on a plugin (that's how I inherited it and didn't bother to change since it was working good) that does not support GA4 as of now. I would like to start collecting GA4 data already and I'm thinking of introducing it with GTM separately (I have tried connecting the existing tag) but I fear for safety and/or data duplication. Is a set up like that a solution I can easily trust running? Should I also disconnect the UA tag from GA4 tag before?
Thank you, best!
Hi Julius,
I noticed that after I setup the GA4 with GTM (january), our bounce rate shows an abnormal drop. From, 50-60% bounce rate before the setup, it is below 10% starting Feb - present.
What could be wrong in here?
Our website is https://www.solarwhiz.com.au/.
The real-time report seems to be correct when I visit the site, it just shows 1 active visit.
Within GTM for GA4, what would you suggest for a sites that have multi language folders e.g.
example.com/en-uk - unique measurement ID
example.com/es-es - unique measurement ID
example.com/fr-fr - unique measurement ID
If you plan to build reports in GTM that show data from multiple languages at the same time, you will need to use the same measurement ID across all languages. Otherwise, you are fine with separate measurement IDs
Hi Julius,
Your blogs are very helpful in implementing GA4 with GTM.
Can you tell how to implement custom event parameters (data layer variables) in page views?
I tried adding the custom parameters as 'Fields to set' in GA4 Configuration Page view tag but I do not see those parameters within page view event in GA4. They are visible for other custom tags though.
Thanks
Do you recommend setting up a container for web, one for iOS and one for Android or one container for those three assets is enought? Thanks in advance.