44

Just wondering if there's any out of the box solution for this, I am not too familiar with the analytics api maybe I can write some simple js that updates analytics before going to my service etc. -- otherwise I am going to have to stick to the good old 'store records in the database'.

Any help appreciated!

JohnIdol
  • 48,899
  • 61
  • 158
  • 242

8 Answers8

14

I think Keen IO would be a great fit here. It's an API-only analytics platform (meaning that you both send data and consume analysis via a REST API).

Full disclosure: I'm the CEO. I'm not writing this answer to self-promote, but because honestly, our product was purpose-built for use cases like yours.

Several Keen IO users are API companies who use it to do analytics on how their users are using their APIs.

At the risk of being a bit too meta: We use the Keen IO API internally to collect events and perform analysis of how our customers use the Keen IO API externally, and by way of example, our two-event data model looks something like this:*

  • analysis_call
    • request (object)
      • client_library_version (string)
      • API_version (number)
      • query_parameters (key-value object)
      • post_parameters (key-value object)
      • origin_ip (ip address)
      • URI (string)
    • num_events (integer)
    • includes_geolocation (boolean)
    • user_agent (string)
    • response (object)
      • HTTP_code (number)
      • latency (number)
      • headers (object)
      • body (object: the actual full JSON response object, if under 1K)
  • events_added_call
    • client_library_version (string)
    • API_version (number)
    • origin_ip (ip address)
    • request (object)
    • response (object: the actual full JSON response object)

*We actually use a lot more properties than this, I've stripped them out to make this more clear

Kyle Wild
  • 8,845
  • 2
  • 36
  • 36
12

There seem to be a few solutions out there, though they mostly seem to involve changing your API architecture.

You could potentially use one of the Google Analytics server-side tracking libraries.

I see you're using AppEngine; I also run an API using AppEngine, and recently have been playing with using a Google Analytics Library for App Engine. It's not a perfect solution, but there's a decent amount of quality data.

Be warned that Google Analytics data modeling really isn't that analagous to that of an API; depending on your API, the notion of a "visit" is somewhat meaningless.

Yahel
  • 37,023
  • 22
  • 103
  • 153
  • 1
    With 3scale, there's no need to change you API infrastructure - it works with a code plugin you drop into your system and you can report traffic synchronously or asynchronously. – steve Apr 11 '12 at 04:59
9

Well, you could use...google analytics

On the server, in a REST API handler function, make an HTTP GET request to http://www.google-analytics.com/__utm.gif with the right parameters, and you're done. Preferably async.

https://developers.google.com/analytics/resources/concepts/gaConceptsTrackingOverview

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
5

You could do this now with GA using the new Measurement Protocol the is currently in public beta.

Andre Lackmann
  • 686
  • 6
  • 14
  • Anyone use/try this approach? It's been 2.5 years since the post, I assume this is out of beta now. Just wanted feedback on its use for this case. – David Feb 22 '16 at 21:19
  • @David, measurement protocol is working fine for similar use cases ( I have troubling joining sessions that are partly web and partly measured serverside, but that is not a problem here). – Eike Pierstorff Apr 26 '16 at 07:31
2

I think what you're looking for is something like apigee: http://apigee.com

jverdi
  • 1,506
  • 13
  • 14
1

I think this solution might be a really good choice if you're interested in specifically tracking REST calls: http://apianalytics.com It looks like it has everything you'd need. A bit like the Mixpanel of APIs.

Disclaimer: A good friend of mine has built this

API_sheriff_orlie
  • 1,223
  • 10
  • 18
1

I don't think google analytics can track rest calls, because it's activated by a snippet of JavaScript that you embed in your HTML.

To view the logs, you can go to the appengine console, choose your application and select Logs.

To access your logs programmatically, you've to download them (with Java, with Python), but it seems that up to now you can't do it within your app engine, so you've to do it either on your workstation or maybe on an Amazon EC2 (maybe micro) instance.

On the other hand, if you decide to store records in the DataStore, do the update within a task queue, so you don't slow down your API (Task Queues with Java, Task Queues with Python).

stivlo
  • 83,644
  • 31
  • 142
  • 199
0

What information are you looking for specifically? You might be able to get what you need from http access logs.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57