Skip to content

Fix Matomo page view tracking (MatomoRouterModule.forRoot()) - #26

Merged
matthewberry merged 1 commit into
mainfrom
mjberry/fix-matomo-router-tracking
Oct 20, 2026
Merged

matthewberry merged 1 commit into
mainfrom
mjberry/fix-matomo-router-tracking

Conversation

@matthewberry

Copy link
Copy Markdown
Contributor

Problem

No page views reach Matomo. src/main.ts imports MatomoRouterModule bare instead of MatomoRouterModule.forRoot(). Since ngx-matomo-client 7.0, the bare module only sets the "router tracking enabled" flag, and that flag turns off the initial-load page view (trackAppInitialLoad: !inject(MATOMO_ROUTER_ENABLED)). The MatomoRouter service and the ENVIRONMENT_INITIALIZER that subscribe to NavigationEnd are registered only by forRoot(). So nothing calls trackPageView, and Matomo receives only outlink clicks and custom events.

In 6.x the bare import worked, because the module constructor called MatomoRouter.initialize() (MatomoRouter was providedIn: 'root'). The 7.0 upgrade dropped that constructor.

Fix

MatomoRouterModule → MatomoRouterModule.forRoot().

Verification

  • npm ci && ng build passes.
  • For crispr-copies-frontend, I served a production build before and after this change, with trackerUrl pointed at a local stub Matomo, and loaded it in headless Chrome. Before: no tracking requests. After: one page view, idsite=18, url=…/home. The other repos got the same one-line change and a build only.

@matthewberry
matthewberry merged commit af0989e into main Oct 20, 2026
2 checks passed
@matthewberry
matthewberry deleted the mjberry/fix-matomo-router-tracking branch October 20, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant