Google Analytics API PHP Class - Updates May 28th 2009
Posted May 28th, 2009 in PHP
I've published an update to my Google Analytics API PHP Class today which adds better support for filtering, and have added some filtering examples and more documentation to the example.php file.
More information about my Google Analytics API PHP Class can be found here and it can be downloaded from here. The download file is a .tar.gz file containing both the analytics class file and an example script.
New analytics_filters class
It's easy enough to write filters for the Analytics API (which is documented on their website here), remembering that you need to urlencode the string, and this new filtering class makes it easy to add filters as well.
For example, you could filter like this to filter just visitors from the USA and Canada (the filter is the urlencode() part):
$data = $api->data($id, '', 'ga:visits,ga:pageviews', false, false, false, 10, 1,
urlencode('ga:country==Canada,ga:country==United States'));
And now using my filtering class you could do this:
$filters = new analytics_filters('ga:country', '==', 'Canada');
$filters->add_and('ga:browser', '=@', 'Firefox');
$data = $api->data($id, '', 'ga:visits,ga:pageviews', false, false, false, 10, 1, $filters);
It's up to you, either way you prefer to do it.
I'll write up another post later on today or tomorrow with some more filtering examples.
Related posts:
- The Google Analytics API and PHP: A series (Tuesday, April 28th 2009)

Comments
blog comments powered by Disqus