diff --git a/packages/app-shell/src/app-shell.js b/packages/app-shell/src/app-shell.js index 012fd97a85d4f8484b90ef8eba5cdf0590509b2a..6fe7b6dcbf67acd75ed6a8e9590d8ccb56da7f4d 100644 --- a/packages/app-shell/src/app-shell.js +++ b/packages/app-shell/src/app-shell.js @@ -61,6 +61,7 @@ export class AppShell extends ScopedElementsMixin(LitElement) { this.matomoUrl = ''; this.matomoSiteId = -1; + this.matomo = null; this._attrObserver = new MutationObserver(this.onAttributeObserved); } @@ -255,6 +256,10 @@ export class AppShell extends ScopedElementsMixin(LitElement) { this.initRouter(); this._bus.subscribe('auth-update', this._updateAuth); + + this.updateComplete.then(()=> { + this.matomo = this.shadowRoot.querySelector(this.constructor.getScopedTagName('dbp-matomo')); + }); } disconnectedCallback() { @@ -668,9 +673,8 @@ export class AppShell extends ScopedElementsMixin(LitElement) { } track(action, message) { - const matomo = this.shadowRoot.querySelector(this.constructor.getScopedTagName('dbp-matomo')); - if (matomo !== null) { - matomo.track(action, message); + if (this.matomo !== null) { + this.matomo.track(action, message); } } diff --git a/packages/matomo/src/matomo.js b/packages/matomo/src/matomo.js index 47702a416a44c3051f5eecb7d8071568dce5fbf7..17d9b793c59c9373ce2ba29d5b1efa1dd9abf7ed 100644 --- a/packages/matomo/src/matomo.js +++ b/packages/matomo/src/matomo.js @@ -107,7 +107,7 @@ export class MatomoElement extends DBPLitElement { } track (action, message) { - console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message); + console.log('MatomoElement (' + this.isRunning + '): ' + action + ', ' + message); const event = ['trackEvent', action, message]; if (this.isRunning) { _paq.push(event);