Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Analytics API with PHP

I am using the Google Analytics PHP class to get data from Google Analytics. http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation

I would like to get a report of "Bounce Rate" For "Top Contnet".

The thing is I am not familiar with the terminology.

When I am trying to get a "content" report or "topcontent" or "top_content" it says that there in no such metric. I simply don't know the right expressions.

Does anyone know where can I find a list of all expressions? metrics & dimensions?

Thanks.

like image 383
Udi Oz Avatar asked Mar 27 '11 09:03

Udi Oz


Video Answer


2 Answers

Top content isn't a metric, it's just a list of the pages on your site with the highest number of page views.

The metric you're looking for is 'entranceBounceRate' and the dimension is 'pagePath'. You want to get the bounce rate for the top X most visited pages on your site, so you'll want to limit your results and sort the results by '-pageviews' (pageviews descending).

If you want to get the bounce rate for the top 10 most viewed pages on your site, your query should look like this:

$ga = new gapi('[email protected]','password');
$ga->requestReportData(145141242,array('pagePath'),array('entranceBounceRate','pageviews'),array('-visits'),null,null,null,10);

The Google Analytics Export API has a data feed query explorer that should help you out considerably when using GAPI: http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html

Also, here's a list of all available dimensions and metrics you can pull from the API: http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html

Definitely read over the GAPI documentation: http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation

like image 166
luciddreamz Avatar answered Sep 20 '22 23:09

luciddreamz


If you would like to get the global Bounce Rate for the last 30days (by default), here is how. Very simple once you know it.

//Check Bounce Rate for the last 30 days
$ga = new gapi(ga_email, ga_password);
$ga->requestReportData(145141242, NULL ,array('bounces', 'visits'));
$data = round(($ga->getBounces() / $ga->getVisits()) * 100) . "%";

Note that the GAPI has a bug, they mention the dimension parameter is optional (2nd parameter) but it's not. You have to open the gapi.class.php file and patch line 128 with this:

  //Patch bug to make 2nd parameter optional
  if( !empty($dimensions) ) {
      $parameters['dimensions'] = 'ga:'.$dimensions;
  } else {
      $parameters['dimensions'] = '';
  }
like image 39
Etienne Dupuis Avatar answered Sep 17 '22 23:09

Etienne Dupuis