Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture a website API traffic data with Google Analytics?

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?

like image 684
Saleh Al-Zaid Avatar asked Jul 01 '09 21:07

Saleh Al-Zaid


People also ask

Can Google Analytics track API calls?

After installing GoogleAnalyticsTracker into your project, you currently have two options to track your API calls: use the Tracker class or use the included ASP.NET MVC Action Filter. Here's a quick demo of using the Tracker class: 1 Tracker tracker = new Tracker("UA-XXXXXX-XX", "www.example.org"); 2 tracker.


2 Answers

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

like image 118
Ian Elliott Avatar answered Oct 31 '22 01:10

Ian Elliott


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.

like image 41
Demian Turner Avatar answered Oct 31 '22 02:10

Demian Turner