Open ukutaht opened 1 year ago
Instead of making the library a singleton, I think effort should be put into something like this instead:
https://github.com/plausible/analytics/discussions/2414
That way, the library would be just that, a library (and a class), of which you could have many instances.
Then, the wrapper itself would act as a singleton, to make sure that it (by default) wouldn't setup multiple listeners.
There is a specific motivator for this RFC. When the
enableAutoPageviews
is called multiple times inadvertently by the library client, it registers multiple listeners on thepushState
API and starts sending duplicate events.It would be easy to avoid this mistake by storing some information on the
window
object and making any further calls toenableAutoPageviews
act as a no-op.Nice to have: in development mode, we should
console.warn
about using the library in an unintended way.This begs two questions:
pushState
andpopState
by this library ever be considered a feature not a bug?NODE_ENV
be used for that?