A blend of programming and seo

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Reddit
  • Twitter
  • HackerNews
  • StumbleUpon
  • Technorati

9 comments

1 Free php library for the google analytics API | A blend of … | Webmaster Tools { 05.01.09 at 4:18 pm }

[...] Read more:  Free php library for the google analytics API | A blend of … [...]

2 Mark { 05.07.09 at 7:26 am }

Any idea why I´m getting this messsage: “Invalid value for ids parameter:”
Thx

3 Justin (rawseo) { 05.12.09 at 1:46 am }

@mark:

The ids parameter is your profile ID. You might want to check to make sure this is the right value from your account. When you first log in to your analytics account, you will see the name(s) of your profiles on the first screen (copy and paste the exact text from the “name” column”)

4 Ren Lawrence { 05.13.09 at 12:53 pm }

Amazing Tool!! Exactly what I was looking for.

5 Custom AMFPHP Services for GeSHi & Google Analytics API | Rive.be | Blog { 05.14.09 at 2:57 pm }

[...] I made some new custom AMFPHP Service classes for the GeSHi – Generic Syntax Highlighter & Google Analytics API. [...]

6 mxyzplk { 05.18.09 at 12:54 pm }

thanks for joining mybloglog community, at this time try to learn about API and AJAX, but I still don’t have time to learn because I have to increase my earning… I hope you can share minds about API’s, btw do you have feedburner email subscription? I want to hear more about your programming posts..

7 ReignDesign | Blog - Highlight your site’s hot content with the Google Analytics API { 06.19.09 at 12:02 am }

[...] I chose to use the PHP library provided by RawSEO.com [...]

8 srini { 08.12.09 at 6:00 am }

After running your test script with my data, i get the blank screen. Any reason ?

9 Justin (rawseo) { 08.12.09 at 8:51 am }

@srini,

Do you have analytics data for the test dates? also, do you have php 5 with the curl extension installed?

Leave a Comment