How to Install & Set Up Google Tag Manager in WordPress: Complete Guide 2024

Dec 14 2024

Written by: P1 Growth Team

Step-by-step guide to installing Google Tag Manager in WordPress, including best practices and troubleshooting tips for proper tracking implementation.

Google Tag Manager WordPress Set Up Guide

Google Tag Manager (GTM) is an essential tool for modern digital marketing, allowing you to manage and deploy marketing tags without modifying your website’s code directly. In this comprehensive guide, we’ll walk you through the process of installing and configuring GTM on your WordPress site.

⏱️ Implementation Time: 15-30 minutes for basic setup, 1-2 hours for full configuration with common tags

Table of Contents

  1. Why Use Google Tag Manager?
  2. Prerequisites
  3. Step-by-Step Installation Guide
  4. Verification and Testing
  5. Common Use Cases
  6. Common Issues and Troubleshooting
  7. Best Practices

Why Use Google Tag Manager?

Before diving into the installation process, let’s understand why GTM is crucial for your marketing stack:

  • Centralized Management: Control all your tracking codes from one dashboard
  • Improved Site Performance: Better tag loading and management
  • Version Control: Track changes and roll back if needed
  • Quick Updates: Deploy tracking changes without developer involvement
  • Enhanced Security: Reduce risks associated with direct code modifications

Prerequisites

Before starting, ensure you have:

  1. A WordPress website with administrator access
  2. A Google Tag Manager account
  3. Access to your WordPress theme files or a code injection plugin
  4. Basic understanding of WordPress administration

Step-by-Step Installation Guide

1. Create a GTM Account and Container

  1. Go to Google Tag Manager
  2. Click “Create Account”
  3. Fill in your:
    • Account Name (usually your company name)
    • Country
    • Container Name (your website name)
    • Target Platform (Web)
  4. Accept the Terms of Service

2. Get Your GTM Code

After creating your container, GTM will provide two code snippets. Here’s what they look like:

Head section code example:

<!-- Google Tag Manager -->
<script>
  ;(function (w, d, s, l, i) {
    w[l] = w[l] || []
    w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" })
    var f = d.getElementsByTagName(s)[0],
      j = d.createElement(s),
      dl = l != "dataLayer" ? "&l=" + l : ""
    j.async = true
    j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl
    f.parentNode.insertBefore(j, f)
  })(window, document, "script", "dataLayer", "GTM-XXXXXX")
</script>
<!-- End Google Tag Manager -->

Body section code example:

<!-- Google Tag Manager (noscript) -->
<noscript>
  <iframe
    src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
    height="0"
    width="0"
    style="display:none;visibility:hidden"
  ></iframe
></noscript>
<!-- End Google Tag Manager (noscript) -->

Replace GTM-XXXXXX with your actual GTM container ID.

3. Install GTM in WordPress

  1. Install and activate “Insert Headers and Footers” plugin
  2. Go to Settings → Insert Headers and Footers
  3. Paste the first GTM code snippet into the Header section
  4. Paste the second code snippet into the Body section
  5. Save changes

Method 2: Manual Installation (Advanced)

  1. Access your theme’s header.php file
  2. Paste the first GTM code snippet immediately after the opening <head> tag
  3. Locate your theme’s header.php or body.php file
  4. Paste the second code snippet immediately after the opening <body> tag
  5. Save both files

Verification and Testing

To ensure proper installation:

  1. Install the “Tag Assistant” Chrome extension
  2. Visit your website
  3. Click the Tag Assistant icon
  4. Verify GTM is shown as properly installed
  5. Check for any warning messages

Common Use Cases

Here are some popular implementations we regularly set up for our collaborators:

1. Event Tracking

Track specific user interactions like:

// Example click event tracking
dataLayer.push({
  event: "button_click",
  button_text: "Sign Up Now",
  button_location: "hero_section"
})

2. E-commerce Tracking

Track purchase events:

// Example purchase event
dataLayer.push({
  event: "purchase",
  transaction_id: "12345",
  value: 99.99,
  currency: "USD",
  items: [
    {
      item_name: "Premium Subscription",
      price: 99.99,
      quantity: 1
    }
  ]
})

3. Form Submission Tracking

// Example form submission tracking
dataLayer.push({
  event: "form_submit",
  form_name: "contact_form",
  form_location: "contact_page"
})

Common Implementation Examples

  1. Google Analytics 4 Setup

    • Implementation time: 15 minutes
    • Key tracking: Pageviews, events, user behavior
  2. Meta (Facebook) Pixel

    • Implementation time: 20 minutes
    • Key tracking: Page views, custom events, conversions
  3. Custom Event Tracking

    • Implementation time: 30-60 minutes
    • Examples: Button clicks, form submissions, video plays
  4. E-commerce Tracking

    • Implementation time: 2-4 hours
    • Key tracking: Purchases, cart actions, product views

Common Issues and Troubleshooting

Issue 1: GTM Not Showing in Tag Assistant

  • Verify code placement in correct locations
  • Clear browser cache and reload
  • Check for conflicting plugins

Issue 2: Multiple GTM Installations

  • Search all theme files for duplicate GTM codes
  • Check header/footer plugins for duplicates
  • Review child theme files

Best Practices

  1. Use Preview Mode: Always test tags in GTM’s preview mode before publishing
  2. Document Changes: Keep a log of implemented tags and their purposes
  3. Regular Audits: Review and remove unused tags quarterly
  4. Backup First: Always backup your site before making GTM changes
  5. Use Folders: Organize your tags, triggers, and variables in GTM

Next Steps

Now that GTM is installed, you can:

  • Set up Google Analytics tracking
  • Implement conversion tracking
  • Add remarketing tags
  • Track form submissions
  • Monitor file downloads

Need Professional Help?

At P1 Growth, we specialize in technical marketing implementations and analytics setup. Contact us for expert assistance with your tracking needs.