Skip to content
Snippets Groups Projects
Commit 0942162b authored by Neuber, Eugen Ramon's avatar Neuber, Eugen Ramon :speech_balloon:
Browse files

Simplify call to matomo.track()

See issue #29
parent 718300dd
No related branches found
No related tags found
1 merge request!2Matomo web component
Pipeline #13009 passed
...@@ -61,6 +61,7 @@ export class AppShell extends ScopedElementsMixin(LitElement) { ...@@ -61,6 +61,7 @@ export class AppShell extends ScopedElementsMixin(LitElement) {
this.matomoUrl = ''; this.matomoUrl = '';
this.matomoSiteId = -1; this.matomoSiteId = -1;
this.matomo = null;
this._attrObserver = new MutationObserver(this.onAttributeObserved); this._attrObserver = new MutationObserver(this.onAttributeObserved);
} }
...@@ -255,6 +256,10 @@ export class AppShell extends ScopedElementsMixin(LitElement) { ...@@ -255,6 +256,10 @@ export class AppShell extends ScopedElementsMixin(LitElement) {
this.initRouter(); this.initRouter();
this._bus.subscribe('auth-update', this._updateAuth); this._bus.subscribe('auth-update', this._updateAuth);
this.updateComplete.then(()=> {
this.matomo = this.shadowRoot.querySelector(this.constructor.getScopedTagName('dbp-matomo'));
});
} }
disconnectedCallback() { disconnectedCallback() {
...@@ -668,9 +673,8 @@ export class AppShell extends ScopedElementsMixin(LitElement) { ...@@ -668,9 +673,8 @@ export class AppShell extends ScopedElementsMixin(LitElement) {
} }
track(action, message) { track(action, message) {
const matomo = this.shadowRoot.querySelector(this.constructor.getScopedTagName('dbp-matomo')); if (this.matomo !== null) {
if (matomo !== null) { this.matomo.track(action, message);
matomo.track(action, message);
} }
} }
......
...@@ -107,7 +107,7 @@ export class MatomoElement extends DBPLitElement { ...@@ -107,7 +107,7 @@ export class MatomoElement extends DBPLitElement {
} }
track (action, message) { track (action, message) {
console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message); console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message);
const event = ['trackEvent', action, message]; const event = ['trackEvent', action, message];
if (this.isRunning) { if (this.isRunning) {
_paq.push(event); _paq.push(event);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment