A blend of programming and seo

Posts from — May 2009

Free php library for the google analytics API

Here is a list of other services that google supports using this same protocol:

Application Service name
Calendar Data API cl
Google Base Data API gbase
Blogger Data API blogger
Contacts Data API cp
Documents List Data API writely
Picasa Web Albums Data API lh2
Google Apps Provisioning API apps
Spreadsheets Data API wise
YouTube Data API youtube
Google analytics analytics

Login

Google uses something called the oauth protocol. It’s more secure than basic authentication because it encrypts your datastream. (Twitter currently uses basic authentication for API access, but will also support oath at some point in the future).

From the oath website:

“The Initiative for Open Authentication (OATH) is a collaborative effort of IT industry leaders aimed at providing a reference architecture for universal strong authentication across all users and all devices over all networks. Using open standards, OATH will offer more hardware choices, lower cost of ownership, and allow customers to replace existing disparate and proprietary security systems whose complexity often leads to higher costs.”

I have created a free PHP toolkit for retrieving data from your analytics account.

Example of usage:

<?php
require_once 'googleAPI.class.php';

$gapi = new googleAPI('your username','your password',"a profile");
$reportData = $gapi->viewReport("2009-04-01","2009-04-25","ga:pageviews,ga:visits,ga:newVisits","ga:country,ga:city,ga:date,ga:browserVersion");
?>

You just need to include the analytics library and initialize the object with your username, password, and profile (this is the site name(s) that you see when you first login to your analytics account).

Parameters:

$dateStart: The start date of the report data
$dateEnd: The end date of the report data
$metrics: metric list (multiple metrics need to be separated by commas)
$dimensions: dimensions list (multiple dimensions need to be separated by commas)

You can download it here

Return values

The “viewReport” function returns an array with a list of all the dimensions/metrics that you requested.

Also, a full list of dimensions and metrics can be found here

May 1, 2009   9 Comments