Is it possible to disable Google Tag Manager in a SPA after a user logs in? - google-tag-manager

I have a React app and want to install Google Tag Manager on certain pages, but I do not want it present after a user logs in. Is it possible to disable / remove the GTM scripts after a certain user action?
I am using react-gtm-module to install Google Tag Manager but open to other options.

Well, this, basically, answers it: How to unload a javascript from an html?
But a better answer would probably be: don't unload GTM. It's not a good practice. It adds a lot more complexity to your overall logic. People don't expect someone to arbitrarily override deployed scripts' namespaces. It's very likely to cause havoc at some point and it's unlikely the one to debug it would be thankful to you for a thoughtful implementation.
Instead, consider using blocking triggers within GTM to just prevent certain tags from firing.

Related

I´m trying to use Google analytics on my genexus based application, but I run into some problems regarding the domain name property, probably

I´m trying to use Google analytics on my genexus based application, but I run into some problems regarding the domain name property, or the lack of it sometimes.
To contextualize a bit, I have an application which runs in Apache Tomcat can´t figure out a way to make Google Analytics work with it when setting it up from the genexus properties. I´ve tried to add the Google Analytics control to my masterpage and set up the properties for ir to work, but since the domain name will change based on which server is runing my webapp, I can't find a way around this.
If possible, I want to make each instalation of the webapp to generate data to a different Property on Google Analytics Control Panel, but the only way I've managed to make google analytics work with genexus is using an external .js file using the code google analytics gave me, and doing this way I can't make each application send data to a different Property.
My ideia was on the Start Event of the master page, to set the info needed like this:
GoogleAnalytics1.Code = &var1
GoogleAnalytics1.DomainName = &var2
Where &var1 and &var2 where loaded earlier in the event.
I've tried to make it work setting it up through the properties to see if I was doing something wrong in the attribuition but didn't work either. The only way I found to make it work is to write the .js file and add it to the Knowledge Base as an external file and call it in the master page Start Event.
I saw that this was improved on GX17 U10 but I haven't found any other coments on this. Also, I could not find the .js file generated by genexus when I set the Google Analytics Control in my MasterPage, my hope was to see if there is any difference in the file generated by Genexus and the file suggested by Google. Is there any way for me to find this file or some other thing I need to set it up on my Knowledge Base to make it work? I've tried to look on genexus wiki but didn't find anything there.
At the start, I thought the lack of the DomainName was the problem, but I've managed to make it work without a domain name using the static .js file, so right now I'm not so sure about what's the problem here.

Google Tag Manager on localhost

I was asked to implement the Google Tag Manager scripts into the React application. I've added the scripts to head and body of my html file. I've tested the site in the Preview mode of GTM and everything seems to working fine. Clicks and route changes are tracked correctly.
I have one doubt... What about the localhost development ? Is it going to generate unnecessary logs on the analytics (which I have no access to)? Or maybe it's just enough to paste the snippets and that's it?
I can't find an answer so that's why I decided to ask here.
If someone has some experience on that topic - please let me know :)
I would advise you to map separate Google Analytics property IDs by either a datalayer variable, URL or custom JavaScript to return a separate property ID based on whether users are accessing your website from either your localhost development environment, your UAT environment (if any) and then your production environment (or others as applicable).
Essentially you're looking at having something that says "if the URL contains "localhost", return my development property ID", then use this variable name in your Google Analytics tag(s) instead of a static value.
Yes, unfortunately all your existing testing is all in your profile because if you had the production property ID configured and fired off a bunch of events and pageviews, it absolutely collected and sent there as part of the debugging experience. Generally though, that's a low concern on a production app because you make up such a small portion of overall traffic; you're just a couple of blips in the larger dataset.

Is there a way to get a developer account to avoid being confused with an automated tool?

