Thứ Ba, 18 tháng 12, 2012

Google Analytics API Investigation

In order to be able to show off some real time statistics we would like to be able to integrate with GA to give us some load type information.

Therefore we needed to investigate what sort of integration points Google Analytics provides. Luckily, it provides a javascript api which we can quite easily enable access to and query for various bits of data.

Some examples of this data are...

  • page visits
  • visitor continent
  • visitor city
  • visitor browsers
  • bounce rate
  • mobile device usage breakdowns

Google Analytics API

The GA API is basically what we need I believe. Google refer to this API as the GA CORE Reporting API.

It is basically broken down in to two different ares. Metrics and Dimensions.

Metrics are more quantitative and Dimensions more qualitative from what I can see at first glance.

Some of the metrics that they provide include those in the Session category:

  • ga:visits
  • ga:bounces
  • ga:entranceBounceRate
  • ga:visitBounceRate
  • ga:timeOnSite
  • ga:avgTimeOnSite

Some of the dimensions they provide include those in the Geo/Network category:

  • ga:continent
  • ga:subContinent
  • ga:country
  • ga:region
  • ga:metro
  • ga:city
  • ga:latitude
  • ga:longitude
  • ga:networkDomain
  • ga:networkLocation
And you can even do combinations of Metrics and Dimensions. The full reference is here: https://developers.google.com/analytics/devguides/reporting/core/dimsmets

PHP Integration
This API also provides a PHP integration interface.
For example in PHP you can do something like this to get the visits/source keyword data.


function queryCoreReportingApi() {
  $optParams = array(
      'dimensions' => 'ga:source,ga:keyword',
      'sort' => '-ga:visits,ga:source',
      'filters' => 'ga:medium==organic',
      'max-results' => '25');

  return $service->data_ga->get(
      TABLE_ID,
      '2010-01-01',
      '2010-01-15',
      'ga:visits',
      $optParams);
}
The API is quite plentiful and available to be called via Javascript (and Java) as well as PHP.

More documentation on the API from a developer point of view is available here:

https://developers.google.com/analytics/devguides/reporting/core/v3/coreDevguide

A good initial tutorial is available here:

https://developers.google.com/analytics/solutions/articles/hello-analytics-api

Other API Functions
There are many more API requests detailed in full here at
https://developers.google.com/analytics/devguides/reporting/core/v3/

API Quotas
General Analytics API quotas. These apply to both the Analytics APIs, i.e., Management API and Core Reporting API:

50,000 requests per project per day
10 queries per second (QPS) per IP
Quotas specific to Core Reporting API:

10,000 requests per profile per day
10 concurrent requests per profile

Conclusions
Basically from my investigations, there are a lot of metrics and dimensions that we can slice and dice from this API and use in our mobile capability site.

Không có nhận xét nào:

Đăng nhận xét

Học lập trình web căn bản với PHP

Bài 1: Các kiến thức căn bản Part 1:  https://jimmyvan88.blogspot.com/2012/05/can-ban-lap-trinh-web-voi-php-bai-1-cac.html Part 2:  https://...