Google Tag Manager Tracking Guide for WordPress

This guide shows you how to track:

  • External Link Clicks
  • Internal Link Clicks
  • Affiliate Link Clicks
  • Anchor Link Clicks
  • 404 Errors
  • Comment Form Submissions
  • Contact Form 7 Submissions
  • Subscriber Opt-Ins
  • Social Follows
  • Media Shares
  • Social Shares

How to setup Google Tag Manager Tracking in WordPress

  1. Create Google Account or Login to your existing Google Account
  2. Sign into Google Tag Manager
  3. Create a new Google Tag Manager Account (e.g. Penguin Initiatives)
  4. Google Tag Manager Account Setup Screen
  5. Create a new Google Tag Manager Container for your website (e.g. penguininitiatives.com)
  6. Setup Container Google Tag Manager
  7. Copy your new Google Tag Manager Container’s GTM ID (e.g. GTM-P3XHZF):
  8. Copy New Google Tag Manager Container's GTM ID
  9. Login to your WordPress website’s Admin Dashboard and go to Plugins > Add New
  10. Search for “DuracellTomi”, click the “Install Now” button for “DuracellTomi’s Google Tag Manager for WordPress” and then activate the plugin
  11. Go to Settings > Google Tag Manager
  12. Paste in your Google Tag Manager ID and click the “Save Changes” button
  13. DuracellTomi's Google Tag Manager for WordPress General Settings Screen
    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
  14. Right click and save this Google Tag Manager Container Template for WordPress
  15. In your Google Tag Manager account click on the “Admin” section
  16. Select your new Google Tag Manager Account and Container
  17. Click on “Import Container”
  18. Import Container Google Tag Manager
  19. Then select the Google Tag Manager Container Template for WordPress JSON file you downloaded and import it
  20. 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)
  21. 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
  22. Finally replace the “Tracking ID” Variable with your website’s Google Universal Analytics Tracking ID (e.g. UA-61808155-1)
  23. Save all your changes and Publish your Container
  24. Login to your WordPress website’s Admin Dashboard and go to Plugins > Add New
  25. Search for “WP Ajaxify Comments”, click the “Install Now” button for “WP Ajaxify Comments” and then activate the plugin
  26. Go to Settings > WP Ajaxify Comments
  27. Check the checkbox next to “Enable plugin”
  28. Scroll down to the ‘OnAfterUpdateComments’ callback field”, then copy & paste in the following JavaScript code:
  29. WP Ajaxify Comments newComment dataLayer event callback
  30. Scroll to the bottom and click the “Save Changes” button
  31. If you would like to track Contact Form Submissions, simply use the Contact Form 7 WordPress Plugin to power your contact form
  32. 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:
  33. Download Bloom’s custom.js file from this location: /wp-content/plugins/bloom/js/custom.js and open the file in a text editor
  34. Search for the following code (on line 405 in version 1.0.3):
  35. Hit return after this line of code to create an empty line below it, then copy and paste the following code:
  36. Now save your modified custom.js file and overwrite it via FTP
  37. 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:
  38. Download Monarch’s custom.js file from this location: /wp-content/plugins/monarch/js/custom.js and open the file in a text editor
  39. Search for the following code (on line 11 in version 1.2.2):
  40. Hit return after this line of code to create an empty line below it, then copy and paste the following code:
  41. Search for the following code (on line 35 in version 1.2.2):
  42. Hit return after this line of code to create an empty line below it, then copy and paste the following code:
  43. Now save your modified custom.js file and overwrite it via FTP
  44. 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:
  45. Google Analytics Google Tag Manager for WordPress Real-Time Events
  46. 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

Additional Google Tag Manager Resources

Powered by Blogger.