From 0ee96d11dc7e4b8fd6f2200588a879c1316ef5d6 Mon Sep 17 00:00:00 2001 From: Eugen Neuber <eugen.neuber@tugraz.at> Date: Wed, 16 Sep 2020 11:54:36 +0200 Subject: [PATCH] Replay last event when user loges in See issue #29 --- packages/matomo/src/matomo.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/matomo/src/matomo.js b/packages/matomo/src/matomo.js index 4e69ec6d..47702a41 100644 --- a/packages/matomo/src/matomo.js +++ b/packages/matomo/src/matomo.js @@ -11,6 +11,7 @@ export class MatomoElement extends DBPLitElement { this.endpoint = ''; this.siteId = -1; this.isRunning = false; + this.lastEvent = []; } @@ -91,6 +92,11 @@ export class MatomoElement extends DBPLitElement { }); this.isRunning = true; + if (this.lastEvent.length > 0) { + console.log('MatomoElement* (' + this.isRunning + '): ' + this.lastEvent[1] + ', ' + this.lastEvent[2]); + _paq.push(this.lastEvent); + this.lastEvent = []; + } return; } if (! loggedIn && this.isRunning) { @@ -102,8 +108,11 @@ export class MatomoElement extends DBPLitElement { track (action, message) { console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message); + const event = ['trackEvent', action, message]; if (this.isRunning) { - _paq.push(['trackEvent', action, message]); + _paq.push(event); + } else { + this.lastEvent = event; } } } -- GitLab