Skip to content

Instantly share code, notes, and snippets.

@szeidler
Created February 25, 2019 15:48
Show Gist options
  • Save szeidler/378bd798c36eab617e31652cd1ac8340 to your computer and use it in GitHub Desktop.
Save szeidler/378bd798c36eab617e31652cd1ac8340 to your computer and use it in GitHub Desktop.
Add summed up numbers to ga_node_reports graph
diff --git a/ga_node_reports.pages.inc b/ga_node_reports.pages.inc
index f0eb797..8bc4426 100644
--- a/ga_node_reports.pages.inc
+++ b/ga_node_reports.pages.inc
@@ -39,6 +39,13 @@ function ga_node_reports_view_node_report($node) {
// Chart details building.
$chart_date = $chart_page = $chart_session = array();
+ // Sum up pageviews and sessions.
+ $sum = array('pageviews' => 0, 'sessions' => 0);
+ foreach ($results->rows as $records) {
+ $sum['pageviews'] += $records['pageviews'];
+ $sum['sessions'] += $records['sessions'];
+ }
+
foreach ($results->rows as $records) {
$chart_date[] = date('d-m-y', $records['date']);
$chart_page[] = $records['pageviews'];
@@ -46,7 +53,10 @@ function ga_node_reports_view_node_report($node) {
}
// Google chart integration.
- $chart_header = array('Pageviews', 'Sessions');
+ $chart_header = array(
+ "Pageviews\n Σ: " . $sum['pageviews'],
+ "Sessions\n Σ: " . $sum['sessions'],
+ );
$chart_rows = array($chart_page, $chart_session);
$settings['chart']['pageview_session'] = array(
'header' => $chart_date,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment