Google Tag Manager Tracking Guide for WordPress
This guide shows you how to track:
How to setup Google Tag Manager Tracking in WordPress
- Create Google Account or Login to your existing Google Account
- Sign into Google Tag Manager
- Create a new Google Tag Manager Account (e.g. Penguin Initiatives)
- Create a new Google Tag Manager Container for your website (e.g. penguininitiatives.com)
- Copy your new Google Tag Manager Container’s GTM ID (e.g. GTM-P3XHZF):
- Login to your WordPress website’s Admin Dashboard and go to Plugins > Add New
- Search for “DuracellTomi”, click the “Install Now” button for “DuracellTomi’s Google Tag Manager for WordPress” and then activate the plugin
- Go to Settings > Google Tag Manager
- Paste in your Google Tag Manager ID and click the “Save Changes” button
- Right click and save this Google Tag Manager Container Template for WordPress
- In your Google Tag Manager account click on the “Admin” section
- Select your new Google Tag Manager Account and Container
- Click on “Import Container”
- Then select the Google Tag Manager Container Template for WordPress JSON file you downloaded and import it
- Now replace “yourdomain.com” with your website’s domain in the following Triggers: Anchor Link Click, External Link Click and Internal Link Click (you may have to refresh your container to see the newly imported Tags, Triggers and Variables)
- Next replace “affiliatelinkpattern” with whatever URL pattern is consistent for your affiliate links, if your site doesn’t have affiliate links or they don’t use a consistent URL pattern you can skip this step
- Finally replace the “Tracking ID” Variable with your website’s Google Universal Analytics Tracking ID (e.g. UA-61808155-1)
- Save all your changes and Publish your Container
- Login to your WordPress website’s Admin Dashboard and go to Plugins > Add New
- Search for “WP Ajaxify Comments”, click the “Install Now” button for “WP Ajaxify Comments” and then activate the plugin
- Go to Settings > WP Ajaxify Comments
- Check the checkbox next to “Enable plugin”
- Scroll down to the ‘OnAfterUpdateComments’ callback field”, then copy & paste in the following JavaScript code:
- Scroll to the bottom and click the “Save Changes” button
- If you would like to track Contact Form Submissions, simply use the Contact Form 7 WordPress Plugin to power your contact form
- If you use Elegant Theme’s Bloom Email Opt-In WordPress Plugin and want to track new Opt-Ins you’ll need to do the following:
- Download Bloom’s custom.js file from this location: /wp-content/plugins/bloom/js/custom.js and open the file in a text editor
- Search for the following code (on line 405 in version 1.0.3):
- Hit return after this line of code to create an empty line below it, then copy and paste the following code:
- Now save your modified custom.js file and overwrite it via FTP
- If you use Elegant Theme’s Monarch Social Sharing WordPress Plugin and want to track social follows, media shares and social shares you’ll need to do the following:
- Download Monarch’s custom.js file from this location: /wp-content/plugins/monarch/js/custom.js and open the file in a text editor
- Search for the following code (on line 11 in version 1.2.2):
- Hit return after this line of code to create an empty line below it, then copy and paste the following code:
- Search for the following code (on line 35 in version 1.2.2):
- Hit return after this line of code to create an empty line below it, then copy and paste the following code:
- Now save your modified custom.js file and overwrite it via FTP
- Finally clear your cache and purge your CDN if needed, if you followed this guide correctly you should see the following in your Google Analytics > Real-Time > Events Report:
- For slicing and dicing this data further I’ve also created this Google Analytics Advanced Segments Template you can import into your Google Analytics account
Add Google’s Tag Manager Container Code Without a Plugin
If you don’t want to use a plugin to add your Google Tag Manager code to your WordPress website, then you can of course alternatively copy and paste the code snippet right below your opening body tag in your WordPress theme’s header.php file if you know how to do so. Note that if you do this instead you won’t get the WordPress dataLayer variables that DuracellTomi’s Google Tag Manager for WordPress plugin creates

Additional Google Tag Manager Resources
A nice high-level overview of Google Tag Manager on Search Engine Journal.
Google’s official help website for Google Tag Manager.
A very useful Chrome Extension that shows which tags are present and allows you to view events and variables that are available in the dataLayer. It is immensely helpful when you are testing and/or debugging.
Simo is essentially THE Google Tag Manager guru and has written an incredible amount of advanced guides, tips and other helpful resources on Google Tag Manager worth checking out.