WPCode Logo

WPCode Blog

Everything you need to know about the WPCode plugin

How To Add Google Tag Manager To WordPress

How To Add Google Tag Manager To WordPress 

If you ever felt overwhelmed by the number of code snippets required to monitor user behaviors, you would benefit from learning how to add Google Tag Manager to WordPress. 

Tracking conversions, analyzing page views, or understanding user engagement traditionally requires separate code snippets to be inserted directly into your website’s code base. 

This not only clutters your website’s backend but also poses a significant challenge in terms of management and updates. 

Google Tag Manager provides a solution to these problems and makes your life as a website owner much easier.

What Exactly Is Google Tag Manager?

Google Tag Manager (GTM) is a free interface from Google that lets you add, update, and manage code snippets called tags on your website. 

Integrating GTM with your WordPress site can dramatically enhance how you track and understand user behavior. 

It saves time by keeping you away from making direct edits to website code and centralizes tag management.

It ensures that all of the different tags load cohesively, minimizing the impact on your site’s loading speed.

With GTM, you gain the ability to track various user interactions on your site through a simple, code-free setup process.

This process is straightforward and does not require extensive coding knowledge. So let’s get started! 

How To Add Google Tag Manager To WordPress Using WPCode

You need to do a few things to install and set up Google Tag Manager (GTM) in WordPress properly. So let’s do them step by step.  

Step 1: Setting Up Google Tag Manager 

Sign in to Google Tag Manager (sign up if you don’t have an account already). Once you’re in, click “Create Account” from the “Accounts” tab. 

creating google tag manager account

Please enter a name for your account (which can be your business name) and select the country of your market from the dropdown. 

How To Add Google Tag Manager To WordPress: name your account in GTM

Additionally, you need to create a container. It’s the rules that govern all the tags in this basket. Since you’re adding GTM to your WordPress website, choose “Web” from the list. For your container name, you can put your website URL here.

How To Add Google Tag Manager To WordPress: create a container in GTM

You’ll see the Terms of Service from Google; select the checkbox at the bottom to accept and click “Yes” to complete your account. 

Click “create” to finish creating the GTM account 

Step 2: Getting Your Google Tag Manager Credentials 

You are supposed to see a modal pop-up with your credentials immediately after you accept the terms of service. It should look like the following: 

GTM credentials modal popup 

Don’t worry if you didn’t see it. From Tag Manager, navigate to the “Workspace” tab. You’ll notice your container ID formatted as “GTM-XXXXXX”; clicking on it will show your GTM credentials in a pop-up. 

clicking on the container ID to get GTM credentials 

Keep the pop-up modal open; we’ll circle back here in a few moments. 

Step 3: Adding The Code To Your WordPress Website

Google Tag Manager requires you to add scripts in the header and body parts of the website. There is a way to achieve that without having to touch the code base of your website.

The free version of WPCode lets you add scripts in the header, body, and footer sections of your website. Therefore, it’s perfect for adding GTM scripts to your website. Using WPCode, you can also add this script as a code snippet for more control.  

You can install and activate WPCode like any other plugin in WordPress

Once WPCode is activated successfully, you’ll see a new menu item labeled “Code Snippets” in your WordPress admin bar. 

Step 4: Adding Google Tag Manager (GTM) To WordPress

From the backend Dashboard of your website, visit Code Snippets > Header & Footer. You’ll see the following page. 

How To Add Google Tag Manager To WordPress: Go to header and footer in WPCode

Now, return to the previous tab of your browser where Google Tag Manager is open, and copy the #1 code titled <head>. Come back to the browser tab where your website is open, and paste the code in the box titled Header. 

paste script in the header

Then, copy the #2 code titled <body> and paste it into the box titled Body. 

Complete adding GTM in WordPress

Click “Save Changes” when you’re done. This will add Google Tag Manager to your WordPress site. 

How To Create Tags In Google Tag Manager

The whole purpose of adding Google Tag Manager to your WordPress site is to use tags to get insights into your website. For that, you need to create a new tag in Google Tag Manager. We’ll use Google Analytics as an example. 

Click “Add New Tag” and you’ll see the following screen. 

Give your tag a name, then click on “Tag Configuration.” This will show you the list of tags to choose from. 

Configuring tag in GTM  

You can pick any, but as promised, let’s select “Google Analytics” for the purpose of this tutorial. 

Choose Google Analytics from the dropdown

This will again show you different options available for Google Analytics; pick “Google Analytics: GA4 Event” from the list. 

Choose GA4 from the dropdown

Now, you need to add the Measurement ID and the Event Name to proceed. 

Add measurement to create a tag 

To find your Measurement ID, open a new tab on your browser once again and log in to your Google Analytics account. 

Navigate to “Admin”; under “Data collection and modification,” you’ll find “Data streams”. Click on it and select the Web tab. Click the web data stream. You’ll find the measurement ID in the first row of the stream details.

getting measurement ID from Google Analytics

Copy the ID and return to the Google Tag Manager tab. Paste it in the “Measurement ID” field. Once you paste that, you’ll see a notice saying, “No Google tag found in this container.”, that’s because we need to create a Google Tag for this tag to work. 

Paste Measurement ID from Google Analytics 

Click “Create tag” and follow the instructions. You’ll end up creating a new Google Tag. Once that’s done, you’ll see the following check mark indicating everything is good to go. Also, give the event a memorable name. 

completing Tag configuration. 

Now, you need to define when or how the event will be triggered. For that, click on Triggering. 

setting Trigger for tags

You’ll see all triggering options on a new screen; choose “Initialisation – All Page”. 

Choose a trigger for the tag

Finally, click on “Save” to store all the settings. 

Saving the tag

You can publish the tag by clicking the ‘Submit’ button on the top right. 

Submitting tags

Congratulations!

Now you know how to add Google Tag Manager to WordPress. GTM is an incredible tool to have at your disposal. It works as a manager of various kinds of code snippets that help you get critical information about your website. 

Add A Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.


Get WPCode

Popular Resources

Get free tips and resources right in your inbox, along with 500+ others

Follow Us

Get Started Today & Add Your Own Snippets

Future-proof your website with WPCode Snippets and improve the way you manage code across all your websites.