EmmanuelRoux / ngx-matomo-client

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

Question about enabling/disabling tracker #74

Closed rgustavsson closed 12 months ago

rgustavsson commented 1 year ago

Hello!

Many thanks for a great library!

The ngx-tracker works perfectly well in my standard Angular application.

I'm using Scully.io for prerendering pages and see that I have an issue with matomo triggering before the Angular application itself has booted up and initialized the tracker properly (replaced the static html generated by scully).

Scully uses the browser to prerender and in some component I've just got an if statement saying "if scullyIsRunning, return". I'd like to do something similar with this tracker and I've seen that it's possible to disable the tracker in app.module

Is it possible to enable it run-time? :)

I have read through the readme to see if I could enable this tracker globally in some other way where I have access to the scully service.

Any thoughts?

EmmanuelRoux commented 1 year ago

Hi @rgustavsson

I’m not sure I understand deeply the problem, it’s difficult without a repro.

I would suggest to take a look at deferred initialization (explained in README). You can call matomoInitializer.initializeTracker at any time when your app is ready, nothing will be tracked before.

rgustavsson commented 12 months ago

This is perfect @EmmanuelRoux I kind of missed the APP_INITIALIZER possibilites. Already had one so I justed hooked it up in there. Many thanks!