Adding GTM to a website with GA - google-analytics

I have a website that has been using GA for some time. Now someone wants me to add it to theirs GTM and replace my snippet with that GTM tag.
I don't know how to use GTM and don't really want to dig into that :/
My website was working just fine... Is there some easy way to make GTM just a simple middle man that looks at my domain and just throw everything directly to GA?
I manage to make it so GA gets info on the website traffic like active users etc. however that website has scripts that fires events to GA.
After googling a while i think this is because GTM adds some random names to the trackers and my code calls ga('send', ... ) directly :/
I know i can make a custom tag in GTM but they want it to be UA tag -_-.
Is there any way to set a default name for my trigger in GTM settings? Or some other solution?
atm. i have a code with gtm tag only and I'd rather avoid changing my web code if possible.
Edit
Ok, could someone explain to me how to achieve this:
I have this code:
var a = $('meta[property="a"]').attr('content');
var b = $('meta[property="b"]').attr('content');
ga('send','event',a,event,b);
where event is one of several possible strings of for example 'event_1','event_2' or'event_3'
and my GA has 3 goals that have action = 'event_1' etc.
How do i replace this with GTM and dataLayer?

This thread has 2 questions :
1.- Migrate a hardcode implementation of Google Universal into Tag Manager is not so simple as copy and replace the Universal Main Snipper for the GTM Code.
Look for this google guide to migrate. Has more or less the steps needed and the one to take in consideration during the migration.
https://developers.google.com/tag-manager/devguide#migration
If you goes for GTM, it's higly recomended to remove your ga() function on the page, this will stop working and you javascript too. Basically this mean, remove all your Google Analytics of the domains and install GTM and configure the corrects tags. Try to avoid things like paste the Google Analytics code inside a custom HTML tag, it's a very bad practice, but is see that a lot. Plan your migration
2.- Regarding the event you have to do :
Create a tag of universal analytics events and activate when you pushes a GTM event, them manage this values via the dataLayer
Let this link for more information:
https://support.google.com/analytics/answer/6164470?hl=en
var a = $('meta[property="a"]').attr('content');
var b = $('meta[property="b"]').attr('content');
dataLayer.push({'event': 'ga_event' , 'cat' : a , 'act' : b})
Try to involve more yourself in the GTM and Universal's World before ask, i'm not trying to be an asshole, but this question involves so many things that can be solved just looking the documentation, and somany thing to examplain in a single post.

Related

How to add Adsense in Google Tag Manager

I want to use Google Tag Manager to serve Adsense so I also can use other ads from other sources. I found few answers across the sites but not enough to understand. I would appreciate input here if it is possible to use Adsense code in GTM, if yes how? I also use DFP, if I have to use DFP then how it would be.
I assume you already have Google Tag Manager (GTM) running on your site?
Click on Variables on the left side of the screen within your GTM workspace
Create a new user defined variable and call it asClientID
Configure the variable as a Constant. The value to enter is your AdSense Client ID
Click on Tags on the left side of the screen within your GTM workspace
Create a new Tag called AS - Page view - ALL
Because there is no built-in tag in GTM for AdSense you need to use the Custom HTML tag.
Copy and Paste the HTML code shown below into GTM.
Select the trigger All Page views
Test your changes in preview mode
Once everything is working publish the changes to LIVE.
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "{{asClientID}}",
enable_page_level_ads: true
});
</script>
As you can see we are using {{asClientID}} in the script which you have created in step 1 and 2. The reason for creating this variable is flexibility. If you need to change the ID you change it within the variable and not within the code.
NOTE: that it is not best practice to implement AdSense via GTM, but it is possible.
Hopefully this is what you are looking for. Please do let me know if it works for you. :-)

Switch from Google Analytics to Tag Manager

I have site which run on Google Analytics for some time( more than 1 year), now I want to use Google Tag Manager. If i remove Google Analytics from site, and start tracking with tag manager, there is a risk of losing data?
It's really hard to give a helpful answer to that - if you manage a seamless switch between GTM and inline GA code, and have set up everything correctly then you will not lose data. Is there a risk you make mistakes ? Probably.
I recommend to integrate GTM alongside GA and set up your GA tags so that they track to a test property. Then you can compare both properties to make sure that you track actually the same things. And that point you can throw out the inline GA code and switch to GTM (if you implement the tracking id as a variable in GTM it will be as simple as changing a single variable).
But remember to actually remove the inline code, else you will end up with double pageviews.

Google Tag Manager + Google Analytics v just using GA: any reason to use just GA?

