We’ve created a detailed video on YouTube that explains the steps clearly and concisely. You can Watch the Video below.
If you prefer reading over watching, don’t worry—you can continue with the post below for the full explanation.
Google Analytics (GA4) and Google Tag Manager (GTM) Tutorial for Beginners
In this tutorial, you’ll learn how to set up Google Analytics 4 (GA4) and integrate it with your website using Google Tag Manager (GTM). I’ll guide you through the steps and explain why you’re making these decisions, so you understand what’s happening behind the scenes. Let’s dive in!
What Are Google Analytics and Google Tag Manager?
Before we start: Let’s understand what each of these platforms do
- Google Analytics (GA4) helps you track and understand how people interact with your website (e.g., which pages they visit, how long they stay, etc.).
- Google Tag Manager (GTM) acts like a middleman, making it easier to manage and update tracking codes (like Google Analytics tags) without constantly diving into your website’s code.
Why use GTM?
- Imagine you need to add multiple tools to your website (e.g., Google Analytics, Facebook Pixel). Instead of manually adding and editing each code snippet, GTM lets you handle everything in one place.
- It’s beginner-friendly and keeps your website’s code clean.
Setting Up Google Analytics (GA4)
Create a Google Analytics Account
This account will hold your website data.
-
- Go to Google Analytics.
- Click on “Start Measuring” and fill in:
- Account Name: Use a name that represents your business.
- Data Sharing Settings: Choose the defaults (recommended for most beginners). These settings help Google provide insights but avoid ticking “Google Products and Services” unless you want deeper integrations.
- Click Next to move on.


Create a Property
A property represents the website (or app) you want to track.
- 1. Fill in:
- Property Name: Use your website’s name for easy identification.
- Reporting Time Zone and Currency: Select based on your location or audience.
- Click Next.

Describe Your Business
This helps Google tailor reports to your needs.
Choose your Industry and Business Size.

For Business Objectives, tick options like:
- Leads (if you’re focused on signups),
- Sales (for e-commerce sites),
- Traffic and User Engagement (for content-heavy websites).
- Select “Other” only if your goals don’t match these categories.
Click Create and accept the Terms of Service Agreement.



Set Up a Data Stream
Choose Web as your platform.
Enter:
- Website URL (e.g., temi.co.uk or www.temi.co.uk) leave out the https://.
- Stream Name (e.g., “My Website”).
Click Create and Continue.


After Clicking on the Create and Continue button, You will see your web stream details
Like: STREAM NAME, STREAM URL, STREAM ID, and MEASUREMENT ID
Copy your MEASUREMENT ID, as you will need it later.

Pause: Why We Won’t Use the Code Provided by GA4

- Limited Flexibility with gtag.js:
Adding the code directly to your website means you’ll need to edit the site every time you want to track something new, like button clicks or form submissions. - Complexity in Managing Multiple Tags:
If you need to add more tracking tools (e.g., Facebook Pixel or Google Ads), you’ll have to edit your site’s code repeatedly, which can lead to errors. - Scalability Challenges:
As your website grows, so will your tracking needs. Managing all this through hard-coded scripts can become messy and difficult. - Risk of Breaking Your Site:
Updating the <head> section carries the risk of accidentally breaking your site, especially if you’re unfamiliar with code.
Instead, we’ll use Google Tag Manager (GTM):
GTM acts as a centralised hub where all your tracking codes live. This setup is:
- More Flexible: Easily add or update tags without touching your website code.
- Organised: Manage all your tracking tools in one place.
- Scalable: Effortlessly integrate additional tools as your needs evolve.
Analogy: Think of gtag.js as manually wiring each light in your home individually. GTM is like installing a central control panel—you can control all your lights (tracking codes) from one place with minimal effort.
Now that you understand why GTM is the preferred approach, let’s move on to setting it up.
Create a GTM Account and Container
Go to Google Tag Manager.
Click on Create Account:
- Account Name: Descriptive name for your business.
- Business Country: based on your location or audience.
- Container Name: Usually the website name, not the actual URL (e.g., Habanaija or Haba-naija, but not www.habanaija.com)
- Platform: Choose Web.
Click Create and accept the Terms of Service Agreement.




Add GTM to Your Website
During setup, GTM provides two code snippets that need to be added to your website:
- One for the <head> section.
- Another for the <body> section.

