ngx-matomo icon indicating copy to clipboard operation
ngx-matomo copied to clipboard

How to init matomo _after_ user has accepted terms?

Open tarlepp opened this issue 3 years ago • 5 comments
trafficstars

We've an issue because we don't want to initialize Matomo, before user has accepted the terms of service. How would we do this?

For now it looks like that init is causing that matomo is loaded before user has accepted this.

tarlepp avatar Nov 12 '22 13:11 tarlepp

I would start by adding requireConsent: true to the MatomoConfig and then, once your user has accepted the terms of services, I would call this.matomoTracker.setConsentGiven() which will everything to your Matomo instance.

Arnaud73 avatar Dec 29 '22 22:12 Arnaud73

Actually that didn't do the trick for me - I needed to track that state myself to get all working as expected.

tarlepp avatar Jun 27 '23 18:06 tarlepp

If you'd like to check the "standard" behavior, then:

  1. Clone this repo
  2. Build ngx-matomo : npm run build:ngx-matomo:prod
  3. Run the demo app : npm run test

You'll see that in this app, no tracking occurs before user consent is provided.

If your use case required something different, I'm willing to have a look at it!

Arnaud73 avatar Jun 27 '23 19:06 Arnaud73

Yeah, the main reason is that we need to use this plugin - https://plugins.matomo.org/AjaxOptOut - and if we do that your.piwik/index.php?module=API&method=AjaxOptOut.isTracked request tracking is started.

So I just resolved this by storing this tracking status to local storage and if it's accepted then I do that query otherwise not - simple solution after some testing.

tarlepp avatar Jun 27 '23 19:06 tarlepp

Thanks for the information. Once I nicely integrate MediaTracking and Form Tracking, I'll check how to provide a better way to interact with plugins.

Arnaud73 avatar Jun 28 '23 07:06 Arnaud73