Complete Web Upgrade: ga.js / dc.js to analytics.js


google analytics tracking snippetUpgrading to analytics.js and removing the ga.js snippets from your website.

Hello,
If you still using old Google Analytic trucking script you may “feel better” to know that you are not alone.
Do you feel better now? 😉
If you need more visitors and more sales then you may need more accurate STATS.

Tracking Code: The Analytics snippet is a small piece of JavaScript code that you paste into your pages. It activates Google Analytics tracking by inserting ga.js into the page. To use this on your pages, copy the code snippet below, replacing UA-XXXXX-X with your web property ID


It is not mandatory but at least little bit more pragmatic to change to use Google Analytic in more accurate and useful way.

Important Considerations
Important: 100% of Google Analytics properties have been transferred to Universal Analytics, and all new properties will be Universal Analytics properties. If you are still using a legacy tracking library (such as ga.js or versions 1.x of the mobile SDKs), you should strongly consider upgrading your tracking code to get all the benefits of Universal Analytics.

Google has been gradually rolling out Universal Analytics since 2012, and it has only been in the 2015 that the transfer from Classic to Universal Analytics was finished – BUT not for ALL, millions of sites still use old ga.js.

Still not convinced and thinking as follows:Google has been gradually rolling out Universal Analytics since 2012

  • It does not matter;
  • “Google do not know what they are doing” – The Winner of All Excuses!
  • it work good for us with old script;
  • I do not care;
  • and what ever else your creative mind will come up with…
  • 😉

Maybe simple understanding that it is “EASY” will help.
if you use standard not customized google Trucking script it Easy.

You do not need to even login to you analytic, looking for login info, browsing on multiple google account pages just copy templates which google provide

Caution: When upgrading to analytics.js, you must remove the basic ga.js snippets from your pages to avoid overcounting page-views in your reports.

(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-XXXX-Y‘, ‘auto’); // Replace with your property ID.
ga(‘send’, ‘pageview’);

QUESTION:
What is on Earth is the property ID?
ANSWER:
It is your unique ID assigned to your site in YOUR Google analytic as properties ID.
Do not worry about it, you can learn it later here

So Look at your code, template, skin all depend on waht kind of CMS you are using, or simple adding your script, code, html, php code.

Find at the bottom of your source code this part:

// IMPORTANT: Remove this code snippet when upgrading to analytics.js

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-XXXX-Y‘]);
_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);
})();

and copy where ever you see on this line shown in this format: UA-XXXX-Y
_gaq.push([‘_setAccount’, ‘UA-XXXX-Y‘]);

Example: for UN.org this line look like this:
_gaq.push([‘_setAccount’, ‘UA-4803886-1‘]);

Did you find it on your site?
You do not need to have login, it is simply view source code feature on most of the browsers.

Use this format: view-source:http://www.google.com/

Most difficult part of this little How to 😉
Once you find it and replace in your local text editor you need to upload your NEW edited Google script to your site.
For that you need login and need to know “What kind of CMS” you are using to upload to add it to right place.

Where to add NEW Google analytic script?
Google say: “right above closing tag, so your code should looks like this in source-view

 

var _gaq = _gaq || [];
_gaq.push([‘_setAccount’, ‘UA-4803886-1’]);
_gaq.push([‘_setDomainName’, ‘un.org’]);
_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);
})();

 

You also need to REMOVE your OLD script or it will mix up your STATS – Google say it not me “to avoid overcounting” I just repeat.

Conclusion.

If you are not “know it all” and may need proper STATs to work with you may consider to REMOVE old and add NEW to the proper place.
tip: old one you can usually find at the bottom of your page in source view.

If you have any issue with above let me know and i will help.

One more time very short:
find this:

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);

document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

try {

var pageTracker = _gat._getTracker(“UA-563315-1”);

pageTracker._trackPageview();

} catch(err) {}

 

copy: UA-563315-1 to new code like so:

(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-563315-1’, ‘auto’); // Replace with your property ID.
ga(‘send’, ‘pageview’);

and copy paste right before closing HEAD tag of ALL your pages you want to be tracked by Google Analytic’s.

or as Google say it:
“You need to add the tracking code to each page or screen from which you want to collect data.”

More info on How Set up Analytics tracking here

and here:
Improvements coming to the Google Analytics desktop UI

But real live not that easy sometimes and if you use ANY CUSTOMIZED features look here.

 

Covered:

How to add tracking code to the web?
What is Google Analytics properties?
How to upgrade from old to new Google Tracking code?
How to remove the basic ga.js snippets?
How to migrate from ga.js to analytics.js.
Have a nice day.

 

source:
https://developers.google.com/analytics/devguides/collection/upgrade/reference/gajs-analyticsjs
https://developers.google.com/analytics/upgrade