You are here

protected function GoogleAnalyticsReportsApiFeed::sanitizeReport in Google Analytics Reports 8.3

Sanitize report data.

1 call to GoogleAnalyticsReportsApiFeed::sanitizeReport()
GoogleAnalyticsReportsApiFeed::queryReportFeed in google_analytics_reports_api/src/GoogleAnalyticsReportsApiFeed.php
Query and sanitize report data.

File

google_analytics_reports_api/src/GoogleAnalyticsReportsApiFeed.php, line 696

Class

GoogleAnalyticsReportsApiFeed
Class GoogleAnalyticsReportsApiFeed.

Namespace

Drupal\google_analytics_reports_api

Code

protected function sanitizeReport() {

  // Named keys for report values.
  $this->results->rawRows = isset($this->results->rows) ? $this->results->rows : [];
  $this->results->rows = [];
  foreach ($this->results->rawRows as $row_key => $row_value) {
    foreach ($row_value as $item_key => $item_value) {
      $field_without_ga = str_replace('ga:', '', $this->results->columnHeaders[$item_key]->name);

      // Allow other modules to alter executed data before display.
      $this->moduleHandler
        ->alter('google_analytics_reports_api_reported_data', $field_without_ga, $item_value);
      $this->results->rows[$row_key][$field_without_ga] = $item_value;
    }
  }
  unset($this->results->rawRows);

  // Named keys for report totals.
  $this->results->rawTotals = $this->results->totalsForAllResults;
  $this->results->totalsForAllResults = [];
  foreach ($this->results->rawTotals as $row_key => $row_value) {
    $this->results->totalsForAllResults[str_replace('ga:', '', $row_key)] = $row_value;
  }
  unset($this->results->rawTotals);
}