I'm currently developing a Chrome extension to use with LinkedIn Sales, and I'm having issues while testing the front end.
Due to some style changes, I had to refresh the page multiple times and now my account is temporarily banned because they confused me with an automated tool.
Does anyone know a workaround for this? Or, alternatively, can I create some type of developer account to use?
TIA!
Due to some style changes, I had to refresh the page multiple times
This is really a suspicious action.
So isn't your "Chrome extension" also an automated tool?
Either get some API access (you find available APIs here https://developer.linkedin.com/product-catalog)
or if you just do some visual brush-up for users, you could try to make an offline copy of the page once (with a tool like HTTrack) and then use that copy for development.
For the Sales API it says
It's required that all integrations are built by approved partners for the SNAP program. To become a partner, visit this page.

Google Tag Manager and page load performance: does it reduces performance in PageSpeed Insights?

I know this may seem a bit vague, but I'm about to give more context: in the company I work for we use (my personal thought is we're misusing) Google Tag Manager (GTM) to inject some third party scripts inside GTM tags. Mostly we use it to manipulate the DOM in certain page templates (like, for instance, product pages) and inject third party scripts (examples are Zopim chat, Facebook pixel, etc…).
Things we tipically do are: manipulating the DOM when DOMContentLoaded and/or load events happen on page load, so It seems obvious to me that without these GTM tags our site will get a better score in PageSpeed Insights and in Chrome DevTools' Lighthouse. I can't test the website without GTM tags activated since it's already everywhere in the site.
How much is this kind of use of GTM harming our site speed?
There are a few different ways in which you can find out the performance impact of GTM and the third party tags.
Via the Developer tools
You can block gtm.js in your browser developer tools. This will prevent loading of Google tag manager and the associated tags. You can find out more about that feature here. Once you have done this, you can run Google Lighthouse from your browser, to see how your scores improve.
Via Webpagetest
You can also use Webpagetest to find out the performance without third party tags. Webpagetest has a request blocking feature or you can use the following Webpagetest script to test out the performance with only your first party domains.
blockDomainsExcept yourwebsite.com
navigate https://yourwebsite.com
This is to measure the performance impact of your third party scripts. You probably will get similar results if you include the third party scripts directly into your website without using GTM. That being said, there are ways to optimise your GTM setup for performance and to fully leverage the features of a tag manager to improve the performance of your website. You can check out this article if you are interested in optimizing your GTM setup.
Injecting tags is what GTM is for, so this does not constitute abuse.
GTM itself is just a delivery mechanism; it's one JS file (I think an empty container is some 100KB unzipped, and 30KB to download if your browser supports compression) with a mechanism for asynchronous loading of tags. By itself it will contribute very little to the page load time.
Of course the stuff you deploy via GTM might slow down your site a lot - partly because it will download external libraries, and partly because DOM manipulations might force reflows/repaints in the browser. However this is not due to GTM, this is due to the tags you use, and would happen exactly the same if you integrated Zopim etc. via some other means.
So, will using a lot of (potentially bad [1]) JavaScript make your site slow? In all likelihood, yes. It this the fault of GTM? It is not, other than in the sense that GTM makes integrating the nasty stuff a little easier.
[1] Not a dig against you, it's just that marketing tags are quite often written in appallingly outdated JavaScript.
Yes, it reduces the Lighthouse performance scores, especially the mobile ones. We have to be very careful adding GTM to our website, especially for the homepage. For my website, GTM was injecting another 5 JS files from different domains. This adds more Round-trip time (RTT)to our application and in-turn add more load to browser.
When I removed GTM from my homepage, it improved Lighthouse performance scores by 5 points. So there should be some kind of suggestions/insights provided by GTM itself whether it is going to impact our website or not.

Manage ads inside a Single Page Application

I m developing a Single Page Application (SPA). So, I use to refresh the page's HTML's content dynamically using Ajax requests.
I'd like to register to the DoubleClick for Publishers program, but I m wondering if my SPA is able to integrate advertising due to its dynamic content loaded without refreshing the page.
I saw this link: https://support.google.com/dfp_sb/answer/3058726
So I assume it's ok. But I'd like to be certain before starting using DFP. Could someone confirm please?
Then, sometimes I m using external html pages that I still load using Ajax. Should I consider writing the advertising banners JavaScript inside these external views, or directly inside the master page of my app?
Last question: How can I manage users having an adblocker software installed? Am I allowed to detect the presence of an adblocker software using JavaScript and then execute some specific code for this kind of users?
I'm working in a SPA and working with DFP successfully. Here is my feedback to your questions:
So I assume it's ok. But I'd like to be certain before starting using
DFP. Could someone confirm please?
Yes, you can refresh the banners using the method you are refering in the link you shared
Then, sometimes I m using external html pages that I still load using
Ajax. Should I consider writing the advertising banners JavaScript
inside these external views, or directly inside the master page of my
app?
To load them externally will bring you to lower performance results. You can control everything from the main page and you will have better results.
Last question: How can I manage users having an adblocker software
installed? Am I allowed to detect the presence of an adblocker
software using JavaScript and then execute some specific code for this
kind of users?
This is something I have not started to work on it but you can detect (like forbes.com is doing on it website) and there are also projects on dealing with this.

Resources