Automatic checking of GTM Tags - google-analytics

Is there is a tool or a solution that automatically checks if the GTM (Google Tag Manager) tags are working properly on a page?
I don't need it to do anything else except retrieve the bag of tags and let me know which any URLs where there is a problem with a tag.
I can only find manual validation checking and I would need to implement a solution for a large number of tags so automation would be most helpful.

There are a few paid services that I can think of:
Observepoint
Tag Inspector
I'm sure there are others, but those are the ones I've used.
You can also use GTM's error tracking to log client-side JS error. Doesn't really check to see what tags are firing, but will let you know when your JavaScript is having problems.
Good blog post here: Using Google Tag Manager to log JavaScript errors in Google Analytics

Related

How can I redact personal-identification info (PII) in a URL when using gtag.js?

I'm using the Google global site tag (gtag.js) to manage my tags, and I use it for Google Analytics.
Sometimes there is an email address in URLs on my site, and I need to remove that from the code.
I know there are clever ways to get this done when using Google Tag Manager. But I'm not using GTM, I'm using gtag.js. (This simple page explains the difference.)
How can I check the current page's URL for email addresses and fix that, before the URL is tracked by gtag.js?
(I know how to do the regex etc... this is more asking where in the flow can I grab the URL and 'rewrite' it as needed before the Analytics pageview event posts?)
I looked through the gtag.js API reference without much luck. Also looked at the docs for how Analytics implements gtag.js, still no luck.
Indeed Google's documentation can be hard to explore sometime since they describe stuff only once for better maintenance and consistency, but at the end you could be missing a working summary ...
I would suggest to use this https://developers.google.com/analytics/devguides/collection/gtagjs/pages
gtag('config', 'GA_MEASUREMENT_ID', {
'page_path': '/pagepath?email=redacted#example.com'
});

GTM Not Writing to Page With Custom HTML Tag

I'm trying to implement schema markup on my site using Custom HTML tags in Google Tag Manager. When I preview my changes, it works perfectly. However, when I push the tag live, it does not appear on my page.
I've had a similar issue with tags in preview appearing differently than in live. But when I tried looking into it, it I couldn't find an answer on why that would happen.
So I'm wondering if you have any insights into why this tag works in preview, but does not work live?
I figured it out. We had an X-XSS-Protection header set to 1;mode=block which was limiting Google Analytics from injecting scripts that could be considered an XSS attack.
This could have also happened with an incorrectly configured Content-Security-Policy.
The correct way to set up a Content-Security-Policy that allows Google Analytics and Google Tag Manager to inject scripts is outlined in this Lunametrics article (take note of Simo Ahava's comment after the post).

Adding Custom Popups using google tag manager

When a user lands on a page, I want to show a custom HTML popup. I have Google Tag Manager integrated with the website.
Can this HTML Popup be shown using Google Tag Manager? (script and code to be inserted using Google Tag Manager)
Is it frowned upon / not advised to use google tag manager for
anything apart from tracking?
1.) Yes - GTM is pure Javascript, and inserts Javascript into the page code, so anything you can do you can do via GTM. There are some minor caveats (e.g. a size restriction on custom HTML tags), but doing a popup should work just fine.
2.) There are certain use cases that are discouraged - Google recommends against (or at least used to) making visible changes to the page markup via GTM. The problems with that are that GTM is loaded asynchronously, so you would not know at which point the changes show up and you might get "flickering" pages, and a possible performance impact when you force the page to re-render.
Nothing of this applies to popups, so you should be fine (although using popups these days might have its own problems, but these are not related to GTM).
Personally I would recommend against implementing popups via GTM if the popup is an integral part of your page; splitting up an application between page code and GTM code will sooner or later confuse a developer. But if this is just advertising or a call to action or something similar then (IMO) using GTM is not a problem at all.

Adding GTM to a website with GA

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.

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.

Resources