If you run a number of marketing and analytics scripts on your website, Google Tag Manager can make your life a lot easier. It allows you to manage those multiple pieces of code in one place and easily control when and where those pieces of code execute on your website. It’s powerful, flexible, easy to use, and best of all…free!
In this tutorial, we’ll show you how to add Google Tag Manager to your WordPress website by using one simple and lightweight plugin.
Step 1: Download Head, Footer, and Post Injections
There are a number of script injection plugins available in the WordPress library, but we like to use the Head, Footers, and Post Injections plugin by Stefano Lissa. It allows you to place code in just the right spot when you’re using Google Tag Manager.
Download and activate the plugin on your site.
Step 2: Create a Google Tag Manger Account
Head on over to Google Tag Manager and sign into a Google account or create a new one if needed.
Create a new Account by clicking on the ‘Create Account’ button.

Complete the account creation form and select ‘Web’ as the target platform.

Agree to the Google terms to proceed and you’ll be presented with two seperate pieces of code.

Both of these segments of code will go into the Head, Footer and Post Injections plugin settings on your website. So copy the first piece of code and head back to your website.
Step 3: Add the Google Tag Manager code to your website
Navigate to Settings > Header and Footer

Paste the first piece of code into the <Head> Page Section Injection editor box and the second piece of code into the After the <Body> Tag editor box.

Save your plugin settings and you’re ready to go!
Google Tag Manager is now available on your site, but we haven’t published anything in Google Tag Manager yet. So before we go, we’ll quickly add a Google Analytics tag into Google Tag Manager because that’s the piece of analytics code that most websites will want to have in place straight away.
Step 4: Get your Google Analytics Tracking ID
Head over to your Google Analytics account or create a new one if don’t already have one set up.
Go to Admin > Tracking Info and select Tracking Code from the menu.

Copy the Tracking ID from your Google Analytics account.

Step 5: Create a Tag in Google Tag Manager
Head back to Google Tag Manager, select Overview from the main menu, and click on ‘Add a new tag’.

Name it ‘GoogleAnalytics’ or something similar and click on the ‘Tag Configuration’ section.
Choose the Google Analytics: Universal Analytics tag type.

To start off, we’ll just set the tag up to track page views. Under the ‘Google Analytics Settings’, create a new variable.

Give your variable a name and paste the Tracking ID into the Tracking ID input and save the variable.

Now you’ll need to define a trigger to determine when this particular tag executes on your website. In this case, we’ll want it to execute, or fire on all page views.
Click on the Triggering section within your tag configuration and select All Pages, which should already be available in your account.

Save your Tag and publish your container by submitting your changes and selecting publish.

There you go, you’re all set. You’ve installed Google Tag Manager on your WordPress website and are tracking page views in Google Analytics.
You can now preview your container to ensure your tags are firing as expected and create additional tags across a number of different marketing and analytics platforms to improve your marketing efforts!