You are here

function _google_analytics_reports_pageviews in Google Analytics Reports 7

Same name and namespace in other branches
  1. 6 google_analytics_reports/google_analytics_reports.pages.inc \_google_analytics_reports_pageviews()

Renders an img element with a chart of the number of pageviews over the past 30 days.

1 call to _google_analytics_reports_pageviews()
google_analytics_reports_detail_page in google_analytics_reports/google_analytics_reports.pages.inc
Page callback for admin/reports/google-analytics/detail.

File

google_analytics_reports/google_analytics_reports.pages.inc, line 102
Page callbacks for google analytics.

Code

function _google_analytics_reports_pageviews($path) {
  $params = array(
    'metrics' => array(
      'ga:pageviews',
    ),
    'dimensions' => array(
      'ga:date',
    ),
    'sort_metric' => array(
      'ga:date',
    ),
    'start_date' => strtotime('-31 days'),
    'end_date' => strtotime('-1 day'),
    'filters' => _google_analytics_reports_path_filter($path),
  );
  $feed = google_analytics_api_report_data($params);
  if ($feed->error) {
    return FALSE;
  }
  $max_views = 0;
  foreach ($feed->results as $row) {
    $data[] = $row['pageviews'];
    $max_views = max($row['pageviews'], $max_views);
  }
  $chart = array(
    '#title' => '',
    '#chart_id' => 'visits_large_30d',
    '#data' => $data,
    '#type' => CHART_TYPE_LINE . ':nda',
    '#size' => chart_size(1000, 80),
    '#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_views,
    '@yesterday' => $last_day['pageviews'],
  ));
  $chart['#attributes'] = array(
    'title' => $title,
    'style' => 'height:' . $chart['#size']['#height'] . 'px; width:100%',
  );
  $output = theme('chart', array(
    'chart' => $chart,
  ));
  return $output;
}