Reputation: 75
We've previously used Analytics with trackPageview like this:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1']);
_gaq.push(['_trackPageview', '/Step1']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
However, in the New Analytics, the script isn't formatted the same way and I'm a bit confused about how/where I should add back in the trackPageview 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-1', 'page.com');
ga('send', 'pageview');
So where in the new code should I put the "_gaq.push(['_trackPageview', '/Step1']);" and in which format?
Upvotes: 3
Views: 559
Reputation: 1862
I'd start by reading the documentation that is available for the new analytics.js library since it explains all of this.
Anyways, it looks like you're trying to override the default value for page views and set your own path. There is no _gaq or _trackPageview with the new analytics.js library. Instead, the equivalent code would be:
ga('create', 'UA-1');
ga('send', 'pageview', '/Step1');
Upvotes: 3