I have added to my html page the standard latest snippet to get google analytics to work:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push([开发者_运维问答'_setAccount', 'UA-15080849-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'http://www.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
</script>
</body>
</html>
Now looking at the official 'event tracking guide' google says:
Add a snippet such as:
pageTracker._trackEvent('Videos', 'Play', 'Gone With the Wind');
where is pageTracker coming from? Is it a global object in ga.js
? If it is, why does google not tell me that they run a risk of breaking some script?
You are using the async version of GA.
So your event tracking code should use that syntax. Instead of pageTracker._trackEvent('Videos', 'Play', 'Gone With the Wind');
, you will want something like _gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
Also, you can see more about the tracking method here (I can't post a second link yet):
code.google.com/apis/analytics/docs/gaJS/gaJSApiEventTracking.html
Does this help?
The migration guide for async analytics describes how to do event tracking asynchronously: http://code.google.com/apis/analytics/docs/tracking/asyncMigrationExamples.html#EventTracking
pageTracker is the global that most people use when using the traditional GA syntax. You don't need to use it for asynchronous GA. Instead you want:
_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);
精彩评论