ngx-matomo-client
ngx-matomo-client copied to clipboard
How to not trigger trackPageView if I change query params in the url.
Hello. I change a query param in the url and it triggers a NavigationEnd in the angular router, and the MatomoTracker makes a trackPageView. Is there any way to filter out these events?
Hi @p-aron
You can configure your Matomo server, see the official help.
But if you want to configure it client-side, I think there is no easy way to do what you want currently. But good news is it could be easily implemented!
Long answer : This feature can be split up:
- If I understand correctly, you want to strip all (or only some?) url parameters, and track the page url without params, eg.
/url?param1¶m2
would be tracked as/url
. This is already feasible by providing a custom implementation forPageUrlProvider
. - Subsequent navigation events to the same url should be ignored and not tracked as a new page view. This is already the case BUT based on
RouterEvent.urlAfterRedirect
. This may be a bug, we should use the url provided byPageUrlProvider
instead.
Short answer : I will think about the following:
- add a simple configuration option to strip url parameters (without the need to provide a custom
PageUrlProvider
implementation) - track page view only after distinct url changes using the
This can probably be implemented soon, but it would be great if you would like to open a PR for one or each of those two points!
Hi @p-aron, is your issue solved?
hello, my case is 2. I found the problematic code in/matomo-router.service.ts:
this.router.events
.pipe(
// Take only NavigationEnd events
filter(isNavigationEnd),
// Filter out excluded urls
filter(isNotExcluded(this.config.exclude)),
// Distinct urls
distinctUntilKeyChanged('urlAfterRedirects'),
// Optionally add some delay
delayOp,
// Set default page title & url
switchMap(event =>
this.presetPageTitleAndUrl(event).pipe(map(({ pageUrl }) => ({ pageUrl, event }))),
),
// Run interceptors then track page view
concatMap(({ event, pageUrl }) =>
this.callInterceptors(event).pipe(tap(() => this.trackPageView(pageUrl))),
),
)
My understanding is that distinctUntilKeyChanged('urlAfterRedirects') is not working as the code writer expected. I can maybe do a fix later.
@p-aron you're right, that was my point 2.
I will take a look on how to fix it, but don't hesitate to create a PR if you have some time! Thanks
Next week I might have some time to understand the code better. Thank you very much!
:tada: This issue has been resolved in version 6.2.0 :tada:
The release is available on:
-
v6.2.0
- GitHub release
Your semantic-release bot :package::rocket: