Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.89 KB

README.md

File metadata and controls

39 lines (30 loc) · 1.89 KB

GoogleAnalyticsRequester

Wrapper for querying GoogleAnalytics API, getting the results and returning as JSON with a bit of post processing.

It makes use of the Google APIs Client Library for PHP.

Install

  1. Clone the repo
git clone https://github.com/XaviArnaus/GoogleAnalyticsRequester.git
  1. Move to the folder
cd GoogleAnalyticsRequester
  1. Run composer install on it
composer install
  1. Place the service-account-credentials.json in the root of the project, following the steps in Google Reporting API authorisation.
  2. Start making requests to the script. You can fire the PHP interpreter or point a Web Browser to this script.

API

This is a call to a script with GET parameters that returns an array of values as a JSON. That's all.

The following are the available parameters and their defaults:

GET parameter possible values defaults comment
metrics string ga:users Which metrics to query. Can be a list of comma separated metrics.
from string 14daysAgo Data range start for queried metrics
to string today Data range end for queried metrics
dimensions string ga:date Which dimensions are used to divide the queried metrics. ga:date means that you'll get a row per day.
sort string -ga:date Wich dimension will be used to sort the queried metrics. Note that the minus in front means DESC order.
simplify int 0 Discards rows from result, returning only one every n defined. A 0 means no simplification done. Useful for huge resultsets.

For an exhaustive reference of metrics and dimensions visit the official documentation and play with the Query Explorer