Google Tag Manager For WordPress – Complete Setup Guide

It is quite confusing to choose the proper method to install google tag manager on wordpress.

There are many plugins which are available free but some of them DO NOT follow google’s best practises.

We’ll be looking at 2 methods to setup tag manager in wordpress.

  1. Manually deploy in header.php
  2. Using Plugins


So let us start with 1st method:

1.) Tag Manager Setup - Manual Deploy in header.php

Step 1:

Google Tag Manager Code - Digishuffle
Google Tag Manager - Admin

Step 2:

You will see 2 codes.
Header Code:

  • It will trigger in javascript enabled browsers.
  • As per the best practice the code should be placed high up in the <head> section

Body Code:

  • It will trigger in javascript disabled browsers.
  • As per the best practice the code should be placed immediately after the opening <body> tag.
  • Copy these codes & open you wordpress admin in new tab.
GTM Header & Body Code
Google Tag Manager Code

Step 3:

  • Login To Your WordPress Admin
  • Go To Appearance > Editor
  • Verify the theme on the top right corner dropdown.
  • On Right Side, Search & Click on header.php file.

 

WordPress Theme - header.php file

Step 4:

  • Copy the header code & paste it immediately after thetag 
  • Then copy the body code & paste it immediately aftertag.
  • Click on Update File.
  • Click on Gif below to enlarge.
Wordpress-TagManager - Setup
WordPress Header.php - Code Placement

Step 5:

  • Open your website in new tab
  • Install the Tag Assistant Plugin
  • Click on plugin icon > Enable
  • Refresh the Page
  • You should see Tag Manager install success.
Tag Assistant Verification in WordPress

Summary

  • The Setup is quite easy & codes are placed as per google’s best practises.
  • If you are using child theme, make sure to edit the child theme files & not parent theme’s.
  • WP Updates might require to place the code again. 
  • Don’t change other code in the file. You just have to copy paste the tag manager code. You can use CTRL+Z to undo any other changes.

2.) Tag Manager Seutp - Deploy via Plugin

Step 1:

Duracell Tomi's - Google Tag Manager
Duracell Tomi's Tag Manager Plugin

Step 2:

  • Go To Settings > Google Tag Manager.
  • In General Tab, Enter your Google Tag Manager ID. (GTM-XXXXXX)
  • Select Container Code Placement >  Custom.
  • Copy the code php below (check image)
Google Tag Manager Plugin
Duracell Tomi's Tag Manager Plugin

Step 3:

  • Go To Appearance > Editor.
  • Paste the copied code just below the body tag.
  • Click Update.
Duracell Tomi's Tag Manager Plugin

Step 4:

  • Verify the placement using tag assistant plugin as in Step 5 (GTM manual placement)

Summary

  • Manual code placement is needed in both the methods.
  • In plugin, you can do much more as populating the dataLayer with post type, author, date, etc.
  • You can also track scroll events, form fills,etc.
  • Sometimes plugins might not be compatible with your theme & not track the required data.
  • You will not have to place the code again after any WP updates.

Ritwik is Web Analyst & Growth Hacking Consultant. He loves to write technical & easy to understand blogs for Marketers & Entrepreneurs. Focused on Google Analytics, Tag Management, GScripts & more. Google Certified Professional. A Firm Believer in Teaching -> Learning -> Growing. :)

One comment

  1. teşekkür ederiz,
    faydalı ve güzel paylaşım seo açısından hangi etiket türünü seçmeliyiz ? optimize mi sağlıklı olur bilgi verebilir misiniz ? teşekkür ederim

Leave a Reply

Your email address will not be published. Required fields are marked *