Vu Nguyen
Vu Nguyen

Reputation: 215

How to track API calls on my ruby on rails app using google analytics?

I created an API for external applications to log in or make specific web calls using OAuth. What I'm looking for is a way to track the number of times these API calls are being used.

Is there an option for me?

Upvotes: 3

Views: 825

Answers (2)

Matt
Matt

Reputation: 5168

You could send the events with the measurement protocol.

require "net/http"
require "uri"

uri = URI.parse("http://www.google-analytics.com/collect")

Net::HTTP.post_form(uri, {"v" => "1",
                          "tid" => "UA-XXXX-1",
                          "cid" => "555",
                          "t" => "event",
                          "ec" => "API",
                          "ea" => "request",
                          "el" => "data/get",
                          "ev" => "5"})

Upvotes: 5

Andy Waite
Andy Waite

Reputation: 11076

I believe you can do this with Google Events:

https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

There are various Ruby libraries for interacting with GA.

Upvotes: -2

Related Questions