EmmanuelRoux / ngx-matomo-client

Matomo analytics client for Angular applications
https://matomo.org/
MIT License
74 stars 14 forks source link

'isUserOptedOut' does not return a value #84

Closed osca closed 6 months ago

osca commented 7 months ago

I'm setting up Matomo Tag Manager as provided in the documentation with the resulting provider:

...
  provideMatomo({
      scriptUrl: `https://${matomoHost}/js/container_${containerId}.js`,
      requireConsent: MatomoConsentMode.TRACKING,
  }),
...

When trying to create a custom opt-out form, I want to get the current state of the tracking via matomoTracker.isUserOptedOut(). This Promise does not return anything and seems to be just stuck. No error, no response in the console. Also matomoTracker.forgetUserOptOut() and matomoTracker.optUserOut() seems to do nothing. Do I need some special configuration to get this working properly? Thanks for any help in advance!

EmmanuelRoux commented 7 months ago

Hi @osca

Do you want to implement opt-in or opt-out?

For opt-in: your configuration seems correct, but you must then use methods like isConsentGiven() or setConsentGiven instead.

For opt-out: your configuration must be changed to requireConsent: MatomoConsentMode.NONE (or empty), and then use methods you described (isUserOptedOut(), optUserOut()...)

Doc here in README

osca commented 7 months ago

Thanks for the fast answer. I changed the requireConsent to MatomoConsentMode.NONE, but still no response from the methods. I created a small sample project to reproduce it:

matomo-opt-in.zip

Is there maybe something wrong with my Matomo config?

EmmanuelRoux commented 7 months ago

@osca Sorry I missed an important information: MatomoTracker was not originally designed to work with Tag manager. So the methods available on it may not work properly.

The only workaround I see right now to use both tag manager and tracker methods, is to include the standard tracker script (matomo.js) using this lib configuration options, and include tag manager script (https://${matomoHost}/js/container_${containerId}.js) manually in your page.

To wait for user to consent for cookies/tracking, you can delay the call to window._mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});. If you are using a Consent Manager it probably provide integration with Matomo Tag Manager.