Skip to content
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

How to not trigger trackPageView if I change query params in the url. #72

Closed
p-aron opened this issue Nov 15, 2023 · 6 comments · Fixed by #89
Closed

How to not trigger trackPageView if I change query params in the url. #72

p-aron opened this issue Nov 15, 2023 · 6 comments · Fixed by #89
Labels

Comments

@p-aron
Copy link
Contributor

p-aron commented Nov 15, 2023

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?

@EmmanuelRoux
Copy link
Owner

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:

  1. If I understand correctly, you want to strip all (or only some?) url parameters, and track the page url without params, eg. /url?param1&param2 would be tracked as /url.
    This is already feasible by providing a custom implementation for PageUrlProvider.
  2. 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 by PageUrlProvider instead.

Short answer :
I will think about the following:

  1. add a simple configuration option to strip url parameters (without the need to provide a custom PageUrlProvider implementation)
  2. 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!

@EmmanuelRoux
Copy link
Owner

Hi @p-aron, is your issue solved?

@p-aron
Copy link
Contributor Author

p-aron commented Dec 14, 2023

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.

@EmmanuelRoux
Copy link
Owner

EmmanuelRoux commented Dec 14, 2023

@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

@p-aron
Copy link
Contributor Author

p-aron commented Dec 14, 2023

Next week I might have some time to understand the code better. Thank you very much!

p-aron pushed a commit to p-aron/ngx-matomo-client that referenced this issue May 22, 2024
EmmanuelRoux added a commit to p-aron/ngx-matomo-client that referenced this issue May 28, 2024
EmmanuelRoux pushed a commit that referenced this issue May 28, 2024
This introduces a new option to ignore subsequent navigations to the _same_ url, according to a custom url comparator. This allows, for example, ignoring navigations triggered by only changing query params.

closes #72
EmmanuelRoux added a commit that referenced this issue May 28, 2024
# [6.2.0](v6.1.3...v6.2.0) (2024-05-28)

### Bug Fixes

* **tracker:** add default value for `acceptDoNotTrack` option ([243fc46](243fc46))
* upgrade schematics to non-deprecated module names ([946ef9f](946ef9f))

### Features

* add compatibility with Angular 18 ([7828aed](7828aed)), closes [#90](#90)
* add FormAnalytics support ([ccdcfac](ccdcfac))
* **router:** allow ignoring subsequent navigation to the same url ([#89](#89)) ([1cb504c](1cb504c)), closes [#72](#72)
* **tracker:** add new `disableCampaignParameters` configuration option ([88258fa](88258fa))
* **tracker:** add new `disableCampaignParameters` tracker method ([4cfda65](4cfda65))
@EmmanuelRoux
Copy link
Owner

🎉 This issue has been resolved in version 6.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants