简体   繁体   English

谷歌分析服务器端跟踪

[英]google analytics serverside tracking

I'm trying to track the use of a mobile app that gets data from a datafeed written in php. 我正在尝试跟踪移动应用程序的使用,该应用程序从用PHP编写的数据源获取数据。 So I'm currently using this script. 所以我目前正在使用这个脚本。

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

however the important thing for me is to see the location of the users in google analytics. 但对我来说最重要的是在谷歌分析中查看用户的位置。 but this doesn't seem available. 但这似乎不可用。

has anybody been able to do this. 有人能做到这一点。

I create events as shown in the example on the website but the location of the visitor is always set to US, I believe that's just where my server is located. 我创建事件,如网站上的示例所示,但访问者的位置始终设置为美国,我相信这就是我的服务器所在的位置。

EDIT : My previous answer was a bit incorrect. 编辑 :我以前的回答有点不正确。 I've amended it. 我修改了它。

Typically, Google Analytics does not explicitly pass the location information on its own; 通常,Google Analytics不会自行明确传递位置信息; instead, it relies on the IP address of the user. 相反,它依赖于用户的IP地址。 ie, when Google Analytics "sends" data to Google Analytics, it makes an HTTP request to Google Analytics servers, and the requesting agent's IP address is used to determine the location. 也就是说,当Google Analytics向Google Analytics“发送”数据时,它向Google Analytics服务器发出HTTP请求,并使用请求代理的IP地址来确定位置。 (The same method is used to determine the user's browser, as the HTTP request sends the User-Agent header to Google's servers.) (同样的方法用于确定用户的浏览器,因为HTTP请求将User-Agent标头发送到Google的服务器。)

However, it turns out that in the official Google Analytics for Mobile library , there is a special parameter, utmip, you can pass that will emulate this behavior and give you proper geolocation reporting. 但是,事实证明,在官方Google Analytics for Mobile库中 ,有一个特殊参数utmip,您可以通过该参数来模拟此行为并为您提供正确的地理位置报告。 You can download that library to see how the implement it in PHP (it doesn't appear to pass the whole IP address.) 您可以下载该库以查看如何在PHP中实现它(它似乎不会传递整个IP地址。)

It appears that, in order to utilize this feature, you have to pass your account name as MO-XXX-X, not UA-XXX-X 看来,为了使用此功能,您必须将您的帐户名称传递为MO-XXX-X,而不是UA-XXX-X

Reminder: Change the prefix on your Analytics web property ID from UA- to MO- in the server-side snippets given below. 提醒:在下面给出的服务器端代码段中,将您的Google Analytics网络媒体资源ID上的前缀从UA-更改为MO-。 For example, if your web property ID is UA-12345-67, you would use MO-12345-67 in your server-side snippets. 例如,如果您的网络媒体资源ID为UA-12345-67,则可以在服务器端代码段中使用MO-12345-67。

Their PHP library also shows how you can spoof your User Agent to match that of the user so you can collect relevant browser information. 他们的PHP库还显示了如何欺骗用户代理以匹配用户代理,以便您可以收集相关的浏览器信息。

Check out http://code.google.com/p/php-ga , which is probably the most powerful server-side implementation library for GA. 查看http://code.google.com/p/php-ga ,这可能是GA最强大的服务器端实现库。 It does also solve this issue: http://code.google.com/p/php-ga/issues/detail?id=9 . 它也解决了这个问题: http//code.google.com/p/php-ga/issues/detail?id = 9

I have tweaked the code google supplies to try sending the IP address of the requesting user, so something like: 我已经调整了代码google供应以尝试发送请求用户的IP地址,所以类似于:

// Construct the gif hit url.
string utmUrl = utmGifLocation + "?" +
    "utmwv=" + Version +
    "&utmn=" + GetRandomNumber() +
    "&utmhn=" + HttpUtility.UrlEncode(domainName) +
    "&utmr=" + HttpUtility.UrlEncode(documentReferer) +
    "&utmp=" + HttpUtility.UrlEncode(documentPath) +
    "&utmac=" + account +
    "&utmcc=__utma%3D999.999.999.999.999.1%3B" +
    "&utmvid=" + visitorId +
    //"&utmip=" + GetIP(Request.ServerVariables["REMOTE_ADDR"]);
    "&utmip=" + GetIP(Request.UserHostAddress);

SendRequestToGoogleAnalytics(utmUrl);

But in Google Analytics I am only ever seeing the location of the hosted server in Germany rather than the end user. 但在谷歌分析中,我只看到托管服务器在德国而不是最终用户的位置。

Does anyone know if utmip is still working/supported? 有谁知道utmip是否仍在工作/支持? It seems to be just using the IP address of where the above code is running rather than that of the requestor which I am passing. 它似乎只是使用上面代码运行的IP地址而不是我传递的请求者的IP地址。

(PS - I have checked and am using the correct MO-???? tracking id) (PS - 我已经检查过并使用正确的MO - ????跟踪ID)

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

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