-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable page tracking on server #94
Conversation
@pawcoding you're right, the lib was designed to disable only the low level tracking in SSR mode. It was not designed to also disable higher logic and prevent any client code call. I agree we may also disable client code defined as library components, such as interceptors. I will take a look at your PR soon! |
@pawcoding You can build the lib locally then reference it in your project with
|
Thanks for the quick reply and the explanation for local links. Unfortunately I use I also updated the code with your suggestion to use |
@pawcoding Thanks for you work! FYI, I added another commit to also disable form-analytics module |
## [6.3.1](v6.3.0...v6.3.1) (2024-09-15) ### Bug Fixes * **router, form-analytics:** disable page tracking on server ([#94](#94)) ([229083b](229083b))
🎉 This PR is included in version 6.3.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
The Problem
I've been using this package for various Angular projects, both with client-only and server-side rendering. However, I encountered an error where the server throws an error saying
navigator
is not defined.This happens when I attempt to get the current language in an interceptor to add it as a custom dimension:
While adding an
isPlatformBrowser
check to the interceptor would solve this, the README states:So, it seems like the interceptor shouldn't be executed on the server at all.
The Fix
Upon investigating, I found that:
core
package correctly checks the platform to initialize the tracker.MatomoRouter
does not skip initializing itself on the server and continues listening to router events and executing interceptors, leading to the error.To align with the README, I have modified
MatomoRouter
to also skip initialization when running on the server.Testing
I added two new test scenarios to cover both
'browser'
and'server'
PLATFORM_ID
values used by Angular. Both tests now pass as expected, confirming that the changes work correctly in both environments.Unfortunately Angular doesn't export the
PLATFORM_ID
s via a proper API but only with the internalɵ
prefix. Nevertheless I thought it's better to use them than hard-coding the strings just in case they might change the values in the future.I haven't been able to test these changes in my project because I'm unsure how to install a local version without deploying it to npm.Please let me know if this fix is acceptable or if the current behavior was indeed intended.