!!! UPDATED 2016-09-28 !!! – New screenshots and adaptions to newest version of GTM –
One of the most important things on any site is to have some kind of web analytics tools setup so that you can track what is happening on your site. While there are many web analytics platforms out there my sole focus is on Google Analytics.
This guide is for those who want an easy way of installing Google Analytics through Google Tag Manager.
What you need in order to make this work:
- A Google Account (free)
- A self hosted WordPress installation (not residing on wordpress.com)
- A cup of coffee
Setup a Google Analytics Account
The first thing that needs to be done is to setup a new account in Google Analytics for your site if you haven’t already. This is done in just a few minutes, but we’re going to tweak this a bit later on so keep on reading.
Head over to the Google Analytics site and login (or create a free Google Account if you haven’t already).
Once logged in all you need to do is click on Admin in the top menu followed by opening the Account Menu and click “Create new account” at the end. When doing this you are instructing Google Analytics that you want to create a brand new account for a new site.
Next steps is also very straight forward. There are 3 required field to fill in and just make sure to fill them out according to your needs. For just a small site with only one web property this works out just fine.
Just make sure that you enter your site with or without the preceding www. in front under Website URL if you are using that. Something I’m not using on this site. That is all up to personal preference.
Below this there are some optional tick boxes regarding what you want to share with Google. It is completely safe to leave all four boxed checked. But then again, feel free to opt out of any given one.
Just click Get Tracking ID at the bottom and accept the Google Analytics Terms of Service and you’re good to go.
You’ve got your unique Google Analytics Tracking ID, yay! Now, let’s start working on collecting that precious data of yours.
Note: The data above is for Universal Analytics, which is the kind of tracking variant you’d want if you’re installing something from scratch today. You can easily adapt the rest of this guide if you are using the traditional ga.js tracking code since before.
[pexcirclecta pex_attr_small_title=”You might also like” pex_attr_title=”Top 5 debugging tools for GA and GTM” pex_attr_button_text=”Read more!” pex_attr_button_link=”https://dcarlbom.com/google-tag-manager/top-5-debugging-tools-for-google-analytics-and-gtm/” pex_attr_button_link_open=”same” pex_attr_button_color=”119c28″][/pexcirclecta]
Hello Google Tag Manager
Up until Google Tag Manager arrived, webmasters had to implement the tracking code(s) on every page through out the CMS (like WordPress) and make sure that it showed the right tracking code on the right page at the right time.
All that changed with Google Tag Manager. Now we’ve got a new interface where we basically just install an empty script (container) on all pages on the site and then manage all scripts from within GTM asynchronously.
That. Is. Amazing.
In order to get this to work, just point your browser to the site for Google Tag Manager. Log in via your Google Account if you haven’t already and let’s get this data collection going.
Start by creating an account by clicking on CREATE ACCOUNT. An account in Google Tag Manager is a place where you can store everything related to a company, even if they have many sites. If you only have a few personal sites (webpages) you can name this basically anything. Like My Sites or something.
I choose to name my account after the domain I’m going to track. Make sure to give this a unique name so that it’s easy identifiable when your account list grows.
When it comes to ticking the box to Share data anonymously with Google or not is once again a personal preference. I believe that if you don’t have that big international corporation you’re working for, demanding that you own all your data (in which case the free version of Google Analytics wouldn’t suffice) just go with your gut feeling. I tend to keep it selected. But it’s all up to you really.
Next part is where we put in the actual site information.
For the Container Name part, make sure to name it after the site you are going to use it on. This makes it much easier finding what you are looking for when you have multiple accounts and containers.
Then select if your GTM container is to be used on either the “Web” (classic webpages, this is probably what you’re going for), iOS apps or Android apps.
Hit Create when done and bask in glory after creating your first Google Tag Manager container.
Yay, you’re getting good at this now!
On the following page you will be presented with the unique GTM ID for your container as well as code needed to implement the container on your site. But we are not there quite yet… so keep that code available for just a few more minutes.
Note: Your GTM ID will differ from mine. Make sure to use your own ID or you will not see any data further on.
Connect your Google Tag Manager Container with a Google Analytics Property
At this point we have one container in GTM and a Property in Google Analytics and it’s time connect the two. Don’t fret, it’s the easiest thing to do.
When you’re looking at your Container it’s rather empty before you start populate it with some data. Start by clicking on Tags -> New.
This will give you the option to create a brand new tag inside Google Tag Manager that we are going to use to send data to Google Analytics with.
Click anywhere inside the box that says Tag Configuration and let’s get started.
The first thing you have to select is what template you are going to use. In other words; where are you going to send your data? Since we’re about to send the data to Google Analytics using Universal Analytics, that’s the option we’re going for here.
When you have selected the Tag template, give the tag a name. You can use whatever naming convention you’d like here but my recommendation is to keep it consistent for your own sake in the future.
Since beginning of time (well, GTM-wise at least) I’ve given my standard pageview tags the following name: UA – Pageview
That shows me that the tag is connected to UA (Universal Analytics) and that I’m sending pageview data.
Next step is to check back into Google Analytics and the property you created just before. Just copy the UA-XXXXXXX-Y and insert it into the Tracking ID field in GTM.
Once again, use your own unique identifier here, not mine. Your data will not show otherwise.
Leave Track Type to its default; Pageview.
Next, we need to tell Google Tag Manager when and where to fire this tag. Hence, click the Triggering section just below.
You’ll se one default Trigger in this list named All Pages. Select this one and you’re done. You’ve just told Google Tag Manager to trigger this tag on every page where the GTM Container (snippet code) is present, which is going to be on every page on your site. Which leads us to…
Installing Google Tag Manager on WordPress
There are two ways of doing this and both are relatively straight forward and easy to implement.
Either we go with a WordPress Plugin or we insert the code in the template ourselves. Now what are the pros and cons of either of them?
Install Google Tag Manager via WordPress Plugin
- + Easy to implement.
- + Doesn’t change when updating theme.
- + Gives additional custom functionality from plugin author.
- – Dependent on third party for it to work.
What WordPress Plugin would I recommend for Google Tag Manager?
I’d go with DuracellTomi’s version since it works like a charm out of the box.
All you need to do is to install the Plugin from within the admin section of your WordPress site and then just insert your unique GTM ID that you created a few moments ago. If the Plugin doesn’t highlight exactly where to go, this is what you are looking for:
http://yourdomain.com/wp-admin/options-general.php?page=gtm4wp-settings
The next part is where it could get a bit tricky. Google recommends that you insert the GTM Container just after the opening <head> tag in the WordPress Theme Template.
The good part here is that the plugin nowadays actually tries to implement the code through a codeless injection which usually works as a charm. Try this option first and make sure that your frontend (your actual page in the browser) turns into a mess.
If this for any reason doesn’t work, select the Custom option and to below changes to your template instead.
Select Custom in the options, copy the code below and then navigate to Appearance -> Editor.
<?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?>
Don’t panic!
Somewhere on the right side under Templates you should find a file named header.php – that’s what you’re looking for. There is a chance that this file doesn’t exist in your template, in that case try looking for a file called main.php och perhaps index.php in that case.
<!DOCTYPE html> <html <?php language_attributes() ?>> <head> <!-- THIS IS WHERE CUSTOM CODE SHOULD GO --> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title><?php wp_title(pexeto_option('seo_separator'), true, 'right'); ?></title> <?php //print the Facebook and Google+ meta tags to include the featured image //of the post/page when it is shared global $post;
Inside your header.php, find the opening <head> tag and insert your code just below that line of code.
NOTE: Your code will differ from mine, unless you are using the exact same theme and template as I am. What’s important is that you place the code just after the opening <head> tag.
Just save that and just like magic, you’ve now inserted the GTM Container on your WordPress site by using a WordPress Plugin.
Install Google Tag Manager without a plugin
If you’ve read the part about installing GTM with the WordPress plugin you already know what to do, but let’s have a look at the ups and downsides of this.
- + Complete control over the implementation.
- + Not dependent on any third party code/plugin.
- – Still needs to be reinserted when changing or updating core template files.
The only thing that really differs is what kind of code you need to insert just after the opening <body tag in your header.php file.
Looking at the Admin -> Install GTM in Google Tag Manager you will see the exact snippet of code that needs to be implemented on your site.
The following code should be placed as high up as possible in the <head> of every page possible.
<!-- Google Tag Manager --> <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXXXX');</script> <!-- End Google Tag Manager -->
And the additional code that need to be added right after the opening <body> tag is as follows.
<!-- Google Tag Manager (noscript) --> <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->
Google has as of September 2016 changed its recommendations as of where the Google Tag Manager tracking code should be placed. This means that part of your GTM tracking code should now be placed as close to the opening <head> tag as possible.
Publish your GTM Container
The last step in order to get data collection going is to publish the GTM Container you’ve setup in this guide. One of many strengths with Google Tag Manager is the possibility to keep every update separated in versions so that you always have the possibility to go back if something stops working after you’ve done an update.
Let’s publish that Container!
Since this is your first version you’re creating, all you really need to do is press Publish in the top right corner. Give the container a descriptive name and just hit Publish one last time an you’re all set!
BAM! You’re live.
Congratulations. You have now successfully installed Google Tag Manager together with Universal Analytics on a WordPress site.
[Updated] In this article I will guide you through on how to make sure that we filter out the data we don’t want into Google Analytics by working with some dataLayers in GTM.
Hi Daniel.
Just a question about the section under the heading “Install Google Tag Manager without a plugin”.
I don’t understand why I would be installing the Google Analytics code here, rather than the Google Tag Manager code?
With respect, have you made a mistake, or am I missing something? If it is the latter, can you please explain how this works, especially for later using GTM for other (non-Google) tags?
Thanks!
Hi Stephen,
You are so correct in this, and I can’t actually understand how that slipped through my audits. I will update this accordingly, because what’s shown is the Univeral Analytics snippet for some unexplained (lack of coffee?) reason.
Thank you!
Hi Daniel!
First of all, great guide!
I have done everything described above, but the events does not fire (e.g. scrolling, outbound links etc). I’ve double and triple-checked the set up, but I cannot seem to find the reason why they not fire.
The analytics ID is fired, nothing else.
I check the “Real-Time” tool i analytics and the only thing it tracks is pages, not events..
Best Regards,
Gaute
Hi Daniel,
Thanks for such a complete guide. Just installed everything on a clean WP.
Waiting for more on custom tracking options that are available in DuracellTomi’s plugin ;)
— Stas
Hi,
Thanks for the guide, but a little stuck.
I have followed this guide to the letter and used the plugin and edited my header.php with .
Where do I put the Google analytics code below?
(function(i,s,o,g,r,a,m){i[‘GoogleAnalyticsObject’]=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,’script’,’//www.google-analytics.com/analytics.js’,’ga’);
ga(‘create’, ‘UA-57034428-1’, ‘auto’);
ga(‘send’, ‘pageview’);
Thanks,
Chris.
Hey Chris,
You do have the GTM code properly placed right after your opening body tag on your site, but the code in question above here is your Tracking Code for Universal Analytics.
This code will not be needed on the page, but should be taken care of by Google Tag Manager in a Tag that fires on every page instead.
You do have that setup in GTM already, right?
Hi Daniel,
Thanks for sharing this info. Really helpful!
One thing i wanted to clarify. I have developed my website in WP4.0 and for GA tracking through GTM I have included the container code in header.php but the container code in in JavaScript and not in PHP. So don’t you think the JS code will make impact on the page-load performance?
Why am asking this because I can see in firebug (add-on to firefox browser), the request that is being fired to google-analytics server does not show the end time. It keeps on making the request and does not show the completion time of making the request. It completes the request when we navigate to other page. Hope you got the point here?
Thanks in Advance!
Cheers
Amardeep
Hi Amardeep,
I get your point. Looking at GTM docs where it states that “…so when it executes, it does not block other elements from rendering on the page.”, we see that its being fired asynchronously. (https://support.google.com/tagmanager/answer/2772432?hl=en)
The reason it keeps listening on your page could be as simple as you having a Click Listener active, perhaps?
Regards,
Daniel
Hi Daniel,
Had the same question. So just to be clear. If I set up GTM, paste in the single line GTM code under ‘body’ in header etc., and get the GA tracking code as per your instructions in the above, this means I then do not need to paste in the long GA tracking code on every page, right? And if this is right, then where do I view tracking data? Do I log in to Analytics or to GTM?
Thanks again!
Hey CF,
That’s correct. And you’d look at the data in Google Analytics. GTM’s part is to take care of sending the data from your site to Google Analytics.
Best of luck.
thank you very much,
I followed your tutorial and it works very well now.
A great, great help. Thanks!
Thank you!
Thank you so much for the walk through. so much of it was new to me and you didnt take anything for granted.
Thank you for your appreciation Patrick.
what happens if a certain page does not load the header so the tag will not appear?
the page template of this page does not contain .
Hi Steve,
If the template for some odd reason wouldn’t load the tag it will not fire and nothing will be sent to Google Tag Manager.
tag opens it *should* really be available on all pages, otherwise I’d say there’s bigger problems at hand.But since it’s loaded just after the
I hope that answers your question, otherwise just give me another shout.
/Daniel
Thanks for the great instruction. I just have a small question regarding to link the GTM with the Google Analytics properties. What if the current website is using Classic Analytics then what should we do in this case? Do we still use the Universal Analytics tracking ID right away or we have to upgrade from Classic to Universal Analytics before using the tracking ID? Thanks a lot!
Hi Steve,
Thanks for all this information! My tag shows as “blocked by: all pages.” When I open the tag it says “this tag will not fire because it has no firing rules.” Assuming this is bad and I need to unblock the tag, can you tell me how to do this please?
Thanks!
Lynda
Hi Steve – I added a firing rule and fixed it. Thanks anyway!
Daniel,
Thank you for writing this up.
I have been trying to figure out a way to insert GTM into WordPress and not have to worry about it changing with updates.
I notice that you say using a plugin such as DuracellTomi’s “+ Doesn’t change when updating theme” for the plugin installation. But if you insert the code into the themes header.php won’t this potentially change with an update?
Wouldn’t I have to insert it into a child theme’s header.php to prevent it from changing? I tried inserting the DuracellTomi snippet into a child theme header.php but received a non-standard implementation error when I viewed the tags.
Thank you in advance for any help.
Best,
Joe
Daniel,
My apologies. After reading a post by DuracellTomi on WP about non-standard implementation errors I saw that this happens often. I refreshed the page and did the check again and the NSI error disappeared.
Best,
Joe
I’m sure I’m just an idiot but when I use the plugin or manually place GTM code I get added characters after my GTM ID so http://www.googletagmanager.com/ns.html?id=GTM-XXXXX&189db0” any idea what’s causing that?
Hey Chris,
This still an issue or did you resolve it? In that case, on what site are you using it on?
BR Daniel
Excellent Guide.. I have been doing with out the Pluging of Google Tag Manager.. I will use it, it is a faster way.
Thank You
This is a good getting started guide.
If you want to track all of the following events on a WordPress website with Google Tag Manager:
External Link Clicks
Internal Link Clicks
Affiliate Link Clicks
Anchor Link Clicks
404 Errors
Comment Form Submissions
Contact Form 7 Submissions
Subscriber Opt-Ins
Social Follows
Media Shares
Social Shares
Check this out: http://penguininitiatives.com/google-tag-manager-tracking-guide-wordpress/ =P
hi , thanks for your help. I used “Install Google Tag Manager without a plugin” , and I added my code right after “” ,
what should I do?
here it is ;
<body
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({‘gtm.start’:
new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!=’dataLayer’?’&l=’+l:”;j.async=true;j.src=
‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,’script’,’dataLayer’,’GTM-W67HDD’);
>
Thank you for your time .
Hey Artmis,
You got it wrapped inside a script tag?
If that’s not the case, just drop me an email with a link to your site or post it here and I’ll have a look.
/Daniel
Is there any way to install this using the Child Theme? Under Functions.php it shows:
I don’t see
Hi Pamela,
I do believe that the easiest way of adding this to a child theme is to copy the parent theme’s header.php into the child theme folder and do the changes in that file. If I’m not all mistaken, that’s the ‘right way’ of doing it the WordPress way.
BR Daniel
Also Non Standard Implementation (NSI) errors as viewd in Tag Assistant. I wouldnt mind BUT it is causing Adword to think that the Advertising features part of the Google Analytics tag isn’t working… hence Audiences not working > can’t get remarketing operational.
Not playing out until line 136
Do be careful if you have a CDN in the way.
Thanks for your clear instructions. They were very easy to follow and I now have my Google Tag Manager on my website. I used the code snippet plug in as I am not familiar with how to modify my theme and it worked great! I will certainly use your site and expertise again.
Much appreciated !! Yvonne
Sigh. I don’t have a header.php file. And anything that I can find with header in the title (in de WP core files of in the theme) doesn’t have a tag to paste the container code under. Why does everybody get these things except me?
Any idea’s?
regards,
Colette
Hey Colette,
It could be that you’re using a child theme and therefor the header.php might not be present in the child theme per default.
Perhaps you file is named index.php and that’s where you have your opening body tag?
BR Daniel
Why do I need a plugin (DuracellTomi’s) ?
If I can not insert a theme in the settings (Appearance -> Editor – header.php) ?
If I can insert сode Google Tag Manager (header.php).
Hi Vadim,
You don’t need any plugins at all. This guide will show you how to implement it with and without any plugins.
Still, using a plugin can simplify things, whereas not using a plugin will give you a much better control over the implementation yourself.
BR Daniel
I’m trying to use the plugin, but can’t locate the header.php file. This is with the Genesis eleven40 Pro Theme which is a child theme. Screen shot: http://goo.gl/yjtrcE
The “Genesis” theme has one, but includes a warning message not to edit it under any circumstances.
Hi Tapiwa,
In general when it comes to child themes in WordPress, you usually just have to copy the original header.php into the child theme folder and make the changes to it there. It will then override the parent theme’s header.php
But, in your case, since you’re using Genesis I would recommend going into:
Genesis -> Theme Settings -> Header och Footer scripts. Just add the code snippet in the first textarea and it will be appended to wp_head()
Good luck.
Thanks for this tutorial. It really helped out!
You’re welcome Nicloas!
hi daniel,
i’m new to wordpress and gtm , and i decide to install google tag manager without plugin , and you wrote just install it at header.php
and here’s my question :
isn’t it suppose to install gtm sniplet at every pages ? (well i think that’s work for common website not wordpress perhaps ? )
thank you so much, hope you’ll reply it sooner than i expected
thanks, Hady
hi daniel , it’s me again lol , so i tried to install without tags
i inserted gtm java sniplet right after the opening of <body tag like this :
<body
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({‘gtm.start’:
new Date().getTime(),event:’gtm.js’});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!=’dataLayer’?’&l=’+l:”;j.async=true;j.src=
‘//www.googletagmanager.com/gtm.js?id=’+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,’script’,’dataLayer’,’GTM-P2SLM8′);
>
<header id="masthead" class="site-header" role="banner" >
and when i updated it , when i opened my website , there’s an error code :
class=”home page page-id-366 page-template page-template-template-homepage page-template-template-homepage-php logged-in admin-bar no-customize-support custom-background left-sidebar woocommerce-active has-site-logo”>
but when i delete the gtm sniplets, everythings went fine, i wish you can give me you’re personal email, so you can help me further ,thank you
hi daniel,
so i moved the GTM snip right after
<body
>
is it wrong ? since google recommend it to place gtm sniplet right after the opening of body (
anyway, i’m tryin to use data layer , and shouldn’t i placed it to every pages ?(i only placed it on header.php atm) but my issue is , i couldn’t find my product.php :( perhaps you could check it for me ? it would be pleasure then
regards, hady
Hi Hady,
Sorry for the late reply, I’m on vacation and the wifi down here isn’t all the best.
, and not inside the body tag (before the end bracket).If you’re running WordPress you have already found the correct file, being header.php or similar where the body tag is present.
You should insert the GTM snippet right after the opening tag, including the end bracket;
I hope this helps you, otherwise, just give me a holler.
/Daniel
Thanks! Helped a ton.
Very useful information about google tag manger… this information really improve our page rank…
Hi,
Great post. I was having issue with pageviews not being visible in Google Analytics and hosting service guy suggested that I should use Google Tag Manager for the same. I followed all your steps and later checked presence of Google Tag Manager on every page of my website using some online tool. My question to you is how much time it takes before I can check analytics in Google Analytics once Google Tag Manager is installed?
PS: I have used pluggin method.
Hi Gaurav,
It should only take a few hours for data to show up in the reports nowadays in GA. And you should be able to see it instantly in the Real-Time Reports.
Daniel
thanks for informations. already implement codes to my website http://www.handpickedx.com
Brilliant! Thanks so much Daniel, works like a charm :)
Daniel, thanks a lot for this post, really helpful for a newb like me. Along with your post on Contact Form 7l I’m nearly there.
I’m fairly new to WordPress and was wondering… under my themes settings I originally entered the GA tracking code. Now that I’ve implemented the GTM method, should I remove the GA code from my theme settings. Would I start to get duplicate data showing up in analytics?
Also, is there a way, other than using a child theme (that’s a whole new thing for me to learn), to make sure the header.php tweak doesn’t disappear when updating my theme.
Your posts ended yesterday on a positive note after much frustration. Thank you!
Hi Richard have you found an answer to your question?
Whether we should remove the GA code or not when installing GTM.
I used both type of GTM installation with and without a plugin, as you suggested, but in my case second type of GTM implementation had worked without any plugin.
in first type GTM implementation with your suggested plugin, it doesn’t work. it shows many errors but with second type it works GREAT
Thanks for your GREAT SUPPORT.
You can see my website too
Can I know which theme and template you are using for the implementation given above?
I am relatively new to analytics and havent coded in ages. Let me know which theme you use here so I will use the same theme on my experiments’ website for learning GA – GTM. That way I can make implementations in the same way with the same code mentioned here.
Thanks
Swetha
Hey, thanks for the guide.
But I think you also need to reinsert the custom-code also when updating the theme, no?
Do you think it could be a good idea to copy the header.php into the child-theme and insert the container right there?
So the container wouldn’t be removed when updating the whole theme.
Regards,
Hi Jan,
You’re right. If you’re updating the core theme you’ll have to reinsert the code. Unless you opt to use the Plugin.
Going with a child theme is a suitable solution, but then you have to make sure to update the header.php if the core file has been updated as well.
BR Daniel
Spot on with this write-up, I absolutely believe this website needs much more attention. I’ll probably be returning to read more, thanks for
the information!
Awesome tutorial, thanks!
I usually do not drop a comment, but after reading
a great deal of remarks on this page Google Tag Manager on WordPress – Complete Install Guide.
I actually do have a couple of questions for you if it’s okay.
Is it only me or do a few of these comments come across like they are written by brain dead individuals?
:-P And, if you are writing at additional online social sites, I would like to
follow you. Would you post a list of all of all your social community
pages like your linkedin profile, Facebook page or twitter feed?
I have been searching the internet for days trying to get some clarity about a simple
step in GTM install. After reading your excellent article then all the comments
then finally I found a comment in this blog on this page by (Richard Hamilton September 24, 2015) asking the same question I desperately need answered.
We have the Google Analytics code snippet inserted in evcery page on our site.
We have not bothered to insert any additional tracking codes in the site to show important data in GA. But times are changing.
Now we wish to install Google Tag Manager code snippet and create lots of useful tags and triggers in our container.
Here is the question:
Should we remove the GA code or is that still required to assist GTM?
This question has already been asked on this blog.
But no answer has been given yet.
In all the Google documentation we have read there is no mention
about whether we should remove the GA code or not. Our case is simple.
We do not have any hard coded tracking to transfer. I am guessing that in our case when using
the Google Tag Manager code the old GA code would no longer be required and we should remove it. Is that right?
This blog might just be the first to answer this question.
Awesome post. I’ve been diving deep on GA and tags. Mike King (@ipullrank) has a great resource here on Google Tag Manager = http://ipullrank.com/google-tag-manager/ . Also worth checking out… it’s pretty epic.
Cheers.
Hey Jason,
Yeah, Mike’s post is pretty awesome too. Happy to see that GTM get the traction it deserves :)
Best,
Daniel
Hey there,
I’m trying to add the tag into my header.php
Below is the only section in my header.php file that contains ‘body’. Would you have any clue where to put the code? I’ve tried but just keeps breaking my site unfortunately!
Cheers
<body data-footer-reveal=”” data-footer-reveal-shadow=”” data-button-style=”” data-header-inherit-rc=”” data-header-search=”” data-animated-anchors=”” data-ajax-transitions=”” data-full-width-header=”” data-slide-out-widget-area=”” data-loading-animation=”” data-bg-header=”” data-ext-responsive=”” data-header-resize=”” data-header-color=”” data-smooth-scrolling=”” data-permanent-transparent=”” data-responsive=”” >
Hi Andrew,
I would put the script on the next row, since that entire row is your body-tag. So don’t insert it anywhere inside that piece of code.
Regards,
Daniel
Hey Daniel,
Yea I’ve tried that and it breaks the site when I put it on the next line down :(
I’m trying to get the theme developers to help me!
Cheers
Hi Daniel,
Great guide, I found it too late unfortunately and have spent the last few days working to your plugin process myself, it was rewarding though.
My tags are working fine to my knowledge but when I go to my site in preview mode to use the live preview and debug triggers etc nothing shows up. Got rid of any add blockers and tag assistant is saying they’re there but never does the debug box at the bottom appear. Any idea why this maybe?
Thanks,
Hi Daniel,
Your article was awesome. I am a coding novice, so I wanted to clarify something– I had Google Analytics UA installed on my WP site. Now I have added GTM per your instructions. Should I remove the UA tracking installation (I used a plug in for this), or do the two work in conjunction with one another?
Thanks in advance.
I ‘m still not clear on does the GTM code replace my old Analytics code? Or is it in addition to my regular Analytics code?
thanks!
Hey Tony,
If you’re using GTM you should not use the “old” GA code on your pages any longer. Sending the data to Google Analytics will be handled by Google Tag Manager. If you keep the old code on the pages as well, it will result in you receiving multiple pageviews with every page load which will mess up your data.
BR Daniel
Hi Daniel,
Thanks very much for a useful resource.
Having read all the comments, I did not see anyone with my specific use case.
I have a WordPress Network with 78 sites. I have configured GTM and deployed it to my highest traffic site using Tommi’s plugin.
However rather than putting GA into GTM, I am going to keep it in the WPMU Dev Google Analytics + plugin.
I’m doing that to maintain consistency across all the sites and because we use the GA+ plugin to track all site traffic across the network, with a network profile as well.
So my question, I want to start deploying tags and triggers which fire on GA Universal events.
Can I set up my tags and triggers using GA Universal events without having my GA tracking code deployed from within GTM?
Thank you kindly for any insights on this.
cheers,
Bradley
Hey Bradley,
tough question, haven’t really tried a setup like that out. The GA Tracking Code you manage through WPMU is that data being sent to your own Property in GA or is it setup to be sent into 78 different Properties?
Even if you do use GTM for the event handling, you’ll still have to take into account where to actually send the data.
BR Daniel
Thank you sooo much..
Big thanks, that was very clear and organized .
i have a question,
you said there are 2 ways , manual or plugin .
can i use both ??
Hi Abdo.
No, you should use either the plugin variant or the manual. Not both.
Hi Daniel, thanks so much, this is great information. My question is: I’m using a plug in to insert headers and footers, where I just have to place the code and it’ll go into every page. Can I just put the 2 pieces of code right next to each other in the heather? Or they need to be placed in different spots? Thanks!
Hi AJ,
What plugin are you using? I’m using this one and it gives me the option to separate the two.
/Daniel
Hello. I keep asking questions but no one actually tells me WHERE to add or correct my Google tracking codes.
Where do I start- what do I click on?
Please help
Sarah
Hi Sarah,
Are you adding Google Analytics tracking code to your page(s) or are you adding it through Google Tag Manager?
Based on your question, it looks like you want to add the regular Google Analytics tracking code. Am I right?
And yeah, sorry for the late reply.
What I am confused about is that on the manual installation it asks me to add the code on every page on my website. What exactly does that mean? I only added the code in my header.php.
You mention that as at Sep 2016 Google changed their recommended placement of the Tag Manager code. You’ve stated it should be placed close the the tag however this is incorrect as the tag manager should be placed just after the tag. This is confirmed by the article you linked to.
Hey David. You are correct. I haven’t had time to update the post but will do that now.
Hi People,
Myself I was frustrated about how to implement this nicely. This is why I made Scripts and Tags Manager which complies with with the old method of inserting the container but also the new split container method.
https://wordpress.org/plugins/omnileads-scripts-and-tags-manager/
It just makes it easier while keeping it simple I think. Would like to know your thoughts on this!
Awesome! Its really amazing article, I have got much clear idea on the topic of from this piece of
writing.