Using the Google Analytics API with PHP

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

I would like to receive a "Bounce Rate" message for "Top Contnet".

The fact is that I am not familiar with the terminology.

When I try to get the report "content" or "topcontent" or "top_content", it says that there is no such metric. I just don't know the right expressions.

Does anyone know where I can find a list of all expressions? metrics and sizes?

Thanks.

+8
terminology php google-analytics
source share
2 answers

Top content is not a metric, it's just a list of pages on your site with the most page views.

The metric you are looking for is 'entryBounceRate' and the size is 'pagePath'. You want to get a bounce rate for the most visited pages on your site, so you want to limit your results and sort the results by "-pageviews" (page views).

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

$ga = new gapi('email@yourdomain.com','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 a lot when using the GAPI: http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html

In addition, here is a list of all available dimensions and measures that you can extract from the API: http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html

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

+5
source share

If you want to get the global bounce rate in the last 30 days (default), here's how to do it. Very simple as soon as 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) . "%"; 

Please note that there is an error in the GAPI, they mention the measurement parameter optional (2nd parameter), but this is not so. You should open the gapi.class.php file and patch line 128 as follows:

  //Patch bug to make 2nd parameter optional if( !empty($dimensions) ) { $parameters['dimensions'] = 'ga:'.$dimensions; } else { $parameters['dimensions'] = ''; } 
+1
source share

All Articles