• 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 PHP API: Getting data without a dimension

Google Analytics PHP API: Getting data without a dimension

My Google Analytics API PHP class was initially developed assuming that a dimension would always be supplied but it doesn’t actually need to be, so I modified it to deal with no dimension and present an example here.

Thanks to Turner Walters from www.visionpointmarketing.com for pointing out this issue and helping with the solution.

If both a dimension (more more than one dimension) and a metric is supplied to the data() function then a multi-dimensional array is created storing the dimension(s) and metrics. I have now modified the function so that if there is no dimension then is a single dimensional array containing just the metric data instead.

This is useful if you want to get a summary for the account profile as a whole, instead of looking at data for specific dimensions.

For example, if you wanted to get an account overview for the last month showing counts for the number of bounces (i.e. one page only visits), new visitors, pageviews and unique pagesviews, you would do this:

$data = $api->data($id, '', 'ga:bounces,ga:newVisits,ga:visits,ga:pageviews,ga:uniquePageviews');

Doing print_r($data) would result in something along these lines:

Array
(
    [ga:bounces] => 80358
    [ga:newVisits] => 77986
    [ga:visits] => 91141
    [ga:pageviews] => 111634
    [ga:uniquePageviews] => 101403
)

You could then potentially loop through all the accounts in the class’s accounts array and get a summary for each account.

Check Out These Related posts:

  1. Google Analytics API PHP Class – Get most popular pages
  2. Google Analytics API dimensions vs metrics
  3. Looping through the Google Analytics API PHP class data
  4. Paging through result data from the Google Analytics API PHP Class

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