I noticed that for pages with URL that contains non standard characters the block does not display the page views stats.
Inside the file google_analytics_reports.blocks.inc there is a function called

I made the following changes and now it works fine.

 * Generates a block with the current page statistics.
function google_analytics_reports_path_mini_build($path) {
  if (!variable_get('google_analytics_reports_oauth_token', FALSE)) {
    return '<p>' . t('You must <a href="!url">authorize</a> Drupal to use your Analytics account before you can view reports.', array('!url' => url('admin/settings/google-analytics-reports'))) . '</p>';

  if ($path == '/') {
    //$path = '/index.html';  // <<<<THIS is not correct because the block does not return data for the frontpage (/)

  $params = array(
    'metrics' => array('ga:pageviews'),
    'dimensions' => array('ga:date'),
    'sort_metric' => array('ga:date'),
    'filters' => _google_analytics_reports_path_filter(urldecode($path)), //THE URLDECODE SOLVE THE NON ASCII CHARACTERS IN URL PROBLEM
    'start_date' => strtotime('-31 days'),
    'end_date' => strtotime('-1 day'),
  $feed = google_analytics_api_report_data($params);
  if ($feed->error) {
    return '<p>' . _google_analytics_reports_error_message() . '</p>';
  $max_visits = 0;
  foreach ($feed->results as $row) {
    $data[] = $row['pageviews'];
    $max_visits = max($row['pageviews'], $max_visits);
  $chart = array(
    '#chart_id' => 'pageviews_small_30d',
    '#data' => $data,
    '#type' => CHART_TYPE_LINE . ':nda',
    '#size' => chart_size(500, 40),
    '#adjust_resolution' => TRUE,
    '#data_colors' => array('AAAAAA'),
    '#chart_fill' => chart_fill('bg', '00000000'),
    '#shape_markers' => array(chart_shape_marker(0, 0, 'B', 0, $color = 'EEEEEE')),
    '#line_styles' => array(chart_line_style(2, 10, 0)),
  $last_day = end($feed->results);
  $title = t('The most views on a single day was @max.  Yesterday there were @yesterday views.', array('@max' => $max_visits, '@yesterday' => $last_day['pageviews']));

  $report['chart'] = l(chart_render($chart, array('title' => $title, 'style' => 'height:' . $chart['#size']['#height'] . 'px; width:100%')), 'admin/reports/google-analytics/detail', array('query' => array('path' => $path), 'html' => TRUE));
  $report['views'] = l(t('@views views this month', array('@views' => number_format($feed->totals['pageviews']))), 'admin/reports/google-analytics/detail', array('query' => array('path' => $path)));
  return theme('google_analytics_reports_path_mini', $report);

Members fund testing for the Drupal project. Drupal Association Learn more


grendzy’s picture

So I can be sure I'm testing the same thing as you, please post an example encoded character that you're working with. Thanks.

The other issue is #1345542: pull defaultPage from management API, instead of assuming index.html, /index.html is the default home page in Google Analytics so the issue is more complicated. Changing to "/" doesn't solve it, we have to get the home page value from the management API.

aleada’s picture

Try to change the url of a page to the following:
"δοκιμαστική-σελίδα-μπλα-μπλα" means "testing-page-blah-blah" in greek.

The $path is the page path that the block requests pageviews data from google analytics
After removing the code
$path = '/index.html';
the block started to display the pageviews of my front page ( / )

Plazik’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

6.x version is unsupported. Please upgrade to 7.x.