Instead of manually pasting these snippets (which requires editing your website’s code), we’ll use a plugin for ease and safety.
Why Use a Plugin to Add GTM?
- Ease of Use: You don’t need any coding knowledge.
- Error Reduction: Ensures the snippets are placed correctly without breaking your website’s design or functionality.
Steps to Add GTM Using a Plugin (WordPress)
In your WordPress dashboard, go to Plugins > Add New.
Search for GTM or Google Tag Manager for WordPress and install it.
Activate the plugin.
Go to Settings > Google Tag Manager and:
- Add your GTM ID (you can find this in your GTM dashboard, starting with GTM-XXXXX).
- Turn Container Code ON.
- Save your changes.




Test GTM Installation Using Tag Assistant
Before we proceed, let’s ensure GTM is installed correctly. We’ll use the Tag Assistant Chrome Extension for this.

Why Use Tag Assistant?
- Validation: Confirms GTM is working before you start tracking data.
- Debugging: Identifies any issues with tag firing.
Steps to Test Your GTM Installation:
- Install the Tag Assistant Chrome Extension (search “Google Tag Assistant Chrome” on Google).
- In GTM, click Preview.
- Enter your website URL in the popup and click Connect.
A new tab will open, and Tag Assistant will display whether GTM is installed correctly.





Creating a Tag in GTM to Send Data to GA4
Now that GTM is set up and connected to your website, we’ll create a tag to send data from your website to GA4.
What is a Tag?
In GTM, a tag is an instruction that tells the system what data to collect and where to send it. For example, in this step, the tag will send website pageview data to GA4.
Setting Up the GA4 Tag
- In GTM, go to Tags > New.
- Click Tag Configuration and select Google Analytics > Google Tag



For the Tag ID, where you need to paste your GA4 Measurement ID:
Click the variable icon next to the Tag ID input box.
Create a new variable:
- Choose Constant.
- Enter your Measurement ID (you can find this in your GA4 data stream settings).
Save the variable (e.g., {{GA4 – Measurement ID}}).






Variables
A variable in GTM is like a placeholder or a container that stores a value you want to reuse. It’s used to dynamically insert information into your tags, triggers, or other configurations. Think of it as a reusable label that points to a specific piece of information.
Why Use Variables?
- Reusability:
Instead of entering the same value multiple times (like your GA4 Measurement ID), you can save it in a variable. Whenever you need that value, you can simply reference the variable.
Example: If you’re creating multiple tags for different types of events (e.g., button clicks, form submissions, etc.), they can all use the same variable for the GA4 Measurement ID. - Efficiency:
If the value (e.g., your GA4 Measurement ID) changes in the future, you only need to update it in the variable. GTM will automatically apply the updated value to all the tags using that variable.
Analogy: Imagine you’re writing a book and decide to use placeholders like “{{ProtagonistName}}” for the main character’s name. If the name changes later, you only need to update it in one place instead of going through the entire book.
Creating a Variable for the GA4 Measurement ID
When setting up your GA4 tag in GTM, you’ll store the Measurement ID in a Constant variable.
- Constant Variable: This type of variable holds a fixed value that doesn’t change dynamically.
- Why Use It for the Measurement ID? The Measurement ID remains the same for your GA4 property, making a constant variable a perfect choice.
Add a Trigger
Triggers
A trigger in GTM is like a set of rules or conditions that tells GTM when a tag should fire (i.e., send data). It determines the when and where part of your tracking setup. Without a trigger, your tag won’t activate.
Why Use Triggers?
- Precision:
Triggers let you specify exactly when you want data collection to happen. For example: - On all pages of your website (a common choice for tracking pageviews).
- On specific pages (like a “Thank You” page after a form submission).
- When users perform specific actions (e.g., clicking a button, watching a video).
- Control:
They allow you to tailor your data collection to your business goals. You’re not tracking unnecessary events, which can clutter your reports.
Adding a Trigger to Track All Pages
When setting up your GA4 tag, you’ll attach a trigger that fires the tag on every page of your website:
- Trigger Type: All Pages is a built-in trigger that ensures the tag fires whenever a user visits any page on your site.
- Why Use All Pages? For basic GA4 setup, you want to track every pageview. This helps you understand user behaviour across your entire website.
How Variables and Triggers Work Together
When you create a GA4 tag in GTM:
- The variable (e.g., the Measurement ID) tells the tag where to send the data (your GA4 property).
- The trigger (e.g., All Pages) tells the tag when to fire (whenever a page is loaded).
Steps To Add a Trigger
- Click Triggering.
- Select All Pages to track visits to all website pages.
Save your tag.



