I inserted Google Analytics with the following code snipped.
<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/analytics.js','ga');
ga('create', 'UA-xyz-1', 'xyz');
ga('send', 'pageview');
</script>
Now I want to track a specific page in my ajax application. The following link describes how to push events to google analytics:
If I try to execute the following mand, I just get the error saying "_gaq" is not defined.
_gaq.push(['_trackPageview', 'myPage']);
Am I doing something wrong here or are the docs are outdated?
Edit: So there seems to be a new API. What would be the equivalent to:
_gaq.push(['_trackPageview', 'myPage']);
Would this be the same mand in the new API?
ga('send', 'pageview', 'myPage);
I inserted Google Analytics with the following code snipped.
<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./analytics.js','ga');
ga('create', 'UA-xyz-1', 'xyz.');
ga('send', 'pageview');
</script>
Now I want to track a specific page in my ajax application. The following link describes how to push events to google analytics:
https://developers.google./analytics/devguides/collection/gajs/eventTrackerGuide
If I try to execute the following mand, I just get the error saying "_gaq" is not defined.
_gaq.push(['_trackPageview', 'myPage']);
Am I doing something wrong here or are the docs are outdated?
Edit: So there seems to be a new API. What would be the equivalent to:
_gaq.push(['_trackPageview', 'myPage']);
Would this be the same mand in the new API?
ga('send', 'pageview', 'myPage);
Share
Improve this question
edited Dec 29, 2013 at 1:49
Kara
6,22616 gold badges53 silver badges58 bronze badges
asked Oct 3, 2013 at 22:34
janjan
4,0759 gold badges42 silver badges81 bronze badges
3
- This question appears to be off-topic because it is about Google Analytics which belongs at Pro Webmasters – John Conde Commented Oct 4, 2013 at 11:51
- @JohnConde - please see meta.stackexchange./questions/199101/… – MisterPhilip Commented Oct 4, 2013 at 20:40
- @MisterPhilip Thanks for the heads up. I'll keep on eye on that to see what es of it. – John Conde Commented Oct 4, 2013 at 20:44
3 Answers
Reset to default 6You're mixing the new analytics.js with the old async ga.js. Use analytics.js (Universal Analytics) event tracking documentation instead.
This is actually the code that samples the variable is not defined _gaq, reviewing the Analitycs page I see that the code is as follows:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_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./ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
Check the block of code and make sure that all is well implemented
Jan, I believe the pageview request is already in the snippet you mentioned:
ga('send', 'pageview');
Just make sure you the line above this -- you need to make sure that domain and Analytics account ID is specified:
ga('create', 'UA-123456-1', 'yourdomain.');
Looking at your code, it seems that you are using new Universal Analytics library, so _gaq.push mands won't work anymore. When you refer to documentation, always double check you looking at Analytics.js section (link).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745135689a4613187.html
评论列表(0条)