Google Analytics Universal and Classic - google-analytics

I have several different Google Analytics codes for several different purposes. With the one I recently created, GA automatically created it as Universal, without the option of Classic. However, I have several other trackers as Classic.
Is there a way to use both Google Analytics Universal and Classic codes on the same page?
I have too much to do a migration and change everything around, and need an option to use both codes on the same page.
Thanks for your help!...every time you help me you save a kitten!!

The "classic" code will track to classic properties or, for the time being, to properties that have been recently transferred to Universal Analytics. UA code will track only to UA enabled properties.
You can mix classic and universal code on properties that have been recently transfered to UA (altough at the moment I cannot find the reference for that in the docs, plus I'm not sure how this will work with cross domain tracking).
You can use both ga.ja and analytics.js without problems if they track to different properties (again, this will give you problems with cross domain tracking since they use different parameters to transfer the session between domains).

Related

Using Google Tag(gtag) with Google Tag Manager

I currently have an implementation of GA4 using gtag in my website and I would like to add GTM too. I was wondering if I can use the same endpoint from GA4 (https://www.googletagmanager.com/gtag/js?id=) and insert the GTM tag where id is and GA4 and GTM again with config.
I found this for the documentation
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script> but nothing that specifically talks about using Google Tag with Google Tag Manager. Almost all of it is about using the GTM interface.
I found that GTM supports googletag but the endpoint uses https://www.googletagmanager.com/gtm.js?
It's not recommended since GTM can load gtag and a bunch of other libraries as they're needed and manage them in the most optimal way. That's why you see a lot more information on GTM than gtag.
Implementing tracking with gtag.js is, in most cases, a mistake unless you don't care much about it and just want to be quick about it.
Having said that, yes, you can load both separately. GTM will attempt to use the existing gtag library if it needs it. Set up like this, however, requires you to understand how both libraries deploy listeners to the dataLayer array and how they store/use the local state of things. They will also use the same cookies.
Even though the libraries don't conflict in terms of syntax, it's uncommon to have logical tracking issues due to implementations like this.

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.

Migrate data from one Google Analytics Property to Other

We by mistake created a Google Analytics Property of type Apps + Web(as in image). But it restricts us from using many Web specific features (like adding custom dimensions and connection with Google Tag Manager).
So we create a new property of type Web (as we anyway won't need App related things anytime sooner), but now how can we migrate all analytics data(of 4-5 months) to the new property.
We tried to go through the docs and didn't find any related help.
Any input would be helpful.
There is no way to migrate the data from one Account, web property or view in google analytics to another. Once the data has been sent the data is there forever unless you delete the account.

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.

Google Analytics Tag for Dev vs. Prod

I run a standard google analytics tracking code (ga.js asynch version) on a website.
I am wondering if there is a line of js I can add to the tracking code so that I can segregate dev/prod data? e.g. when I pull in the codebase to do dev work, I can set the tag to DEV. When releasing back to production, DEV tag gets replaced with PROD tag.
Is this even possible and if so, how do i implement it?
One method I thought of is just to create a new "property" (which would generate a new ua number, which I could add during dev. that would allow me to track it all separately.)
Wondering if there are any other methods I should consider.
Alternative to mike's answer is to setup a filter in your profile based on the url or domain or based off any number of other things.
I'm not worried about collecting data from my development server, but I do want to make sure I'm not polluting my production data -- I've been using some variation of the following:
if (!/devServer|localhost/.test(window.location.hostname))
{
_gaq.push(['_setAccount', 'UA-11111111-1']);
}
On the devserver domain (or on localhost), _setAccount doesn't get executed, so the tracker defaults to the default tracker, UA-99999999-1. This allows you to still see tracking data being sent to the analytics servers (via ga_debug.js, chrome dev tools, firebug, fiddler, etc), but doesn't register against your production profiles.
Downsides -- it is an extra bit of code that get's run on the client.
If you do want analytics from your development servers, you could try something like:
gaq.push(
[ '_setAccount',
/devServer|localhost/.test(window.location.hostname) ? 'UA-11111111-1',
'UA-22222222-1']
);

Resources