Time needed: 15 minutes.
In this article, we can see how to Add Google Tag Manager Code to WordPress Site.
- Creating Account in Google Tag manger
Login to Google Tag Manager and in the home screen click on Create Account Option as shown in the image to create a new account for a website.
- Set up account and container in the create account page
1) Account includes the name and country for account
2) Container includes the name for the container and where to use the container(Web, iOS, Android, AMP). This is basically the property which you want to track.
Click Create after entering all the details. An account will be created and Google will take you to the Google Tag Manager interface.
- Google Tag Manager Code snippets
In the Google Tag Manager workspace, Two snippets will be shown which needs to be added to your WordPress site. Directly
If you already configured the Google Tag Manager with required Tags and Triggers, Please move to Step 9 directly. Else please follow the below steps to configure Tags and Triggers.
- Adding Google Analytics in your Google Tag Manager
Now we will add the Google analytics tracking code to the tag manager which should be fired, when the GTM code is found in the website. Click on the Add new tag option in the workspace as shown below.
- Select Google Analytics – Universal Analytics Option as Shown
- Setting Up the Analytics Tracking in the Tag Manager Itself
- Adding a Variable for the Google Analytics Code which can be reused later inside the Tag Manager
1 shows the name you give for the variable you configure.
2 Shows the Universal ID of the Google Analytics Account which you save in the variable.
3 Click Save to the Variable and again click Save in the Add Tag Window.
- After setting up the Tag, We need to set up the Trigger to fire the tag. In this Example
,we will see how to configure to fire the tag for the Page View
Click Save, and the trigger will be saved.
Now we’re all set in the Google Tag Manager set up to track the Page Views of our site.
- Now we will see how to add the Tag Manager Code Snippet to WordPress Site:
As per the instruction of Google, Tag Manager Code Snippet needs to be added as High as Possible in the <head> of the page.
For Themes other than Genesis Framework:
The first thing you will need to do is install and activate Insert Headers and Footers plugin. Upon activation, you need to visit Settings » Insert Headers and Footers.
Paste your tag manager code in the header section and click on the save button to store your settings.
If you do not wish to install a plugin, then you can also add the Google Tag Manager code in your WordPress theme or Child theme. Simply edit the header.php template and paste the code right after the <body> tag.
For Themes built on Genesis Framework:
If you are using Genesis Framework Theme in your WordPress Site, Then you need to add
header.php file of your Parent Theme. Add as shown below.
- Publish Your Container in Google Tag Manager
Tags in Google tag manager will not go live until you publish the container. Visit Google Tag Manager dashboard and then click on the publish button. Now google Tag Manager is configured in your WordPress Website.
- How To Test If Individual Tags Are Firing
If you want to make sure the individual tags in your container are firing, Google offers a free browser extension for Chrome called Tag Assistant.
This is how you can Add Google Tag Manager Code to WordPress Site