google analytics for responsive design - google-analytics

I've started with Google Analytics this year so I'm still learning a lot.
I have stumbled onto this article: http://www.smashingmagazine.com/2014/08/28/responsive-web-design-google-analytics/
And I thought it really interesting but I'm struggling. I implemented it for this website:
http://conversionadvantage.com/
but now my GA stopped tracking; telling me I don't have the code on my website.
Can someone give me pointers please as what I could have done wrong? My code 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-xxxxxxxx-x', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview', {
'dimension2': WURFL.complete_device_name,
'dimension4': WURFL.form_factor,
'dimension3': WURFL.is_mobile
});
</script>
I just have different dimensions since nr 1 is taken. The developer also added
<script type="text/javascript" src="//wurfl.io/wurfl.js"></script>
So any thoughts for a newbie?
Thanks in advance!

Wurfl is a script for device detection that is used to determine device name etc. So you need to include this before your pageview calls else the variables will not be set (which will result in a javascript error, hence GA will not track anything).
Device Name and "is_mobile" are not necessary since this is already tracked by Google Analytics.

Related

Google Tag Manager conflict because in my HTML I have an element with name="ga" and id="ga"?

Is it possible that my GTM code is failing because of some conflict with Google Analytics and an HTML element I have with <input id="ga" name="ga">?
My tag for Google Analytics is:
<style>.async-hide { opacity: 0 !important} </style>
<script>(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
(a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
})(window,document.documentElement,'async-hide','dataLayer',4000,
{'GTM-XXXXXXXXXXXXX':true});</script>
<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-XXXXXXXXXXXX', 'auto');
ga('send', 'pageview');
</script>
Should I change the 'ga' to something else and it'd still work but without the conflicts?
I found this answer but I'm not sure if it's the same issue, however I'll try to do it (the reason why I don't try and test it by myself is because it will take a lot of time until the marketing team can check it).
Changing the Global GA Object in google tag manager
Yes, it is certainly a cause.
The error it will generate is:
Uncaught TypeError: ga is not a function
You can see it in this JSFiddle (see error in console).
As the answer by Michele Pisani says, it does conflict, and it can be solved with this answer (changing the global function name):
Changing the Global GA Object in google tag manager

Which tracking code am I supposed to use? The one with window.dataLayer or window.ga?

I've just started using GA (after I took a long vacation from it). It seems I'm missing something obvious/simple here.
I don't understand why in my analytics account / admin / property / tracking code they tell me to put this into <header> :
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-blahblah-1');
</script>
While in their docs they tell me to use this:
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
Src: https://developers.google.com/analytics/devguides/collection/analyticsjs/#the_javascript_tracking_snippet
These are completely different scripts o.O Additionally, the examples here https://developers.google.com/analytics/devguides/collection/analyticsjs/how-analyticsjs-works just don't work with the first snippet, because ga is undefined.
Is this because they have different API versions? Then... why isn't this explained somewhere o.O
I'm asking because I get
unreachable code after return statement
In the console, on this javascript: https://www.googletagmanager.com/gtag/js?id=UA-my-tracking-code-1:formatted
I also found this answer:
Why is tracking code generated for my site different than what is in the documentation?
But it's from 2015, and the js snippets are again different, so I guess I can't use it as a reference.
All of this is just weird, this is why there are so many "o.O" in my question, please forgive me :)
This is definitely slightly confusing, but you're seeing the difference between analytics.js and gtag.js. You can learn more about the differences between them and/or migrating to gtag.js here.
Hope this helps!

Google analytics is included in the header, but doesn't work

So I am working on nosleeplessnights.com and have google analytics added to the header. For some reason it doesn't work and tag managers says the script is missing.
<script type="text/javascript">
(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.nosleeplessnights.com/analytics.js','ga');
ga('create', 'UA-35194122-1', 'auto');
ga('send', 'pageview');
</script>
"Missing analytics.js script" Any idea what I'm doing wrong here?
In your snippet you re asking ga to look for the analytics.js script at https://nosleeplessnights.com/analytics.js, try replacing this url in your snippet with the official one : https://www.google-analytics.com/analytics.js
we swapped to gtags which worked. not a real solution, but still - it worked.

Do I need any library before adding google analytics to my website?

I have got the google analytics code which is written below
<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', 'xx-xxxxxx-x', 'auto');
ga('send', 'pageview');
</script>
I searched on net a lot but could not find my answer. Do I need any library before adding this code to my web just like we add jQuery library before adding jQuery script.
You can just add that code to your website, place it just before the </head> tag. No extra libraries are needed.
You can just paste the code in right before the </head> tag
Set up the web tracking code:
https://support.google.com/analytics/answer/1008080?hl=en

Google Analytic tracking code not working / not installed.

The code is visible in "view page source" but GA says "Tracking Not installed". the website is validated for errors with html5.validator.nu and http://validator.w3.org and there is no error. But still couldn't see the "Tracking Installed" not the realtime activity.
<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-40983367-1', 'star-business-directory.com');
ga('send', 'pageview'); </script>
here is my site: star-business-directory.com
The code is implemented correctly. Please check that your property is properly configured to receive Universal Analytics data. If not, then it will not work.
Regarding Universal or Classic Analytics support, you can find this information if you look in the administrative overview, under "Property".
If you look at the top, you can see a property which does NOT have support for Universal Analytics. Please upgrade. If you DO have support for it, you should see a green check sign.
Also, are you looking into the correct account and property? You should be seeing real-time data for the property UA-40983367-1.
The code on your site looks like this:
<script> <!-- type="text/javascript" language="javascript"> -->
(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-40983367-1', 'star-business-directory.com');
ga('send', 'pageview');
</script>
I believe the problem you are having issues with the HTML comment inside the script tag. Try and remove the following code.
<!-- type="text/javascript" language="javascript"> -->

Resources