views:

679

answers:

4

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

The solution might be executing the javascript using a javascript engine. I searched stackoverflow 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

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

+1  A: 

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.

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

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

Jason
here is a tut on how to request header only for the gif file http://icfun.blogspot.com/2008/07/php-get-server-response-header-by.html, hopefully cutting down the traffic from analytics to your server by not grabbing the contents of the gif file itself.
Jason
another person trying to do server side analytics :)http://groups.google.com/group/analytics-help-tracking/browse_frm/thread/686570f10449a807/e891d4dd5ddadbda
Jason
A: 

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

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.

Richy C.
+2  A: 

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

Ian Elliott
+1  A: 

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.

demianturner
yep, serversidegoogleanalytics works well, give it a try.
demianturner