Limitations to Universal Analytics using External .js - google-analytics

What are the limiations to using Universal Analytics when placed into a .js file at the and can it result in a decrease of pageviews?
I am using the below UA code with Demographics "displayfeatures" enabled. I noticed traffic numbers declined, but I don't understand why I can't use an external .js. Any thoughts?
(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', 'INSERT UA CODE', 'INSERT SITENAME');
ga('require', 'displayfeatures');
ga('send', 'pageview');

Related

google analytics data is not showing up - Tracking not installed

I have a problem with google analytics for web.
I installed the analytics as following just before the closing head tag.
<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','//www.google-analytics.com/analytics.js','ga');
// ga('create', 'UA-xxxx23-1', 'auto');
ga('create', 'UA-xxxx56-2', 'auto');
ga('send', 'pageview');
</script>
It is weird because on one UA code (the one that is uncommented) no data is coming through ans the status of the tracking code is "tracker is not installed".
While the other property on another account the data is coming in correctly and the status is "Receiving data".
Any idea what this problem might be?
Turns out it was a time issue. The settings took around a day to kick in. The weird thing was that no realtime data was coming through. But now it works. If anyone has the same problem, just be patient.
If you are using multiple tracking ID then you have to pass the name field as the fourth argument in the create command.
ga('create', 'UA-XXXXX-Y', 'auto', 'myTracker');
And then you have to prefix the command name with the tracker name, followed by a dot.
ga('myTracker.send', 'pageview');
finally your code will look like this with double tracker
(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-xxxxxxxx-1', 'auto');
ga('create', 'UA-xxxxxxxx-1', 'auto', 'clientTracker');
ga('send', 'pageview');
ga('clientTracker.send', 'pageview');

Two analytics on one page

How can i put two GA codes on a site. I have this code:
(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-55738390-2', 'auto');
ga('create', 'UA-55738390-3', 'auto');
ga('send', 'pageview');
But the 2nd analytics code is not working. How can i fix this?
Your second tracker is overriding the first. It's not per se a problem to have multiple trackers per website, but you need multiple pageview (or other interaction) calls as well. Best way to do this is to use named trackers:
ga('create', 'UA-XXXX-Y', 'auto', 'tracker1');
ga('tracker1.send', 'pageview');
ga('create', 'UA-XXXX-Y', 'auto', 'tracker2');
ga('tracker2.send', 'pageview');
That way you can make interactions calls to specific trackers by prefixing the tracker name to the send method call.

Migrate pageTracker._trackPageview to Google Universal Analytics

Previously, I'm using traditional ga.js to track the visitors who click on a link.
donating
However, I'm just migrating to Google Universal 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-43627934-1', 'jstock.org');
ga('send', 'pageview');
</script>
What is the proper way to perform equivalent pageTracker._trackPageview?
ga('send', 'pageview', '/my-overridden-page?id=1');
Basically,
ga('send', 'pageview', 'page path');
Check out this link for migration examples:
https://developers.google.com/analytics/devguides/collection/upgrade/reference/gajs-analyticsjs

setting up dual google analytics on 1 website

Long story short, i have two website url's
www.somewebsiteA.com
www.somewebsiteB.com
Both domains point to the same server.
I created a google analytics account, and setup the two urls and have individual analytics keys for them.
Is this how i should paste the google code into the pages?
<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-12345678-1', 'somewebsiteA.com');
ga('send', 'pageview');
ga('create', 'UA-12345678-2', 'somewebsiteB.com');
ga('send', 'pageview');
</script>
I'm not entirely certain. It seems like somewebsiteB.com isnt working.
Thanks!
You need to give each one their own namespace:
<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-12345678-1', {'cookieDomain':'somewebsiteA.com', 'name':'siteA'});
ga('siteA.send', 'pageview');
ga('create', 'UA-12345678-2', {'cookieDomain':'somewebsiteB.com','name':'siteB'});
ga('siteB.send', 'pageview');
</script>

tidesdk google analytics implementation

hello i trying to incorporate google analytics through my application that i have created using tidesdk. i have the standard javascript includes that you would usually use in a website however. i cant seem to get this to work.
(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-41910717-2');
ga('send', 'pageview');
when i check the alalytics page i do not see any activity.
has anyone ever done this is it even possible.
Did you include the script tags? Also, are you placing it in between your head tags? If you use firebug or chrome developer tools, you should be able to see the analytics.js code loading. Do you see that?
<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-41910717-2');
ga('send', 'pageview');
</script>

Resources