如何使用Google Analytics捕获网站API流量数据?

时间:2021-02-04 15:13:49

I have a website where most of the traffic comes from the API (http://untiny.com/api/). I use Google Analytics to collect traffic data, however, the statistics do not include the API traffic because I couldn't include the Google Analytics javascript code into the API pages, and including it will affect the API results. (example: http://untiny.com/api/1.0/extract/?url=tinyurl.com/123).

我有一个网站,其中大部分流量来自API(http://untiny.com/api/)。我使用Google Analytics收集流量数据,但统计信息不包含API流量,因为我无法将Google Analytics javascript代码包含在API页面中,并且包含它会影响API结果。 (例如:http://untiny.com/api/1.0/extract/?url =tinyurl.com/123)。

The solution might be executing the javascript using a javascript engine. I searched * and found javascript engines/interpreters for Java and C, but I couldn't find one for PHP except an old one "J4P5" http://j4p5.sourceforge.net/index.php

解决方案可能是使用javascript引擎执行javascript。我搜索了*并找到了Java和C的javascript引擎/解释器,但除了旧的“J4P5”之外我找不到一个用于PHP的http://j4p5.sourceforge.net/index.php

The question: is using a javascript engine will solve the problem? or is there another why to include the API traffic to Google Analytics?

问题是:使用javascript引擎会解决问题吗?或者还有其他原因要将API流量包含在Google Analytics中吗?

4 个解决方案

#1


A simple problem with this in general is that any data you get could be very misleading.

一般来说,一个简单的问题是,您获得的任何数据都可能会产生误导。

A lot of the time it is probably other servers making calls to your server. When this is true the location of the server in no way represents to location of the people using it, the user agent will be fake, and you can't tell how many different individuals are actually using the service. There's no referrers and if there is they're probably fake... etc. Not many stats in this case are useful at all.

很多时候可能是其他服务器调用您的服务器。如果这是真的,服务器的位置绝不代表使用它的人的位置,用户代理将是假的,并且您无法分辨有多少不同的人实际使用该服务。没有推荐人,如果有他们可能是假的......等等。在这种情况下,没有多少统计数据是有用的。

Perhaps make a PHP back end that logs IP and other header information, that's really all you can do to. You'll at least be able to track total calls to the API, and where they're made from (although again, probably from servers but you can tell which servers).

也许制作一个记录IP和其他标题信息的PHP后端,这真的是你所能做的。您至少能够跟踪对API的总呼叫,以及它们的来源(尽管可能来自服务器,但您可以告诉哪些服务器)。

#2


I spent ages researching this and finally found an open source project that seems perfect, though totally under the radar.

我花了很多年的时间研究这个并最终找到了一个看起来很完美的开源项目,尽管完全不受关注。

http://code.google.com/p/serversidegoogleanalytics/

Will report back on results.

将报告结果。

#3


you would likely have to emulate all http calls on the server side with whatever programming language you are using..... This will not give you information on who is using it though, unless untiny is providing client info through some kind of header.

您可能不得不使用您正在使用的任何编程语言模拟服务器端的所有http调用.....这不会向您提供有关谁正在使用它的信息,除非通过某种标题提供客户信息。

if you want to include it purely for statistical purposes, you could try using curl (if using php) to access the gif file if you detect untiny on the server side

如果你想纯粹为了统计目的而包含它,你可以尝试使用curl(如果使用php)来访问gif文件,如果你在服务器端检测到uniny

http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters

#4


You can't easily do this as the Javascript based Google Analytics script will not be run by the end user (unless of course, they are including your API output exactly on their display to the end user: which would negate the need for a fully fledged API [you could just offer an iframable code], pose possible security risks and possibly run foul of browser cross-domain javascript checks).

你不能轻易做到这一点,因为最终用户不会运行基于Javascript的Google Analytics脚本(除非他们将API输出完全包含在他们的显示屏上给最终用户:否则将无法完全满足成熟的API [你可能只提供一个iframable代码],提出可能的安全风险,并可能与浏览器跨域javascript检查有误)。

Your best solution would be either to use server side analytics (such as Apache or IIS's server logs with Analog, Webalizer or Awstats) or - since the most information you would be getting from an API call would be useragent, request and IP address - just log that information in a database when the API is called.

您最好的解决方案是使用服务器端分析(例如Apache或IIS的服务器日志与Analog,Webalizer或Awstats)或 - 因为您从API调用获得的大部分信息将是useragent,请求和IP地址 - 只是调用API时,在数据库中记录该信息。

#1


A simple problem with this in general is that any data you get could be very misleading.

一般来说,一个简单的问题是,您获得的任何数据都可能会产生误导。

A lot of the time it is probably other servers making calls to your server. When this is true the location of the server in no way represents to location of the people using it, the user agent will be fake, and you can't tell how many different individuals are actually using the service. There's no referrers and if there is they're probably fake... etc. Not many stats in this case are useful at all.

很多时候可能是其他服务器调用您的服务器。如果这是真的,服务器的位置绝不代表使用它的人的位置,用户代理将是假的,并且您无法分辨有多少不同的人实际使用该服务。没有推荐人,如果有他们可能是假的......等等。在这种情况下,没有多少统计数据是有用的。

Perhaps make a PHP back end that logs IP and other header information, that's really all you can do to. You'll at least be able to track total calls to the API, and where they're made from (although again, probably from servers but you can tell which servers).

也许制作一个记录IP和其他标题信息的PHP后端,这真的是你所能做的。您至少能够跟踪对API的总呼叫,以及它们的来源(尽管可能来自服务器,但您可以告诉哪些服务器)。

#2


I spent ages researching this and finally found an open source project that seems perfect, though totally under the radar.

我花了很多年的时间研究这个并最终找到了一个看起来很完美的开源项目,尽管完全不受关注。

http://code.google.com/p/serversidegoogleanalytics/

Will report back on results.

将报告结果。

#3


you would likely have to emulate all http calls on the server side with whatever programming language you are using..... This will not give you information on who is using it though, unless untiny is providing client info through some kind of header.

您可能不得不使用您正在使用的任何编程语言模拟服务器端的所有http调用.....这不会向您提供有关谁正在使用它的信息,除非通过某种标题提供客户信息。

if you want to include it purely for statistical purposes, you could try using curl (if using php) to access the gif file if you detect untiny on the server side

如果你想纯粹为了统计目的而包含它,你可以尝试使用curl(如果使用php)来访问gif文件,如果你在服务器端检测到uniny

http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters

#4


You can't easily do this as the Javascript based Google Analytics script will not be run by the end user (unless of course, they are including your API output exactly on their display to the end user: which would negate the need for a fully fledged API [you could just offer an iframable code], pose possible security risks and possibly run foul of browser cross-domain javascript checks).

你不能轻易做到这一点,因为最终用户不会运行基于Javascript的Google Analytics脚本(除非他们将API输出完全包含在他们的显示屏上给最终用户:否则将无法完全满足成熟的API [你可能只提供一个iframable代码],提出可能的安全风险,并可能与浏览器跨域javascript检查有误)。

Your best solution would be either to use server side analytics (such as Apache or IIS's server logs with Analog, Webalizer or Awstats) or - since the most information you would be getting from an API call would be useragent, request and IP address - just log that information in a database when the API is called.

您最好的解决方案是使用服务器端分析(例如Apache或IIS的服务器日志与Analog,Webalizer或Awstats)或 - 因为您从API调用获得的大部分信息将是useragent,请求和IP地址 - 只是调用API时,在数据库中记录该信息。