The Basics of Google Tag Manager and Google Analytics 4

Google Tag Manager and Google Analytics 4 are powerful tools that many websites and applications use to track performance and gain user insights. However, with lots of conflicting information and out-of-date tutorials out there, it can be tricky to get started without feeling overwhelmed. This article attempts to simplify the general process so you can feel more confident experimenting with these tools within the context of your unique needs.

Overview

Google Tag Manager (GTM) is a free tool that allows you to add "Tags" or snippets of code that collect data and send it wherever you want to store it (for the purposes of this article, we'll assume we're sending data to Google Analytics 4). While you don't technically need GTM in order to send data to GA4, it simplifies the process and allows you to add, remove, and edit tags without needing to deploy any code. 

Google Analytics 4 (GA4) is a tool that accepts data sent from GTM and compiles it into reports that you can view, filter, export, etc. for purposes of interpreting and assign meaning to that data. Google Analytics isn't the only place that GTM can send data, but it is the one that we will be talking about in this article.

Important terminology

Before you start experimenting with these tools, it's good to know a few key terms to avoid confusion (since they're used everywhere in documentation):

  • Tag: A snippet of code that sends data to Google Analytics (or another system) when fired.
  • Event: An interaction or occurrence on a website (Page load, click, form submit, etc.)
  • Trigger: A rule that determines which Event(s) will cause a Tag to fire.
  • Parameter: A key/value pair that provides additional information about an event. (i.e. Referrer)
  • Variable: A placeholder that stores a value that can be used by a Tag or Trigger. (i.e. User ID)
  • Container: A grouping of Tags created for different web properties. Container types include: Websites, AMP Pages, Android Pages, iOS apps.

Assumptions

This article assumes that you have already set up a GTM and GA4 account/property, and you've already linked GTM to your website. For a Drupal website, there is a handy GTM Drupal module that simplifies this process. 

A general process to follow

While this simple process may not fit every need, it is generic enough to explain how things tend to work in these systems. I'll walk through the process of adding a very simple tag: tracking how many users submit a contact form.

Step 1: Create a new trigger in GTM

First, you must determine when GTM should send data. There are many built in triggers that you can use, such as Page View, Form Submit, etc. For this example, let's assume we have a "Thank You" page that a user reaches only after submitting the contact form. I'd add a trigger called "Contact Form Submission" which fires whenever a user reaches a particular URL.

Trigger configuration page showing a "Page View" trigger type that points to a thank you page URL.

Step 2: Create a new tag in GTM

Next, you must decide what should happen after your trigger fires. For this example, I made a new tag called "New Lead," and I selected the "Contact Form Submission" trigger that I made in the previous step. For "Tag Type," I've selected GA4 Tag, since I want my data to be sent to GA4, but there are many other tag types you could select based on what systems you're using.

Tag configuration form showing a GA4 tag called contact_form_submit that references the Contact Form Submission trigger.

Important: Make sure you add the GA4 Measurement ID that connects this tag to the appropriate GA4 property. In GA4, this can be found by navigating to Admin -> Data Streams -> [Property].

Step 3: Test, test, test!

GTM has a "Preview" function which allows you to test your workspace changes before publishing them. When you use this preview, you are essentially viewing your website in a debug environment. You can then test your trigger to make sure the tag fires properly. If it doesn't, then you can go back and change your configuration until things are working properly.

GTM preview screen showing which tags have fired and which tags haven't.

Step 4: Publish and wait

After publishing your new trigger and tag, you must wait for data to actually be captured before you will be able to see anything in Google Analytics (For our example, that means that at least one person must fill out the contact form and reach that confirmation page URL).

Step 5: View data in Google Analytics

Once you have data flowing into Google Analytics, you can start experimenting with creating reports. Google Analytics provides many built-in reports, but to view your custom data, you'll need to edit these reports to expose or filter on that data.

A graph showing data for the new tag "contact_form_submit"

Adding custom data through the Data Layer

If you need to do something custom that isn't available to you within the GTM user interface, then you can also use javascript to send your own data. Say you want to pass a user ID to GTM so you can use it to filter data between anonymous/authenticated users. You might do this by pushing the Drupal UID to a user_id variable in GTM:

window.dataLayer = window.dataLayer || [];
dataLayer.push({
  user_id: settings.logged_in.userId,
}); 

In order for this to work, however, you must ensure that the variable that you're attempting to attach data to actually exists in GTM. For the above code, that means that the `user_id` variable must exists in GTM.

There are many built-in variables that you can use out of the box, but if you do need to add a custom variable, you can do that in GTM in the Variables section.

GTM variable configuration screen showing a new data layer variable called user_id

Conclusion

These tools are incredibly powerful, and there's a lot that you can do with them. Hopefully this high-level overview gives you some confidence to start experimenting more with your specific needs in mind. If you'd like a consult on your project's specific analytics needs, feel free to reach out to RDG for a consult.

Need a fresh perspective on a tough project?

Let's talk about how RDG can help.

Contact Us
Team Insights
Client Resources
Planning & Strategy