Setting up and deploying Google Analytics tracking with Google Tag Manager (GTM) allows you to easily manage your tracking codes without modifying your website’s code directly. This process involves creating a Google Analytics account, configuring it in GTM, and then deploying the tracking tag on your website. Here’s a step-by-step guide on how to do it.
1. Create a Google Analytics Account
If you don’t already have a Google Analytics account, you’ll need to create one.
Step 1: Sign Up for Google Analytics
- Go to the Google Analytics website.
- Click on “Start for free” and sign in with your Google account.
- Click on “Set up for free” and follow the prompts.
Step 2: Create a Property
- After creating your account, you will be prompted to set up a property.
- Enter the property name (usually your website’s name), select your reporting time zone, and currency.
- Click “Next” and fill in the additional information about your business.
Step 3: Get the Tracking ID
- Once the property is created, you will be taken to the property setup page.
- You’ll find a “Web” option—click on it.
- Enter your website URL and name, and click “Create Stream.”
- After creating the stream, you’ll receive a Measurement ID (e.g.,
G-XXXXXXXXXX
for GA4 or a tracking ID likeUA-XXXXXXXXX-X
for Universal Analytics). Save this ID; you’ll need it later.
2. Set Up Google Tag Manager
If you haven’t already set up Google Tag Manager, follow these steps:
Step 1: Create a GTM Account and Container
- Go to the Google Tag Manager website.
- Click “Sign Up for Free” and log in with your Google account.
- Create a new account, enter your account name, and select your country.
- Create a container, name it after your website, and select “Web” for where to use it.
- Click “Create” and accept the terms of service.
Step 2: Install GTM Code on Your Website
- After creating your container, you’ll see two code snippets (one for the
<head>
section and one for the<body>
section). - Copy and paste these snippets into your website’s HTML as explained in the previous guide.
3. Create a Google Analytics Tag in GTM
Once you have both Google Analytics and GTM set up, you can create a tag in GTM to send data to Google Analytics.
Step 1: Access Your GTM Workspace
- Log in to your GTM account and select the container associated with your website.
- Click on “Workspace” to enter the main workspace.
Step 2: Create a New Tag
- Click on “Tags” in the left sidebar.
- Click the “New” button to create a new tag.
- Name your tag (e.g., “GA – Universal Analytics” or “GA4 – Page View”).
Step 3: Configure the Tag
- Click on “Tag Configuration.”
- Select the tag type:
- For Universal Analytics:
- Choose “Google Analytics: Universal Analytics.”
- Set “Track Type” to “Page View.”
- Enter your Tracking ID (e.g.,
UA-XXXXXXXXX-X
).
- For Google Analytics 4:
- Choose “Google Analytics: GA4 Configuration.”
- Enter your Measurement ID (e.g.,
G-XXXXXXXXXX
).
- For Universal Analytics:
Step 4: Set Up Triggers
- Click on “Triggering” to select when the tag should fire.
- Click the “+” button to create a new trigger.
- Choose “Page View” as the trigger type.
- Configure the trigger to fire on “All Page Views” (or customize based on your needs).
- Save your trigger and return to the tag configuration.
Step 5: Save the Tag
- After configuring the tag and triggers, click the “Save” button to save your tag.
4. Preview and Test Your Tag
Before deploying your tag, it’s important to test it to ensure it’s working correctly.
Step 1: Enter Preview Mode
- In GTM, click on the “Preview” button in the upper right corner.
- Enter your website’s URL and click “Connect.” This will open a new tab with your website in preview mode.
Step 2: Check Tag Firing
- Navigate through your website in the preview mode.
- The GTM debugger pane at the bottom will show which tags are firing.
- Ensure your Google Analytics tag is firing on page views as expected.
Step 3: Verify Data in Google Analytics
- Go to your Google Analytics account.
- Open the “Realtime” reports to see if your visits are being tracked.
- Check if your page views are recorded as you navigate your site.
5. Publish Your Changes
Once you’ve confirmed that the Google Analytics tag is working correctly, you can publish your changes in GTM.
Step 1: Submit Changes
- In GTM, click on the “Submit” button in the upper right corner.
- Provide a version name and a description (e.g., “Initial GA Setup”).
- Click “Publish” to make your changes live.
6. Additional Tags and Configurations
You can set up additional tags to track specific events (like button clicks, form submissions, etc.) using similar methods:
- Create a new tag for each event you want to track.
- Configure the tag type according to the event (e.g., “Event” for specific actions).
- Set up the appropriate triggers for those events.
- Test and publish as needed.
7. Best Practices
- Use Clear Naming Conventions: Use descriptive names for tags, triggers, and variables for easy identification.
- Document Changes: Keep a change log in GTM to track what modifications have been made and when.
- Regular Testing: Periodically test tags to ensure they’re firing correctly as your website evolves.
Conclusion
Setting up Google Analytics tracking through Google Tag Manager simplifies the management of tracking codes and allows for more flexibility in tracking user interactions on your website. By following the steps outlined above, you can effectively deploy Google Analytics and ensure you are gathering valuable insights into user behavior, helping you make data-driven decisions for your business.