• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Article / PHP / Google Analytics API PHP Class – Updates May 22nd 2009

Google Analytics API PHP Class – Updates May 22nd 2009

I’ve made some updates to my Google Analytics API PHP Class today and posted the updated class and example files. The changes are documented here.

auth property is now public

The auth property which contains the authorization key after you’ve logged in is now a public property. You could therefore now do this:

$api1 = analytics_api();
$api1->login($email, $password);

$api2 = analytics_api();
$api2->auth = $api1->auth;

You could also save the auth key into a database and use it for subsequent requests; once authorized it’s valid for several days and this can cut down initial request time.

data method start and end parameters

I’ve added the ability to specify the values “today”, “yesterday” and “week” as the $start parameter when calling the data method. “week” sets the start and end dates to be the 7 days before today. Leaving them as false defaults to the month before today (i.e. the same behaviour as previously).

filters parameter added to the data method

The $filters parameter has been added to the data method for specifying filters. When a value is passed in for this parameter it adds “&filters=$filters” to the request string. I haven’t used filters yet myself with the exception of a couple of tests when adding this option.

debug parameter added to the data method

If you set debug to true when calling data the url that is used to call the Analytics API is echoed out to standard output which is useful for seeing what’s going on behind the scenes. If run from the CLI will echo it along with a linebreak; otherwise will put it in a <p> tag and end with a newline.

get_summary method added

A new method get_summary was added to get summary information for a profile: number of visits, number of pageviews, average time on site and pages per visit. I’ll post more about this new function tomorrow.

get_summaries method added

Works the same as the above but gets summaries for all profiles you have access to.

sec2hms method added

This function is from http://www.laughing-buddha.net/jon/php/sec2hms/ and is used to format the seconds returned in the get_summary method into h:m:s format.

Check Out These Related posts:

  1. Using filters with the Google Analytics API and PHP
  2. The Google Analytics API and PHP: A series
  3. Get data for a single page from the Google Analytics API
  4. Google Analytics API PHP Class – Get most popular pages

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap