You are here

function template_preprocess_google_analytics_reports_detail in Google Analytics Reports 7

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

File

google_analytics_reports/google_analytics_reports.theme.inc, line 53
Theme preprocess functions for google analytics.

Code

function template_preprocess_google_analytics_reports_detail(&$vars) {
  $vars['pageviews'] = number_format($vars['stats']['pageviews']);
  $vars['unique_pageviews'] = number_format($vars['stats']['uniquePageviews']);
  $vars['avg_time_on_page'] = format_interval($vars['stats']['avgTimeOnPage']);
  $vars['bounce_rate'] = round($vars['stats']['entranceBounceRate'], 2);
  $vars['exit_rate'] = round($vars['stats']['exitRate'], 2);
  if ($vars['stats']['uniquePageviews'] > 0) {
    $vars['goal_value'] = money_format('%i', $vars['stats']['goalValueAll'] / $vars['stats']['uniquePageviews']);
  }
  else {
    $vars['goal_value'] = '0.00';
  }
  $referrals = array();
  foreach ($vars['referrals'] as $referral) {
    $referrals[] = '<strong>' . $referral['source'] . '</strong> - ' . format_plural($referral['visits'], '1 Visit', '@visits Visits', array(
      '@visits' => number_format($referral['visits']),
    ));
  }
  $vars['referrals'] = theme('item_list', array(
    'items' => $referrals,
    'type' => 'ol',
  ));
  $keywords = array();
  foreach ($vars['keywords'] as $keyword) {
    $keywords[] = '<strong>' . $keyword['keyword'] . '</strong> - ' . format_plural($keyword['visits'], '1 Visit', '@visits Visits', array(
      '@visits' => number_format($keyword['visits']),
    ));
  }
  $vars['keywords'] = theme('item_list', array(
    'items' => $keywords,
    'type' => 'ol',
  ));
}