Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google analytics serverside tracking

I'm trying to track the use of a mobile app that gets data from a datafeed written in php. So I'm currently using this script.

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.

like image 637
Mars Avatar asked Aug 20 '11 07:08

Mars


2 Answers

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; instead, it relies on the IP address of the user. 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. (The same method is used to determine the user's browser, as the HTTP request sends the User-Agent header to Google's servers.)

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. You can download that library to see how the implement it in PHP (it doesn't appear to pass the whole IP address.)

It appears that, in order to utilize this feature, you have to pass your account name as MO-XXX-X, not UA-XXX-X

Reminder: Change the prefix on your Analytics web property ID from UA- to MO- in the server-side snippets given below. For example, if your web property ID is UA-12345-67, you would use MO-12345-67 in your server-side snippets.

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.

like image 80
Yahel Avatar answered Oct 08 '22 11:10

Yahel


Check out http://code.google.com/p/php-ga, which is probably the most powerful server-side implementation library for GA. It does also solve this issue: http://code.google.com/p/php-ga/issues/detail?id=9.

like image 5
Thomas Bachem Avatar answered Oct 08 '22 13:10

Thomas Bachem