Analytics.js JavaScript code Snippets are a new way to measure how users interact with your site. It is similar to the previous tracking code ga.js, but provides greater flexibility for developers to customize the implementation.
The Analytics.js code snippet is part of the Universal Analytics ( currently in Beta) phase. New users should use Analytics.js. Existing Ga.js users should create new network media resources for Analytics.js and make two code implementations in their sites. Adding Ga.js and Analytics.js code snippets on the same page does not have any security issues.
Quick start of tracking code
To start using the Analytics.js tracking site, paste the following JavaScript snippet in front of the end tag in the site template page . The UA-XXXX-Y
parameter must be replaced with the network Media Resource ID of the Google Network media resource that you want to track.
<!--Google Analytics--><script> (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 '), GA (' send ', ' PageView ');</script><!--End Google Analytics--
The code runs asynchronously loads the Google Analytics tracking code onto the page and then UA-XXXX-Y
creates a tracker object for the network media resource that you specify in the parameters. Finally, it records web browsing in Google Analytics for pages that run scripts.
Reference point