Press ESC to close

How to Use Google Tag Manager with WordPress

How to Use Google Tag Manager with WordPress

Google Tag Manager (GTM) is a powerful tool that allows you to manage and deploy marketing tags (like tracking codes, pixels, etc.) on your website without having to modify your website’s code manually. Integrating Google Tag Manager with WordPress is a straightforward process that can give you greater control over your site’s analytics and marketing tools. Here’s a step-by-step guide on how to set up and use Google Tag Manager with WordPress.

1. Set Up Google Tag Manager Account

Step 1: Create a Google Tag Manager Account

  • Visit the Google Tag Manager website.
  • Sign in with your Google account or create one if you don’t have one.
  • Once signed in, click Create Account.
    • Enter your Account Name and Container Name (usually your website name).
    • Choose the container type as Web for a website.
    • Agree to the terms and conditions, then click Create.

Step 2: Get Your GTM Container Code

  • After setting up the container, you will be provided with two pieces of code (JavaScript snippets).
    • Head code: This code should go immediately after the opening <head> tag of your website.
    • Body code: This code should go immediately after the opening <body> tag.
  • You’ll need these snippets for the next steps, so keep this page open.

2. Install Google Tag Manager on WordPress

There are two ways to integrate Google Tag Manager with WordPress: manually adding the GTM code or using a plugin. We’ll cover both methods.

Option 1: Manually Add GTM Code to WordPress

Step 1: Access Your WordPress Theme Files

  • Log in to your WordPress dashboard.
  • Go to Appearance > Theme Editor.

Step 2: Add the GTM Code to Your Theme

  • Find the header.php file on the right side under “Theme Files”.
  • Copy the head code from Google Tag Manager and paste it immediately after the opening <head> tag in the header.php file.
  • Then, find the footer.php file, and paste the body code immediately after the opening <body> tag.

Step 3: Save the Changes

  • After pasting the code snippets, click Update File to save the changes to your theme.

Option 2: Use a Plugin to Add GTM Code to WordPress

If you’re not comfortable editing theme files manually, you can use a plugin to add the GTM code easily.

Step 1: Install and Activate a Plugin

  • Go to Plugins > Add New in your WordPress dashboard.
  • Search for “Insert Headers and Footers” or Header, Footer & Blocks for Elementor.
  • Click Install Now, then Activate.

Step 2: Add the GTM Code Using the Plugin

  • Once the plugin is activated, go to Settings > Insert Headers and Footers.
  • Paste the head code in the Scripts in Header section.
  • Paste the body code in the Scripts in Body section.
  • Click Save to save the settings.

3. Verify Google Tag Manager Installation

After integrating the GTM container code into your WordPress site, it’s important to verify that Google Tag Manager is properly installed.

Step 1: Use Google Tag Assistant (Chrome Extension)

  • Install the Google Tag Assistant Chrome extension from the Chrome Web Store.
  • After installation, open your website and click the Tag Assistant icon in your browser.
  • The extension will show if GTM is installed properly, and if there are any errors or issues.

Step 2: Use GTM’s Preview Mode

  • Go to your Google Tag Manager account.
  • Click on Preview in the top right corner to enable Preview Mode.
  • Visit your website in a new tab. A debug panel will appear at the bottom of the page, showing the tags firing on your site.
  • Check that the GTM tags are loading correctly.

4. Add Tags, Triggers, and Variables in Google Tag Manager

Now that GTM is installed on your WordPress site, you can start adding tags to track analytics, marketing pixels, and more.

Step 1: Add a New Tag

  • In your Google Tag Manager dashboard, click Add a New Tag.
  • Choose a tag type (e.g., Google Analytics, Facebook Pixel, AdWords Conversion Tracking).
    • For example, to add Google Analytics:
      • Select Google Analytics: Universal Analytics.
      • Choose Page View as the Track Type.
      • Enter your Google Analytics Tracking ID (you can find this in your GA account).

Step 2: Set Up Triggers for Your Tags

  • Triggers define when your tags will fire. For most tags, you’ll want them to fire on every page load.
    • Click on Triggering and select All Pages to fire the tag on every page of your WordPress site.

Step 3: Publish Your Changes

  • Once your tags, triggers, and variables are set up, click Submit in the GTM dashboard.
  • Give your changes a name and click Publish to make the tags live on your website.

5. Use Google Tag Manager for Specific WordPress Events

In addition to page views, you can use Google Tag Manager to track specific events or user interactions on your WordPress site, such as:

  • Form submissions
  • Button clicks
  • Scroll tracking

To set up event tracking:

Step 1: Add a Trigger for Specific Events

  • Go to Triggers in Google Tag Manager.
  • Choose Click or Form Submission triggers depending on the event you want to track (e.g., tracking a button click).
  • Use the Variables section to specify conditions (like clicking a specific button or submitting a form).

Step 2: Create a Tag to Fire on These Events

  • Create a new tag (e.g., a Google Analytics event tag or Facebook Pixel event tag).
  • Link the event trigger to this tag.
  • Publish your changes.

6. Test and Troubleshoot Your GTM Setup

After setting up your tags and triggers, it’s essential to ensure everything is working correctly.

  • Use GTM Preview Mode to check if your tags are firing as expected.
  • Check Google Analytics or your other analytics tools to confirm that the data is being tracked accurately.
  • Use tools like Google Tag Assistant or Chrome Developer Tools to troubleshoot any issues.

Conclusion

Integrating Google Tag Manager with WordPress gives you control over your website’s tags without needing to manually edit your site’s code. By following these steps, you can quickly add, update, and manage tags for analytics, marketing, and tracking purposes. Whether you’re using GTM for Google Analytics, Facebook Pixels, or other tools, it streamlines the process and helps you keep your website optimized for digital marketing.