Testing the GA4 Tag
- Click Preview in GTM.
- Open your website.
- In Tag Assistant, confirm that the tag fires correctly (look for “Google Analytics: GA4 Configuration” under “Tags Fired“).


Publishing the GA4 Tag
If everything is working as expected:
- Click Submit in GTM.
- Add a version name (e.g., “GA4 Setup”) and publish it.

Managing Versions in GTM
As you work with Google Tag Manager (GTM), it’s important to understand how versions work. Every time you make changes and publish them in GTM, a new version is created. Versions are a helpful way to manage your setup over time, especially if you need to revert to a previous configuration.


Here’s a breakdown of how versions work and why they’re important:
Why Use Versions in GTM?
- Track Changes: Each version represents a snapshot of your GTM setup at the time it was published. This is useful for keeping track of the changes you’ve made and ensuring that you can revert to a working version if something goes wrong.
- Revert to Previous States: If a tag or trigger is misconfigured and causing issues, you can easily go back to a previous version of your setup that was working fine.
- Consistency: Having versions allows you to maintain consistency across your tags and triggers. You can always go back to a version that’s known to work, which is especially useful in team environments.
How to Manage Versions in GTM
- Publishing a Version:
Every time you publish your container (e.g., after adding or updating tags, triggers, or variables), GTM automatically creates a new version. You can give the version a descriptive name (e.g., “GA4 Setup”, “Added Event Tracking”), so it’s easy to identify later. - To publish a version, simply click Submit after making changes.
- Enter a version name and optionally a description to help you identify the changes.
- Click Publish to save the changes.
- Viewing Versions:
You can view all your published versions in GTM by going to the Versions tab, which shows a list of all versions in your container. This allows you to see when and what changes were made. - Reverting to a Previous Version:
If you realise that something isn’t working after publishing a new version, you can revert to a previous version to restore the previous setup. Here’s how: - In GTM, go to the Versions tab.
- Find the version you want to revert to and click on it.
- Click Restore to revert your container to that version.
- Restoring a version ensures that you can easily undo any mistakes or issues caused by the most recent changes, which is especially important in production environments.
- Creating a New Version from an Existing One:
If you need to create a new version based on an older one, you can also do that. Instead of starting from scratch, simply clone the older version and make your changes, then publish the new version.
Best Practices for Version Management
- Use Descriptive Names: When publishing a version, give it a clear name and description, such as “GA4 Tag Configuration” or “Updated Event Tracking.” This will make it easier to know what changes were made.
- Test Changes Before Publishing: Before publishing a new version, always use GTM’s Preview mode to test your tags, triggers, and variables. This way, you can make sure everything is working as expected before it goes live.
- Keep Regular Backups: While versions in GTM act as backups, it’s still a good idea to export your container’s configuration periodically. This gives you an extra layer of protection in case you need to restore from an earlier point.
By managing versions properly, you’ll have full control over your tag setup, and you can easily roll back to a previous configuration if things don’t go as planned. This version control system makes it easier to maintain and update your GTM setup over time.
By following these steps, your website is now fully connected to GA4 using GTM, and you’ve set up a scalable and flexible system for tracking data.
Verify Your Setup in GA4
Once you’ve successfully implemented GTM and configured your GA4 tag, it’s time to check if the tracking is working as expected. Here’s how you can verify:
- Log into Your GA4 Account:
Go to Google Analytics and log in with your account credentials. - Navigate to the Real-Time Report:
In the GA4 dashboard, find the Real-Time report under the “Reports” section on the left. This report shows live data of visitors on your website, allowing you to quickly confirm that your GTM setup is tracking page views. - Check for Tracked Data:
If everything is set up correctly, you should see active users on your site in the Real-Time report. The “Page Views” metric will reflect the pages your visitors are viewing, based on the trigger you set (All Pages).




- Add More Tags for Other Events:
Now that you’ve successfully connected GTM to GA4, you can continue adding additional tags to track other events on your website. For example, you might want to track:- Button clicks
- Form submissions
- Video views
Each new tag you create in GTM can be linked to specific triggers and variables, expanding your tracking capabilities.
Conclusion
This real-time feedback ensures that your data collection system is working, and you’re ready to track user interactions across your site. From here, you can keep building on your setup by adding more tags and tracking more specific actions as needed.