Google Analytics code snippet incorrect? - google-analytics

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.

Related

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.

google analytics re-marketing code not validated

So I've added this additional line of code to our Google Analytics tracking code so it supports display and remarketing campaigns as outlined by this help article https://support.google.com/analytics/answer/2444872?hl=en
However, within analytics, it still keeps showing that it's not been added. It's definitely in there and the rest of the tracking is working fine.
I am using Universal Analytics (analytics.js) and have added that one line to the existing code as shown
(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-53957342-1', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
Has anyone come across the same issue?
Any tips or advice would be helpful!
Thanks
Activation of this feature may take 48 hours. I recently did the same and added that code to my site and even after click on Validate, it would show as not active until two days later! With most things related to GA, you just need a little patience (usually). If by 48 or 60 hours later the code is still not active, then if you believe you have done everything correctly to implement it, then skip validation.
Hope this helps.

Google Analytics OnClick Event

I'm having some issues with my Google Analytics onClick events. I obviously have the google analytics code in the header:
<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-41953273-1', 'getafreephone.net');
ga('send', 'pageview');
</script>
Now my onclick on the hyperlink looks like the following:
<span class="calltoaction"><img class='alignleft_action' src='images/Forward.png' alt=''/>Click here to sign up today and receive your free iPhone!</span>
However, in Google Analytics it's not picking this up at all (it's picking all page-views etc up, just not events).
Any help will be appreciated, thanks.
I'm going to imagine after you click on the link, you have a error in the Javascript console.
The analytics tracking code you have seems quite old, and doesn't have the _gaq variable available to use. I would try upgrading the tracking code that is available t at https://support.google.com/analytics/answer/1008080?hl=en&ref_topic=1008079 which will give you access to _gaq.push().
Also take a look at the Google Analytics Debugger which logs a lot of useful information to the Javascript console and can help troubleshoot these issues instead of waiting 24 hours.

My Event Tracking inst working?

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

google analytics experiments "No Google Analytics tracking code found."?

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).

Resources