Want to add Google Tag Manager to WordPress and simplify your site tracking system? This tutorial will show you how to install Google Tag Manager in WordPress with and without a plugin.
If you want to track the pageviews, conversions, and use other analytics services on your WordPress site, you need to install tracking codes for them. Each of these services usually comes with different tracking keys.
For example, you need to enter different code snippets for Google Analytics, Facebook Pixel, DoubleClick, Google Ads, etc. It’s a hassle to install and manage these codes separately. Google Tag Manager is a great way to save your time and efforts with a unified solution in this regard.
What is Google Tag Manager
Google Tag Manager is a free online tool. It lets you add and manage various tracking tags from a single dashboard.
Once you install Google Tag Manager in your WordPress site, you can add other trackers like Google Analytics, Facebook Pixel, and more from Google’s dashboard. You don’t need to visit your WordPress backend or edit your theme files to insert a tracking code thereafter.
Google Tag Manager vs Google Analytics
Glad that you’ve asked! It’s a common query whether Google Tag Manager and Google Analytics are the same. Well, they’re not. Google Tag Manager just creates a way for the trackers to communicate with your website.
Once you add Google Tag Manager (GTM) to WordPress, this communication path is established. Then, you will need to add the tracking and marketing services (to GTM) that you want. These can be Google Analytics, Facebook Pixel, Google Ads, custom HTML tags, etc.
Get Latest Post Notifications!
So Google Tag Manager and Google Analytics are not the same. When you install Google Analytics (GA) separately on your site, you’ll use GA (only) for that effort.
But if you install Google Tag Manager on WordPress, later you can install many tracking services like GA from the Google Tag Manager dashboard. So using Google Tag Manager is a smarter choice if you consider it for the long run.
How to install Google Tag Manager in WordPress
This is going to be an easy-to-follow process. Let’s see it in this step-by-step tutorial. Here we go!
Step 1: Sign up with Google Tag Manager
Visit the Google Tag Manager website and click the “Start for free” button.
On the next screen, it will ask for some information.
Set a Google Tag Manager account name. Then for the container name, give the specific website domain for which you’re creating your first tag collection. Simply put, a container will contain all the tags for a specific website (or property).
Since we’re talking about WordPress websites, we’ll choose the “Web” option. It will fit for this how to set up Google Tag Manager in WordPress tutorial.
Click the Create button to continue. You’ll see an agreement screen. You need to agree with their terms and conditions to proceed.
On the next screen, 2 code snippets will appear.
We need to insert these codes into our WordPress site where we want to install Google Tag Manager.
Step 2: Add Google Tag Manager Code to WordPress
In the screenshot above, you can see that the first code snippet needs to be entered in the <head> section of the site. And the second one needs to be entered into the <body> section.
We’ll use a WordPress plugin called “Insert Headers and Footers” to add these snippets. (We can also do it without any plugin, but in that case, we would need to edit our theme’s PHP file. If you’re comfortable with editing the codes of your theme, you can do that. We’ll discuss this method later in this tutorial.)
Install and activate the Insert Headers and Footers plugin on your site. Then open it from Dashboard → Settings.
Enter the appropriate code snippets for the <head> and the opening <body> tags. The plugin specifies this for your convenience. Once done, save changes.
Learn More: PostX Review: Best Post Grid WordPress Plugin
By saving these codes, we’ve added or installed Google Tag Manager on WordPress. Now you can visit the GTM dashboard and add your desired tracking services using Google Tag Manager.
Example: Adding a tag via Google Tag Manager
So you’ve installed Google Tag Manager on your WordPress site. As we’ve discussed earlier, no tracking or marketing service will be activated automatically. You need to add these services from the Google Tag Manager (GTM) dashboard. So let’s go to the GTM account dashboard.
From the top left card, click the “Add a new tag” option. On the next screen, you’ll need to choose a Tag configuration. For this example, we’ll add Google Analytics.
Click the Tag configuration option and choose Google Analytics: Universal Analytics.
Now, under Google Analytics Settings, click Select Settings Variable.
Choose New Variable. Enter your Google Analytics tracking ID for the WordPress site where you want to add Google Analytics via GTM.
If you’ve already created a Google Analytics (GA) property for this WordPress site, you can find the tracking ID by following these instructions. Otherwise, you need to create a Google Analytics property for this site. You can follow Google’s guide on how to create a Google Analytics property.
After getting the GA tracking ID, enter it and save changes (see the screenshot above).
Then, click the Triggering option.
Choose All Pages.
The tag will be saved, but it will NOT go live immediately. We need to publish it.
Publishing a Tag in Google Tag Manager
Sign in to your GTM account. You’ll see all of your Containers. Click the container you want to open.
Hit the Tags menu to view all of your tags.
Click the Submit button on the top right corner. On the next screen, it will show some options.
You can explore these options to save the GTM container code versions (without publishing) or simply create a version and publish the tag(s).
After publishing the tag(s), you’ll see a success message.
How to Add Google Tag Manager to WordPress Without Plugin
As we’ve mentioned earlier, you’ll have to edit your WordPress theme’s header.php file to do this. This might not be the same for all themes. If you use a child theme, the header.php of the child theme should be edited.
As an admin, you can access the theme file editor from your WordPress Dashboard. Go to Dashboard → Appearance → Theme Editor. You’ll see the theme files there. Open header.php and enter the code snippets under the <head> tag and <body> tag respectively. Then save changes.
Since this method also depends on the theme you’re using, so it would be best if you ask for some support from your theme developer. Sometimes the theme may come with options to insert header and body scripts from the theme’s settings panel.
We hope this tutorial was helpful to you. Have you added Google Tag Manager to your WordPress site? How was your experience? Please let us know in the comments!
Disclaimer: This post may contain affiliate links and we may receive a small commission if you purchase something by following them. However, we recommend services/products that we believe good to serve your purpose.