I am using Google Tag Manager on all my sites now to implement Google Analytics and future proof them for any other scripts.
I am putting GTM in my boilerplate.
Is there any reason this might not be good practice?
Any reason why a website (that needs GA) should avoid Google Tag Manager?
Most websites will require some sort of Javascript code added in the future for affiliate tracking, various analytics and having GTM installed will allow for easy installation of any such JS code easily.
Or, as Google puts it: "Why wait months for site code updates? Google Tag Manager lets you launch new tags any time with a few clicks, so you never miss a measurement or marketing opportunity."
Since GTM does not come with a service level agreement you could (very very tenuously) argue that GTM adds an additional point of failure. And if one wanted to be pedantic one could point out that not all ways of analytics tracking work with GTM (if you track serverside via the measurement protocol).
But real life argument, there is none (IMO).
There might be pages that do not greatly profit from GTM (or any other Tag Management) if all you do is to deploy a single analytics tag to track pageviews. But the second you need to track an event or pass data GTM is already worth it.
This is not meant to be merely opinion based, it's more that in 2,5 years of using GTM on large sites I have been unable to find any scenario where the tag management code has caused any technical problem or interfered with existing code. On the other hand I do not write click handlers or submit handlers anymore, I have a boilerplate template for a container tag in which I just have to replace values for a few macros before I import it to GTM and have tracking up and running, I can set data fields with much less trouble than via the code... so I think there is a real technical argument to make in favour of GTM, and none against it.

How to run Google Experiment within Google Tag Manager

I have been trying to get this to work for sometime and there seems to be very little information on how this works.
First, I would like to say that I tried the below method to get it working, so please read this before posting a solution.
What I tried:
I added the google analytics experiment code in a custom HTML block and had it fire only of the original page as stated by google. This doesn't work and seems to create a loop for users. A white page appears when users get to the experiment pages.
Does anyone know how to get this to work? Much appreciated
The Javascript versions of Google Content Experiments are not actually supported in GTM at the moment (they have do do either redirects or change the site on the fly and since it's hard to say in advance at which point during page load the tags fire, and it which order, this does not work very well - in the very best case the original page would load completely before the visitor is redirected to a variation).
The features page for GTM lists A/b testing tags as "coming soon" but does so since at least a year ago, so I wouldn't hold my breath.
However you can do variations serverside (you'd have to implement your own logic to display the proper variation to each users) and pass and experiment id and the variation number to GA via GTM. I do not think there is another (reliable) way to do this, at least not yet. If you need to do it with javascript you should add the experiment scripts to the page code instead of deploying them via tag managemement.
Having said that, there are descriptions for hacking around the GTM limitations using the Experiments Javascript API and some jQuery (here is one). When Google says that something is "not supported" it might just mean they didn't want to test all possible edge cases and err on the safe side. So you if you absolutely have to use GTM for Content Experiments you would have to test if something like this would work for you.
I hope that I understand your problem well. If yes, you can use Google Optimize instead of Google Experiment. The Google Optimize works with Google Tag Manager by default.
Here's what worked for me
For the pages in the Experiment, I implemented Google Analytics the "old fashioned way" with analytics.js instead of GTM.
I tested (with Realtime analytics) this and the Experiment page and the Google Tag Pages both report data.
I did post asking if there might be conflicts from ths.
It's possible to modify the Google Tag Manager (GTM) snippet to run synchronously by removing the j.async=true; line and placing it at the top of your page, immediately after the opening <head> element. Like so:
<!-- 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.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');</script>
<!-- End Google Tag Manager -->
You can also retain support for users without Javascript by inserting the <iframe> part of the code in the original location specified by GTM (after your opening <body> element).
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe</noscript>
It's then possible to insert the Google Analytics Experiments code as a Custom HTML tag in GTM. Just make sure you check the 'support document.write()' checkbox.
Just don't forget to update GTM-XXXX with your container ID.

How to use Google Analytics Tag Manager to track off site links

I noticed that Google has released their Tag Manager application making it really easy to make changes to your tags and tracking options. How can I use this tool to track off site links?
Google Tag Manager (GTM) is not a tracking tool, so the short and unhelpful answer is that you can't. However you can deploy Google Analytics via GTM, which I guess is what you mean. I have to say, though, that tracking offsite links turned out a little less straightforward than I expected it to be.
Usually you track external links by virtual pageviews (or events). The usual way in GTM would be to push a variable to the data layer on the click event of the link and then fire a GA tag with a virtual pageview based on a rule based on that event. This failed completely for me when I tested it, presumably because the new page had loaded before the GA tag could fire. So I resorted to a not very elegant workaround:
First I created a standard Google Analytics Tag (tracking type pageview) to make sure the GA code was included in the site. Then I created a custom HMTL Tag with a bit of Javascript (this is assuming you use jQuery in your page):
<script>
$('a').click(function() {
var p = $(this).attr('href');
if (p.search(/.+YOUDOMAIN/) == -1){
_gaq.push(['_trackPageview', "external://" + p]); // mark links as external in the GA interface
}
});
</script>
For all links that do not contain YOURDOMAIN a click event with a pageview is attached to the link. To make sure the all the links are tagged with the click event you set a rule in the tag manager to make sure the script is executed only after the page has loaded you set event based rule in the tag manager where the event is equal to gtm.load (gtm's equivalent of jQuerys domReady).
This works (at least it did in my tests), but since it does not use GTMs intermediary dataLayer it looks rather like a hack to me. If anybody can suggest a proper solution I'd be grateful.

Resources