[Solved] How to Install & Troubleshoot Google Tag Manager in WordPress
FIRM FIXED IDEAS
Google Tag Manager
I’ve figured out how to install and troubleshoot Google Tag Manager in WordPress after countless hours of problems, mistakes, and misfires.
“Poor unfortunate souls.” – Ursula
Working at a Marketing Agency means that you will often get tasks and jobs that seem far above you or way beneath you. I had come to assume that installing a UTM Tracker like Google Tag Manager was pretty far underneath my skillset. I even scoffed that anyone could do it – so why should I?
I confess, I was dead wrong. I had multiple sites working in tandem across domains and subdomains seamlessly carrying attribution from one to the next until it arrived in the CRM. Then my analytics stalled and data started coming in erratically.
The answer was, my Google Tag Manager Script wasn’t working. I am here to help you learn how to install this wonderful utility in WordPress, and even to troubleshoot the basics. I will start with the simple steps and work my way into the complex.
First and foremost, installing Google Tag Manager requires you have created an account there with Google, you have a WordPress site running, and you have access to the editor files. I also want to throw this disclaimer out there that installations can vary depending on themes… what works for some won’t for others because some themes and WordPress installations are more custom.
The Google Tag Manager script/code is broken into two parts the header code, and the body code. Within GTM you can view the code by navigating to the appropriate Property (will list the name and the GTM-###### at the top so verify it’s the correct one you want) then going to Admin > Install GTM.
In another tab or window you need to login and navigate to your Admin Dashboard of the WordPress site you want to install GTM on. On the left there is a Paintbrush or Appearance > Editor. Once the editor fires up you should see the theme you are currently using selected in the top right. Click the “Theme Header” or “Header” (header.php) from the right sidebar.
Even if you do not understand PHP or HTML, you can do this without blowing everything up – however, I do recommend that you create a backup before you go further (if you do not know how – learn, I will provide insight on this at a later time sorry). A lot of web designers I’ve worked with have recommended loading up the header in Dreamweaver or other program instead of within the WordPress editor.
Start at the top of the window and start scrolling down with your eyes… you should be able to find the word “head” between two brackets <, >. You can move your cursor after the last bracket and click enter two or three times to make some white space for yourself. Copy the Header text here.
Finally, scroll down till you see the header end usually denoted with a backslash “/” and the word “head” which should be followed by the word body within two brackets, just as the header was. There might also be php code with the words “body_class” here, but you can ignore it.
Make some white space again by clicking on the line below the body tag and making room to paste. Make sure you do not cut off any code and that you are careful to make space without breaking code… you will know if your site blows up and you have to reinstall the backup.
Paste your body code here. Now verify everything looks good and if you are sure, have everything backed up… then click the “Update File” button beneath the window to save.
If your site works, you have the script added to your files/theme, then you are ready to test. The easiest and most simple way to test is to tab over to your Google Tag Manager account. Verify you are logged into the correct property, then using the dropdown in the top right, click “PREVIEW” (Preview and Debug).
The window will reload and an orange colored banner should appear in your Google Tag Manager saying “Now Previewing Workspace.” Great, now tab back to your website and load up your home page/domain where you installed Google Tag Manager.
Once your website it loaded you will know if Google Tag Manager is working there because an overlay will appear at the bottom of the page. You should see the blue icon or the whole window appear with the name at the top “Google Tag Manager.”
Another way to test if pixels are firing is to load up the extensions. There are extensions for several of the pixels, the big ones: Google and Facebook, have their own pixel/testing extensions which can help you verify if things loaded and what was happening on a more granular level.
Here are links to the ones I use:
- Google Tag Assistant (https://get.google.com/tagassistant/)
- Facebook Pixel Helper (https://developers.facebook.com/docs/facebook-pixel/pixel-helper)
Case #1 – The Invalid or Missing Account ID
The solution to the invalid or missing account ID issue is the easiest one I know – you don’t do anything. Google’s a little behind on having added GTM ID’s with additional digits, and if you are new to the GTM scene then you likely have a longer than usual ID number and you will get this error. Do not fret, it’s all okay, and Google has said they will update this in a future fix.
Case #2 – The Theme
What I figured out after losing a few hours to stumbling around the internet looking for solutions to my problem I ended up discovering it was a theme issue. In fact, my Tags were loading, just not reliably and I couldn’t get the Preview overlay to come up. I knew there was an issue and I didn’t want to risk inaccurate data.
I tried updating the theme, it was updated. I tried manually configuring the code in so many ways but couldn’t get it to work. Some of you may use themes like I have where they have a built in area where you can add your tracking codes. These have always worked for me but not this time.
Even when adding the script into the header.php file I was still not able to get my preview overlay to load up. I was seeing that multiple analytics codes were firing and some were not. Oddly the fix for me came with a plugin. I tried everything and eventually tried a 3rd-party plugin.
I searched for a WordPress plugin that could deploy Google Tag Manager, and settled on DuracellTomi’s Google Tag Manager for WordPress. This plugin saved me when everything I was doing did not. The lesson here of course is to monitor your Analytics and watch for errors routinely to make sure your data is solid.
Case #3 – Wrong Property
I mentioned this throughout my installation guide but make sure that you are working within the correct property in Google Tag Manager. It is so easy to be in the wrong account. Check it and make sure before you go poking around.
Case #4 – Tags Not Firing
I cannot go too deeply into specific Google Tag Manager errors but this one comes up a lot so I am keeping it in here. A tag relies on the installation of Google Tag Manager to be correct and stable within the environment of WordPress and the Theme in which it is installed.
If everything is working besides a tag firing then the best place to start is the trigger. If you have recently moved over to HTTPS, that could be an issue. If you have the trigger even slightly off you can pinpoint the issue by CTRL + Clicking on the elements with the preview overlay on, check the log, and see if you had the right trigger. Don’t forget to publish your changes – they take affect only then.
Tags not firing can be so broad and complex that if you are still struggling I recommend having a web developer or coder look it over for you, it’s worth not wasting days of your time.
I hope that you find this guide useful. It is accurate up to today. Let me know in the comments if you have suggestions for me to add or write about in more detail.