问题
How do i use both for an existing google acc that has been using ga.js...i cant seem to find the right documentation. anyone with experience in this?
回答1:
To expound what Pete says.
Create a new web property for analytics.js - In your google analytics account, go to Admin section and Create a new web property - Creating a new property will provide you with a new Tracking ID
Dual Tag - Add both your ga.js and analytics.js tracking code. Note that they must not share the same UA code. Your codes may look something like below:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-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);
})();
</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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxx-z', 'yoursite.com');
ga('send', 'pageview');
</script>
回答2:
Existing ga.js users should create a new web property for analytics.js and dual tag their site. It is perfectly safe to include both ga.js and analytics.js snippets on the same page.
see https://developers.google.com/analytics/devguides/collection/analyticsjs/
回答3:
The ga.js code will be obsolete in a couple of years, i suggest you migrate to Universal analytics. The initial phase has probably started by non.
来源:https://stackoverflow.com/questions/17036884/how-to-use-both-ga-js-and-analytics-js