You are here

function seotools_fetch_ga_data in Drupal SEO Tools 7

Same name and namespace in other branches
  1. 6 seotools.report.inc \seotools_fetch_ga_data()
5 calls to seotools_fetch_ga_data()
seotools_dashboard_analytics_box in ./seotools.report.inc
seotools_dashboard_map_box in ./seotools.report.inc
seotools_dashboard_referrers_box in ./seotools.report.inc
seotools_dashboard_sources_box in ./seotools.report.inc
seotools_generate_report_top_and_trends in ./seotools.report.inc
valid ids: keywords

File

./seotools.report.inc, line 422

Code

function seotools_fetch_ga_data($request, $group_by = 'date') {
  $data = google_analytics_api_report_data($request);

  // Add up all the statistics for different paths.
  $rows = array();
  foreach ($data as $item) {
    $dimensions = $item
      ->getDimensions();
    if (is_array($group_by)) {
      $group_name = '';
      foreach ($group_by as $group_by_item) {
        $group_name .= $dimensions[$group_by_item];
      }
    }
    else {
      $group_name = $dimensions[$group_by];
    }
    if (isset($rows[$group_name])) {
      foreach ($item
        ->getMetrics() as $key => $value) {
        $rows[$group_name][$key] += $value;
      }
    }
    else {
      $rows[$group_name] = $item
        ->getMetrics();
    }
  }
  return $rows;
}