Google Analytics Reports 7.x
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
This documentation is for the 7.x version of Google Analytics Reports. For Drupal 6, click here.
Required modules
Views
Google Analytics Reports provides a Views query plugin to create Google Analytics reports using Views interface.
Recommended modules
Charts
Enable charts_google or charts_highcharts submodules to see graphical reports.
Ajax Blocks
For improved loading performance of Google Analytics Reports blocks.
Installation & Configuration
You will need to set up a Google API Console project. For more details on this, as well as installation and configuration, view the README.txt.
Examples
Using the Google Analytics Reports API
// Output a pie chart using Google Charts showing social referrals for the
// last 30 days.
if (module_exists('charts_google')) {
$params = array(
'metrics' => array('ga:sessions'),
'start_date' => strtotime('-31 days'),
'end_date' => strtotime('-1 day'),
'dimensions' => 'ga:socialNetwork',
'filters' => 'ga:hasSocialSourceReferral==Yes',
'max_results' => 10000,
'sort_metric' => '-ga:sessions',
);
$report_data = google_analytics_reports_api_report_data($params);
if (!empty($report_data->results->rows)) {
$data = array();
foreach ($report_data->results->rows as $row) {
$data[] = array($row['socialNetwork'], (int) $row['sessions']);
}
$chart = array(
'#type' => 'chart',
'#title' => t('Social network referrals'),
'#chart_type' => 'pie',
'#chart_library' => 'google',
'#legend_position' => 'right',
'#data_labels' => TRUE,
'#tooltips' => FALSE,
);
$chart['pie_data'] = array(
'#type' => 'chart_data',
'#title' => t('Social Networks'),
'#data' => $data,
);
}
$output = drupal_render($chart);
}
Chart examples
Charts module offers several examples to get you started with charts. After installing, browse to charts/examples. The code for these examples is located in the module file includes/charts.examples.inc.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion