How to Set Up Google Analytics 4 with Google Tag Manager
Google Analytics 4 (GA4) offers a robust and event-based approach to tracking website activity. However, the deprecation of Universal Analytics has forced many marketers to relearn their favorite analytics platform and go through a new setup process. Event and conversion setup also comes with a higher learning curve. Thankfully, Google Tag Manager (GTM) can ease the process of setting up GA4 on your site and reduce the dependency on needing to customize code. In this article, we will guide you through the step-by-step process of deploying the basic GA4 tracking code through GTM, along with creating custom events for more comprehensive data.
How to Set Up the Main Google Analytics 4 Code
The first step in setting up GA4 with GTM is to add the main GA4 tracking code to your site. This code, known as the gtag.js tag, needs to be placed on all pages of your website to start recording default data tracked by GA4 for website visitors. Fortunately, GTM makes setting up this tag simple and straightforward.
Here’s how you can set up the main GA4 code using GTM:
Step 1: Add a New Tag in GTM
To begin, navigate to your desired GTM account and container and select “Add a new tag.” This will open the tag creation window.
Step 2: Configure the GA4 Tag
In the tag creation window, click on “Tag Configuration” to see the options for various types of tags. Select “Google Analytics: GA4 Configuration” as the tag configuration.
Step 3: Enter your Measurement ID
In the GA4 configuration settings, you’ll see a field to enter your Measurement ID. This ID can be found in your GA4 account. Copy and paste the Measurement ID into the designated field in GTM.
Step 4: Customize Tag Settings
You can customize the tag settings according to your preferences. For most users, it is recommended to leave the box checked to “Send a page view event when this configuration loads.” This ensures that each time a user visits a new page, a pageview is tracked in GA4. However, there may be instances where you don’t want to fire a pageview, such as when setting properties for a logged-in user or a customer completing a transaction without the page URL changing.
Step 5: Set Up Triggering
Click within the “Triggering” box to choose where you want the tag to fire on your site. In most cases, you’ll likely want GA4 to fire on all pages. However, depending on your setup, you may want to exclude certain pages, such as private login sections. You can create rules based on URL paths, clicks on specific page elements, and more to customize where the tag fires.
Step 6: Save and Publish
Save your tag and publish your GTM container to push it live. You should now see GA4 firing on your site. To confirm that you’re tracking sessions, check the Realtime section of Google Analytics. You should see your own visit reflected here soon after hitting the site.
With the basic gtag.js tag in place, you can proceed to set up additional customization, such as adding events.
Setting Up Event Tracking for Google Analytics 4 in Google Tag Manager
While GA4 has automatic event tracking and enhanced measurement capabilities, there are instances where you may want to track custom events that are not covered by the default settings. This is where GTM comes in handy. By using GTM, you can easily set up custom event tracking for a wide range of actions on your website.
Here’s how you can set up event tracking for Google Analytics 4 using GTM:
Step 1: Create a New Tag for the Custom Event
To begin, create a new tag in GTM with a Tag Type of “Google Analytics: GA4 Event.” Choose your GA4 ID under “Configuration Tag.”
Step 2: Define the Event Name
Enter the Event Name that you’d like to appear within the Google Analytics interface. This should be a descriptive name that accurately represents the event you want to track. For example, if you want to track form submissions, you can name the event “form_submission.”
Step 3: Configure Event Parameters
Click on the Event Parameters section to expand it. Here, you can add custom parameters to send additional details about the event to Google Analytics. For example, if you want to track the form submission’s category or value, you can add parameters for those.
Step 4: Set Up Triggering
Next, you’ll need to create a trigger to determine when the event should be tracked. Click in the bottom Triggers section to start a new trigger and select the appropriate trigger type based on the action you want to track. For example, if you want to track form submissions, you can select the “Form Submission” trigger type.
Step 5: Save and Publish – Google Analytics 4
Save the trigger, save your tag, and publish your GTM container to make the event tracking live on your site.
You can use the same basic model presented above to fire additional events into Google Analytics. Whether you want to track button clicks, video views, or other user interactions, GTM provides a flexible and customizable solution.
Conclusion
Setting up Google Analytics 4 with Google Tag Manager allows you to track website activity and events in a more efficient and customizable way. By following the step-by-step instructions outlined in this article, you can easily deploy the basic GA4 tracking code and create custom events to capture comprehensive data. Remember to regularly review and analyze the data collected to gain valuable insights into your website’s performance and user behavior. With GA4 and GTM, you have powerful tools at your disposal for effective website tracking and analysis.