如何使用谷歌分析跟踪Ajax请求?

时间:2022-05-15 14:32:33

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).

我正在尝试使用谷歌分析来跟踪我的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.

但是它不能工作(它可以工作,但是它不能跟踪所有的请求)。我得到的数字远远低于我的请求数量。

4 个解决方案

#1


3  

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

#2


2  

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); 
});

#3


1  

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

#4


0  

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请求的人有用。

#1


3  

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

#2


2  

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); 
});

#3


1  

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

#4


0  

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请求的人有用。