Skip to content

Instantly share code, notes, and snippets.

@szeidler
Created January 22, 2020 15:19
Show Gist options
  • Save szeidler/6662711ef748d14cd3000ddad19918d1 to your computer and use it in GitHub Desktop.
Save szeidler/6662711ef748d14cd3000ddad19918d1 to your computer and use it in GitHub Desktop.
diff --git a/src/Controller/GaNodeReportsCharts.php b/src/Controller/GaNodeReportsCharts.php
index 4d377f6..20bd319 100644
--- a/src/Controller/GaNodeReportsCharts.php
+++ b/src/Controller/GaNodeReportsCharts.php
@@ -113,6 +113,14 @@ class GaNodeReportsCharts extends ControllerBase implements ContainerInjectionIn
// Chart details building.
$chart_date = $chart_page = $chart_session = [];
+ // Sum up pageviews and sessions.
+ // We process the results twice, to reduce the chance of patch conflicts.
+ $sum = array('pageviews' => 0, 'sessions' => 0);
+ foreach ($results_array['rows'] as $records) {
+ $sum['pageviews'] += $records['pageviews'];
+ $sum['sessions'] += $records['sessions'];
+ }
+
foreach ($results_array['rows'] as $records) {
$chart_date[] = date('d-m-y', $records['date']);
$chart_page[] = $records['pageviews'];
@@ -123,14 +131,14 @@ class GaNodeReportsCharts extends ControllerBase implements ContainerInjectionIn
$categories = $chart_date;
$seriesData[] = [
- 'name' => $this->t('Sessions'),
+ 'name' => $this->t("Sessions\n Σ: @total_number", ['@total_number' => $sum['sessions']]),
'color' => '#0d233a',
'type' => $this->chartSettings['type'],
'data' => array_map('intval', $chart_session),
];
$seriesData[] = [
- 'name' => $this->t('PageViews'),
+ 'name' => $this->t("PageViews\n Σ: @total_number", ['@total_number' => $sum['pageviews']]),
'color' => '#8bbc21',
'type' => $this->chartSettings['type'],
'data' => array_map('intval', $chart_page),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment