Google Analytics 4 (GA4) is the latest version of Google’s web analytics platform, and it offers a range of powerful features for tracking and understanding website visitors. Integrating GA4 with Google Tag Manager (GTM) can help simplify the process of tracking events and conversions on your website, as well as make it easier to manage and deploy tags.
How to set up the main GA4 code
The installation of the GA4 tracking code on your website starts with the gtag.js tag, which is the basic code required to track visitor data. By deploying this tag on all pages, you’ll be able to collect the default data recorded by GA4.
Google Tag Manager makes the implementation of this tag a breeze, with just a few clicks and the insertion of your GA4 account ID.
Note:- if you already have Universal Analytics (analytics.js) running on your site, you should keep it in place. GA4 and Universal Analytics can coexist, and maintaining your Universal Analytics properties will preserve your historical data. GA4 will only start recording data from the moment of its setup, not from the inception of your website.
Here’s the process of install Google Analytics 4(GA4) with Google Tag Manager(GTM):
- 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.
In this blog post, we will provide a step-by-step guide on how to set up GA4 with Google Tag Manager.
Step 1: Create a GA4 Property
To start, you need to create a GA4 property in Google Analytics. If you already have a Google Analytics account, you can create a new GA4 property by clicking on the “Create Property” button in the GA4 section of your account. If you don’t have a Google Analytics account, you’ll need to sign up for one and You’ll need to provide basic information about your website, such as the website name and URL.
After entering your property name, which could be your website name, company name, brand name, etc., it’s time to specify your company’s country, reporting timezone, and main currency of operation. Simply press Next, answer a few questions, and then click Create to have your new property ready.
The final step in the setup process is to configure your first data stream. This data source will allow events to be transmitted to your GA4 property. You may have multiple data sources within a single property, such as three web properties, one for an Android app, and one for an iOS app.
In this blog post, I will focus on a Web stream. Select it.
After entering URL of your website(for example, https://www.bettershopme.com), ensure that the protocol (https) is already selected. Follow that by providing the name of your website.
When creating a web data stream in GA4, you have the option to enable or disable Enhanced Measurement. This feature is designed to assist marketers in obtaining a comprehensive view of events in their reports, without requiring assistance from developers or manual configuration in GTM.
By default, Enhanced Measurement is enabled in Google Analytics 4, which enables the automatic tracking of 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)
You have the flexibility to enable or disable each event by clicking the gear icon in the Enhanced Measurement section and then toggling the buttons. Press the Create stream button and you are ready.
Step 2: Get Your GA4 Tracking Code
Once you have created your GA4 property, you’ll need to get your GA4 tracking code. This code is unique to your GA4 property, and you’ll need to add it to your website in order to start tracking visitors.
To find your GA4 tracking code, go to the GA4 property you just created and Click the “Data Streams” option, and select “Web” menu. Click on the arrow (>) under “Data Stream” to go to “Web Stream Details” page. You’ll see a code snippet that you’ll need to add to your website.
Now on the “Web Stream Details” screen, under “Tag Instructions” tab find “Add New On-Page Tag”. This is where you can find “Global Site Tag (gtag.js).” Copy and paste this code into the <head> of every web page you want to measure.
Step 3: Create a GA4 Tag in GTM
Next, you’ll need to create a GA4 tag in Google Tag Manager. To do this, log in to your GTM account and click on the “Tags” section. Then, click on the “New” button to create a new tag.
CopIn the tag configuration screen, select “Google Analytics: GA4 Configuration” as the tag type.
Then,In Google analytics>Admin in data steam you created data stream (web), you will see a Measurement ID like below screen shot.
Copy and paste the Measurement ID you obtained in the above step into the “GA4 Configuration” field.
Step 4: Configure the GA4 Tag to Fire on All Pages
After you have created the GA4 tag in GTM, you’ll need to configure it to fire on all pages of your website. To do this, you’ll need to set up a trigger that fires the tag on all pages.
Go to the “Triggering” section of the tag configuration screen, and click on the “New” button to create a new trigger.
Select “All Pages” as the trigger type, and save the trigger.
Rename this tag from “Untitled Tag” to “GA4 Configuration Tag” or the name of your choice. Click on Save for saving this tag.
Step 5: Verify the GA4 Tag is Working
Now that you have created and configured the GA4 tag in GTM, you need to verify that it’s working correctly. To do this, you can use the Preview and Debug mode in GTM, or you can check the real-time report in GA4.
In the Preview and Debug mode, you can see a live preview of your website and track the events that are being sent to GA4. In the real-time report in GA4, you can see the events that are being recorded in real-time.
Check the Tag is firing Correctly in GTM
Click on the “Preview” button.
Enter the URL of the website and click the “Connect” option.
Check if the “GA4 Config Tag” appears under “Tags Fired”. Then your tag is installed correctly.
Now go back to Google Tag Manager Tab and click on “Submit”.
Give “Version Name” and add a detailed description of the changes made in this version. Click on the “Publish” button.
Establishing Google Analytics 4 can be a challenge, as is the case with all new endeavors. This guide aims to simplify the process and make it more manageable for you. If you have any further questions, don’t hesitate to reach out