Google Universal Analytics Enhanced Link Atrribution - google-analytics

I'm using UA on our company's in-house software to help understand how our users use it, and part of that is learning what they click when they click and so on.
Enhanced Link Attribution seems to be the best choice for this, but per the Developer Docs:
Tag your page for enhanced link attribution
In order to implement this additional tagging for enhanced link
attribution, you have to use the asynchronous version of the Analytics
tracking code.
The problem I'm seeing is that currently, I'm using Universal Analytics which uses analytics.js whereas the Asynchronous version of GA uses ga.js. So now I'm confused because the option is available in my property settings in the Admin section in our GA account.
Univeral Analytics
<script>
(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-CODE-HERE', 'SITE_URL');
ga('send', 'pageview');
</script>
Asynchronous Code
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Since the two versions of GA are not compatible, can I still use Enhanced Link Attribution? If so, what steps would I take? I can't seem to find the answers in the Google Analytics docs related to ELA with UA.
Edit
Is it at all possible or advised to use both versions of Google Analytics on the same page/site/property? Assuming I set up another GA property for the standard version and use both JS snippets on the site?

To answer the original question:
No, enhanced link attribution is not yet supported by Universal Analytics. Though this and many other features will be rolled out soon enough. Universal Analytics is still very beta, but it's been established that this is the future for google analytics.
Yes, the new code is asynchronous just like the old code, and I really couldn't imagine a situation where you would want to turn this off. Asynchronous loading in this case means that when the analytics javascript fires, your web page continues loading regardless of whether the javascript has finished loading or not. Before the asynchronous snippet update, it was best practice for the analytics code to be loaded in the footer to prevent the entire page from hanging due to the script not being asynchronous in nature. Though this was changed because on long/slow pages, the user would often interact with the website before the footer/javascript had a chance to load, and in turn caused major discrepancies in the data.
Wikipedia:
In computer programming, asynchronous events are those occurring
independently of the main program flow. Asynchronous actions are
actions executed in a non-blocking scheme, allowing the main program
flow to continue processing.
I also wouldn't suggest changing the object name as Concept Rat suggests, as I believe that would only apply if you were implementing multiple "universal analytics" trackers to different web properties within the same snippet.
https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#snippet:
Renaming the Global Object
In some cases the ga variable name might already be used by an
existing object on your page. To avoid overriding your existing
object, you can rename the ga function, for example to __gaTracker. To
do this, simply replace the ga parameter in the snippet above:
(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','__gaTracker');
Then you can use __gaTracker instead of ga when calling commands:
__gaTracker('create', 'UA-XXXX-Y');
__gaTracker('send', 'pageview');
If renaming the variable were necessary to load both snippets, I don't believe Google would say this:
https://developers.google.com/analytics/devguides/collection/analyticsjs/:
The analytics.js snippet is part of Universal Analytics, which is
currently in public beta. New users should use analytics.js. Existing
ga.js users should create a new web property for analytics.js and dual
tag their site. It is perfectly safe to include both ga.js and
analytics.js snippets on the same page.
Also please note, if you want to try out universal analytics you should run it concurrently with your existing implementation, as they should eventually release a migration tool to remain backwards compatible allowing you to keep your existing data. To be perfectly clear:
You should only fully implement universal analytics if you're are creating a brand new account with no existing data in place.

I've been researching this same problem. As of November 2012, Google said the following in response to a support question: "In-Page Analytics support for analytics.js is not yet implemented. This is one of the features we'll be working on and introducing later in the beta. Other features not currently supported include Remarketing and AdSense reporting." As you know, Enhanced Link Attribution is a feature of In-Page Analytics.
I have not found any new references to this issue since that post, so I can only assume they Universal Analytics is still not ready for prime time. If you can, I would try using Asynchronous Code until Universal Analytics is working properly.

FYI: Universal Analytics is out of Beta testing and Enhanced Link Attribution is now supported:
https://support.google.com/analytics/answer/2558867?hl=en

For your reference the Universal Analytics is, or does support, asyncronous mode. You can see it in the Universal JS code third line down under the "script" tag "a.async=1;".
You can also run both the standard GA code and Universal at the same time. Just setup a separate property for the Universal code and make sure to change the object name "ga" that you see on the fourth line "//www.google-analytics.com/analytics.js','ga')" to say "gau" (just has to be unique on the page for scripts). Then use "gau(" instead of "ga(" for setting things, etc. Remember this is just for the Universal code not the standard GA.
Once you've done this you can continue to track things using the standard GA and have the Universal GA logging underneath the new property. Once you're happy with things you can switch to using only the Universal one.

Related

Which gtag MEASUREMENT_ID to use

I'm a back end developer, sometimes a little fronted, but not a SEO related expert at all.
Now I have to make a full website from top to bottom and I'm stuck with the Google stuff.
First I created a Google Analytics profile, I got the srcipt that I needed to hardcode to all my site.
<script async src="https://www.googletagmanager.com/gtag/js?id=G-MEASUREMENT_ID></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-MEASUREMENT_ID');
</script>
However, a little while later, I started to use Google Ads and it recommended to connect my Analytics page to the Ads page, so I connected them and I got another code that I needed to insert.
The code snippet is almost the same, except the two MEASUREMENT_ID, because now I got a UA-MEASUREMENT_ID.
So, do I have to use both snippets, or just one? If so, which MEASUREMENT_ID should I use?
Or am I screwed up something?
Thanks all the help
The code with UA- (Universal Analytics) and the one with G- (Google Analytics 4) belong to two completely different tracking systems in Google Analytics. If until now you have used UA- you should continue to do so and in parallel track with the new one G-. So you will have two tracking codes at the same time. This is also Google's suggestion not to lose the data history in UA-.

What is gtag and why do I have to add that separately from google tag manager?

I find Google documentation around Google Tag Manager (GTM) terrible at helping me figure out which bits go where.
As I understand, GTM requires that you put a <script> snippet on your pages which is supposed to bring in other code snippets, as could be configured by a non-technical user.
I'm a technical user, though. Perhaps that's the problem! I also find it problematic that Google use the word "tag" to refer to either an HTML element tag, like <script>, or their own proprietary use of the word to mean calling a function ("triggering a tag") in another script, also unhelpfully referred to as a tag.
They also have "gtag" which is what - a helper? something that enables you to send general analytics events through the GTM API? The docs simply say:
The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.
... but we could already send analytics? What does this add?
For example, I wish to send an e-commerce Purchase event.
I've found that to do this I needed to add a new snippet of code with two <script> tags to the header on the site (thought GTM meant I didn't need to do this?) that sources gtag.js, then I'm able to call the following at the appropriate place in my javascript:
gtag('event', 'purchase', { value: 1.23, transaction_id: 'test' });
Or without it (although this does not seem to work):
ga('require', 'ec');
ga('ec:addProduct', {name: 'test product', price: 1.23})
ga('ec:setAction', 'purchase', { id: 'test_id_1', revenue: 1.23 })
So my question is: when would you use gtag() over ga(), and why can't GTM install gtag?
When would you use gtag() over ga()?
Use gtag if you want to send data to supported Google products other than Google Analytics. As you pointed out, "The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.", whereas ga only works for Google Analytics. But (see below), you might decide to never use gtag nor ga and always use GTM.
Why can't GTM install gtag?
It could (you could have a GTM tag inserting some gtag code) but it's beside the point as they are meant to be used as 2 different solutions:
gtag is a purely programmatic tracking tool for sending data and only works with 3 Google products (so far - Analytics, Ads, Marketing Platform - more maybe added in the future), it's made to provide basic out-of-the-box tracking with a simple copy/paste + small lines of code (if needed for customization).
GTM is a tag manager: it can work programmatically BUT requires a minimal configuration of the container via the GTM UI (a default container won't send data anywhere), and can send data to whatever products you want (just need to setup the corresponding tags in GTM), while having a bunch of other features
A few questions to help you choose:
Am I sending data to other tools than Google Analytics/Ads/Marketing platform?
Do I want to use some the extra features GTM offers (UI, version control, templates, debug, environments etc...)?
Is there some tracking that would be heavy to implement via pure custom JS (eg scroll tracking) which GTM can facilitate with its built-in listeners (eg scroll tracking)?
If YES to any of the above, then use GTM
I personally never use gtag, I always replace it with GTM because it's considerably more powerful than gtag.
What Google is doing is progressively replacing all their default snippets with gtag so they only have 1 unified API to maintain and it's an easy copy/paste for users (bear in mind most users aren't tech savy and just need to paste the snippets in into their CMS). Forcing people to use GTM would be too much of a friction as out-of-the-box GTM simply doesn't track anything and people would need to learn & configure GTM, too much work vs a simple copy/paste.
Note: The built-in events don't use category, label, and value. Take care to use the correct keys when sending these events.

Google Analytics stopped gathering data when migrated to gtag.js

I have an angular.js webapp and I´m using Google Analytics. On 16/11 I migrated my angular webapp from the old universal google-analytics.js script to the new gtag.js. Next day, I stopped to getting analytics information. See the screenshot.
Some considerations:
I just migrated the js in the webapp.
I didn´t change any configuration in Google Analytics.
With the purpose to filter spam or ghost visits in GA, since a long time ago I had a filter that I "expected" to allow analytics only from my site, like:
I have another view without any filter that I have noticed that seems to work. So for some reason the root cause could be the filter.
Also, I have noticed the real-time reports are not working in the filtered view, however, they are working in the not filtered view.
For testing purposes, I have just deleted the filter and the real-time reports are working.
As before the migration, I was gathering analytics, I think there are maybe different problems:
- It looks like the filter is (and was before the migration) preventing the real-time reports to work.
- Apart from the real-time reports, the analytics were working before the migration with the filter, so is there anything that needs to be changed, updated in analytics in order the gtag.js works. Or maybe gtag.js is working in a different way that makes analytics not work with that filter?
- Should I delete the filter in any case? At the moment, I have deleted it and I will observe what happens with the analytics next days. However, if I delete the filter the spam analytics will come back. Maybe there is another filter that has to be applied.
UPDATE:
I attach the Gtag.js script in the website:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-property-1"></script>
<script>
var gaEnv;
switch (window.location.hostname) {
case 'www.domain.com':
gaEnv = 'UA-property-1'; // production
break;
case 'www.test.domain.com':
gaEnv = 'UA-property-3'; // test
break;
default:
gaEnv = 'UA-property-2'; // development
}
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Config for analytics
gtag('config', gaEnv, { 'send_page_view': false });
// Config for Adwords
gtag('config', 'AW-property');
</script>
As I use Angularjs I hace developed a service to track page views, like:
service.trackPageView = function (url) {
gtag('config', trackingId, {'page_location': url});
/* Old code for google-analytics.js. deprecated with gtag.js
* ga('set', 'page', url);
* ga('send', 'pageview', url); */
};
UPDATE 2: I have installed Google Tag Assistant. It looks like it´s gathering the data and tracking the pageviews. The only strange thing that I see is the alert: This hit is missing the hostname in the URI.
UPDATE 3: As I suspected, when I delete the "include only" my hostname filter in the analytics view, the data is gathered again as you can see in the pic.
So, it´s pretty clear that gtag.js is sendind data from the app to Analytics to the right property.
Now, the only point is that I had that filter that I have deleted to filter the ghost analytics spam. So, I assume it will be back soon. Again to the starting point.
My concern is if it´s maybe related to the info that I send to analytics or maybe the filter was wrong. So, I think I will need help to setup the filter working properly with this gtag.js library.

How to send ga(...) events with Google Tag Manager?

I'm changing google analytics for google tag manager on an existing website. This website also uses google e-commerce, so I have a few custom ga() calls related to the e-commerce being done on some pages.
The problem is that because the google analytics script loads asynchronously, ga() is not defined anymore when I'm trying to send some e-commerce related data.
I've found a workaround somewhere:
window['GoogleAnalyticsObject'] = 'ga';
window['ga'] = window['ga'] || function() {
(window['ga'].q = window['ga'].q || []).push(arguments)
};
But, although I've not the "ga is not defined" problem anymore, it still doesn't work.
I don't see anything on the google dashboard. I also don't see anything on the debugging messages (in the developer console).
What seems to be happening is that the GA script loaded with GMT is not using these variables I've set but I'm not sure how to fix it or if it is even possible to keep using my ga() calls with GMT.
I know that I can do it with dataLayer but I'm trying to avoid to rewrite a bunch of working code just for this.
I have seen an implementation that does it like this:
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', UA-XXXXXXXXXX, 'auto');
ga('require', 'ecommerce');
maybe that works out for you as well.
if you use enhanced e-commerce then the code below the "ga('create..." hast to change from:
ga('require', 'ecommerce');
to:
ga('require', 'ec');
The order is important here, events can be send after those functions.

Event tracking with analytics.js and without GTM

I’d like to track certain Webflow events in Google Universal Analytics (using analytics.js) without the use of Google Tag Manager. The specific scenarios we are trying to track are:
PDF downloads
YouTube Video views from lightboxes, sliders and straight embeds
I added the JavaScript tracking snippet to the site-wide Head Code of my site, replacing the UA# with the real one.
<!-- Google Analytics -->
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
Do I just proceed with setting up Event Tracking on a per element basis or do I need to create a tracker?
If you create new trackers they might overwrite configuration options for the first tracker (if any), so that is not only unnecessary but potentially harmful (unless you want to track to different properties, in which case you'd use named trackers that do not interfere with each other).
For your use case you need only the default tracker and then you send an event for the elements the user interacts with.
You might also consider using gtag.js over analytics.js, since Google now gives gtag.js as the default code; documentation is much worse than for analytics.js and there are some doubts that it is feature complete, but Google is unlikely to roll back so I'd say gtag.js is more futureproof.
Gtag.js has some of the advantages of GTM (consistency between tags via the datalayer) without its main disadvantage (arbitrary code injection - GTM has been describes as "XSS as a service"), so it might make sense to go that route now.

Resources