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.
Related
basically, my website is based on one set of html codes but it is hosted on 3 different domains. (example.com, example.sg, example.my)
So each of these websites has their unique ids for Google analytics tracking.
Is there a way to tweak the code from Google to track all three websites respectively?
This is the current code I am using.
<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-38011741-2', 'versafleet.sg');
ga('send', 'pageview');
</script>
It is from here: https://developers.google.com/analytics/devguides/collection/analyticsjs/
The flaw with the code is that it only takes in one id for example.com and there is no where to include the ids for the other 2 websites.
So is there a way to include the ids of the other 2 websites into code to track them as well? Thanks for your help!
You could change your configuration depending on the hostname. Not tested, but it work something like this:
uaids = {
"domain1.com":"UA-XXXXX-X1",
"domain2.sg":"UA-XXXXX-X2",
"domain3.my":"UA-XXXXX-X3",
}
ga('create', uaids[window.location.hostname], window.location.hostname);
ga('send', 'pageview');
where the uaids-Array stores the Account Ids with the respective domain as index and the hostname is pulled via javascript from the location object to retrieve the value.
It would be more reliable to change the account id serverside (but I guess if that where an option you would not have asked).
However in your case it would be simpler to use the same account id for each domain (since apparently the pages are the same) and use view filters based in hostnames to separate the data (update: on second reading I may have misunderstood the requirements).
Unless you expect people to move between the domains and you want to track visitor sessions across domain boundaries - in that case, as already has been pointed out, you would need cross domain tracking (and you should follow Crayons link and get back to us with any problems you encounter there).
Google Analytics uses 1st party cookie tracking. You need to implement cross domain tracking on your pages in order for GA to track the visitor across multiple domains.
I'm using the Universal Analytics instead of Classic.
The snippet is
(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-xxxxxxx-x', 'xxxx.com');
ga('send', 'pageview');
But the help pages I visited all referred to another kind of snippet. For example, this help page:
https://support.google.com/analytics/answer/2558867?hl=en&utm_id=ad
As a result, I don't know how to make changes to the above snippet to achieve what I want.
Is the difference in snippet code the result of using Universal vs Classic?
Enhanced Link attribution is not yet supported in UA (as are GDN integration/Demographics or Remarketings Lists via GA, even though the interface is already there). No clear timeline, but support is to come "soon".
Since Google plans a forced upgrade to UA for all accounts "soon" will hopefully be, ehm, sooner than later.
My event tracking isnt working on my Google analytic's. Below is the code that it gave me to insert into the webpage and below that is the snippet it told me to put. I am wanting to track the number of clicks onto a 'mailto' link from the website and I believe this is the best way to do it?
Can anyone tell me where its going wrong?
(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-37080107-2', 'promat-durasteel.com');
ga('send', 'pageview');
This is the snippet: (it wont let me put the opening tag on this forum for some reason, but it is there in the coding!
href="mailto:info#sharpfibre.com" onclick="_gaq.push(['_trackPageview, '/Direct-Email-Enquiry-Link-Clicked’]);">info#sharpfibre.com
Please help!
Thanks
As far as I can tell you are mixing two brands of Google Analytics - the new "Universal Analytics" and the , ehm, traditional asynchronous tracking code. Pushing values to the _gaq-Array will not help you since Universal Analytics does not use _gaq (and even if it would you are tracking a (virtual) pageview, not an event).
You'll have to use ga('send') on the click event. Documentation for event tracking with the new GA code is here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
hopefully someone can help me out.
So l have a google analytics experiment running. However when l set it up and click the "validate code" button l get this error:
No Google Analytics tracking code found.
For both the original, and the variation page.
The thing is, l DO have the google analytics code on the pages.
One thing to note is that my google analytics tracking code looks a little different than most.
It looks like this:
<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-xxxxxxx-1', 'mysite.com');
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');
</script>
Also it's important to note that the site is tracking visits properly in google analytics.
Can anyone help me out?
When I last checked (yesterday) Universal Analytics did not support (yet) content experiments (although it was announced support would be coming soon). I guess you opened a new GA account - new accounts are now set to Universal Analytics as default, you have to manually switch to the previous asynchronous version. However you cannot change this after you started tracking. IF this is a new account it might be feasible to lose the data already collected and start with a new account that set to the previous version.
Bottom line, you either have to wait with your test until support for content experiment is added or you start again with a new account (or you implement another account parallel to the current one and do your test from there, which to me sounds rather untidy).
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.