You are here

function ga_stats_views_data in Google Analytics Statistics 7.x

Same name and namespace in other branches
  1. 7.2 ga_stats.views.inc \ga_stats_views_data()
  2. 7 ga_stats.views.inc \ga_stats_views_data()

Implementation of hook_views_data

Exposing the count table to views as a field, a filter and a sort

File

./ga_stats.views.inc, line 7

Code

function ga_stats_views_data() {
  $data = array();
  $times = ga_stats_ga_timeframes(true);
  $metrics = ga_stats_ga_metrics();
  foreach ($metrics as $mk => $mv) {
    foreach ($times as $tk => $tv) {
      $data['ga_stats_count_' . $mk . '_' . $tk]['table']['group'] = t('Statistics');
      $data['ga_stats_count_' . $mk . '_' . $tk]['table']['join'] = array(
        'node' => array(
          'table' => 'ga_stats_count',
          'left_field' => 'nid',
          'field' => 'nid',
          'type' => 'LEFT OUTER',
          'extra' => 'ga_stats_count_' . $mk . '_' . $tk . '.metric=\'' . $mk . '\' AND ga_stats_count_' . $mk . '_' . $tk . '.timeframe=\'' . $tk . '\'',
        ),
      );
      $data['ga_stats_count_' . $mk . '_' . $tk]['count'] = array(
        'title' => t("{$mv} {$tv}"),
        'help' => t('Information retrieved from Google Analytics'),
        'field' => array(
          'handler' => 'views_handler_field_numeric',
        ),
        'sort' => array(
          'handler' => 'views_handler_sort',
        ),
        'filter' => array(
          'handler' => 'views_handler_filter_numeric',
        ),
      );
    }
  }
  return $data;
}