简体   繁体   English

如何使用Google Analytics(分析)跟踪Ajax请求?

[英]How to track Ajax requests using Google Analytics?

I'm trying to use Google Analytics to track any Ajax request made by my web application (in my case built on ExtJS, but it doesn't matter right now). 我正在尝试使用Google Analytics(分析)来跟踪我的Web应用程序发出的任何Ajax请求(在我的情况下是基于ExtJS构建的,但现在没有关系)。

I wrote few lines of code to track all Ajax requests: 我写了几行代码来跟踪所有Ajax请求:

Ext.Ajax.on('requestcomplete', function(connection, options) {
    pageTracker._trackPageview('/'+options.url);
});

but it doesn't work (it kind of works, but it doesn't track all the request). 但它不起作用(它可以起作用,但不能跟踪所有请求)。 The numbers I'm getting are much lower than the number of my requests. 我得到的数量远远少于我的要求数量。

In the latest (Async) version of ga code, use:- 在ga代码的最新(异步)版本中,使用:-

_gaq.push(['_trackPageview', '/home/landingPage']);

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._trackPageview

it could be that you're using the old tracking code, if so your code should look like: 可能是您使用的是旧的跟踪代码,如果这样,您的代码应类似于:

Ext.Ajax.on('requestcomplete', function(connection, options) {
    urchinTracker('/'+options.url); 
});

Note that the Async Snippet syntax was changed 请注意,异步代码段语法已更改

From this OLD format: 使用此旧格式:

    _gaq.push(['_setAccount', 'UA-12345-1']);
    _gaq.push(['_trackPageview']);
    _gaq.push(['_trackPageLoadTime']);

You should use this: 您应该使用此:

Overriding Default Values: https://developers.google.com/analytics/devguides/collection/analyticsjs/pages 覆盖默认值: https//developers.google.com/analytics/devguides/collection/analyticsjs/pages

ga('send', 'pageview', {
  'page': '/my-overridden-page?id=1',
  'title': 'my overridden page'
});

Or for tracking events: 或用于跟踪事件:

ga('send', 'event', 'button', 'click', 'nav buttons', 4);

Where: 哪里:

button is the category 按钮是类别

click is the action 点击就是行动

nav buttons is the label 导航按钮是标签

4 is the value 值是4

https://developers.google.com/analytics/devguides/collection/analyticsjs/events https://developers.google.com/analytics/devguides/collection/analyticsjs/events

After rechecking whether the code was properly installed it turned out that it was not. 重新检查代码是否正确安装后,事实证明并非如此。 Sorry for my mistake, hopefully this snippet will be useful for somebody who is looking for a way of tracking Ajax requests using ExtJS. 抱歉,我的错误,对于希望使用ExtJS跟踪Ajax请求的人来说,此代码段将很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM