{"id":15722,"library":"ngx-matomo-client","title":"Matomo Client for Angular (ngx-matomo-client)","description":"ngx-matomo-client is a robust, actively maintained library providing seamless integration of Matomo (formerly Piwik) analytics into Angular applications. The current stable version is 9.0.1, offering compatibility with Angular 21. The library generally follows Angular's release cadence, providing updates for new major Angular versions, typically within weeks of their release. Key differentiators include its focus on privacy-respecting analytics, explicit support for Angular's module-less applications (since v8.0.0), and the ability to run tracking operations outside Angular's change detection zone for improved performance and stability. This package consolidates functionality previously split across `@ngx-matomo/tracker` and `@ngx-matomo/router` since version 5, simplifying usage and reducing overhead for developers integrating Matomo with Angular's routing.","status":"active","version":"9.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/EmmanuelRoux/ngx-matomo-client","tags":["javascript","matomo","piwik","angular","analytics","typescript"],"install":[{"cmd":"npm install ngx-matomo-client","lang":"bash","label":"npm"},{"cmd":"yarn add ngx-matomo-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add ngx-matomo-client","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Angular core functionality for common directives and pipes.","package":"@angular/common","optional":false},{"reason":"Core Angular framework required for any Angular application.","package":"@angular/core","optional":false},{"reason":"Required for automatic page view tracking via Angular's router.","package":"@angular/router","optional":true}],"imports":[{"note":"This is the modern, standalone function for providing Matomo in root or feature modules, replacing legacy `MatomoModule.forRoot()`.","wrong":"import { provideMatomo } from '@ngx-matomo/tracker';","symbol":"provideMatomo","correct":"import { provideMatomo } from 'ngx-matomo-client';"},{"note":"The primary service for interacting with the Matomo tracker instance. Inject this into components or services.","wrong":"import { MatomoService } from '@ngx-matomo/tracker';","symbol":"MatomoService","correct":"import { MatomoService } from 'ngx-matomo-client';"},{"note":"Used with `withRouter()` for automatic page view tracking with Angular Router. The legacy module `MatomoRouterModule` was deprecated.","wrong":"import { NgxMatomoRouterModule } from '@ngx-matomo/router';","symbol":"MatomoRouterInitializer","correct":"import { MatomoRouterInitializer } from 'ngx-matomo-client';"}],"quickstart":{"code":"import { Component, OnInit } from '@angular/core';\nimport { MatomoService, provideMatomo, withRouter } from 'ngx-matomo-client';\nimport { bootstrapApplication } from '@angular/platform-browser';\nimport { provideRouter, RouterOutlet } from '@angular/router';\n\n@Component({\n  selector: 'app-root',\n  standalone: true,\n  imports: [RouterOutlet],\n  template: `\n    <h1>Welcome to Matomo Tracking!</h1>\n    <p>Check your Matomo dashboard for tracking data.</p>\n    <button (click)=\"trackCustomEvent()\">Track Custom Event</button>\n  `\n})\nexport class AppComponent implements OnInit {\n  constructor(private matomoService: MatomoService) {}\n\n  ngOnInit(): void {\n    // Manually track a page view if not using router integration\n    // this.matomoService.trackPageView();\n  }\n\n  trackCustomEvent(): void {\n    this.matomoService.trackEvent('UserInteraction', 'ButtonClick', 'CustomButton');\n    console.log('Custom event tracked!');\n  }\n}\n\nbootstrapApplication(AppComponent, {\n  providers: [\n    provideRouter([]),\n    provideMatomo({\n      trackerUrl: 'https://your-matomo-domain.com/matomo.php',\n      siteId: 1\n    }, withRouter())\n  ]\n});","lang":"typescript","description":"This quickstart sets up Matomo in a standalone Angular application, including router tracking and an example of manually tracking a custom event. Replace `trackerUrl` and `siteId` with your Matomo instance details."},"warnings":[{"fix":"Update all `import` statements to use `ngx-matomo-client`. Refer to the migration guide for specific class and function renames/relocations if upgrading from v4 or older.","message":"The package structure changed significantly in v5. The library was consolidated from `@ngx-matomo/tracker` and `@ngx-matomo/router` into a single `ngx-matomo-client` package. Direct imports from the old packages will fail.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Migrate your application's Matomo initialization from `MatomoModule.forRoot()` in `app.module.ts` to `provideMatomo()` in `main.ts` or `app.config.ts`, especially for new standalone components or applications.","message":"Angular module-based setup (e.g., `MatomoModule.forRoot()`) is largely superseded by standalone `provideMatomo` since v8.0.0, aligning with modern Angular practices. While legacy modules might still work for compatibility, the recommended approach is the standalone API.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Ensure your `ngx-matomo-client` version matches your Angular project's version according to the compatibility table in the package's README. Upgrade both `ngx-matomo-client` and Angular together.","message":"Compatibility with Angular versions is strict. Each major `ngx-matomo-client` version typically supports a specific major Angular version. For instance, v9.x requires Angular 21, v8.x requires Angular 20, and so on. Mismatched versions will lead to peer dependency errors.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Most applications will benefit from this. If specific scenarios require tracking within the Angular zone, consider wrapping `MatomoService` calls with `ngZone.run()` if absolutely necessary, or ensure your component logic correctly triggers change detection.","message":"Since v9.0.0, Matomo tracking runs outside Angular's zone by default. This is generally a performance improvement but might affect debugging or change detection if you rely on tracker side effects to trigger Angular updates without manual intervention.","severity":"gotcha","affected_versions":">=9.0.0"},{"fix":"Double-check your `trackerUrl` (including `matomo.php` or `piwik.php`) and `siteId` values against your Matomo server configuration. Use your browser's network tab to verify that `matomo.php` requests are being sent correctly.","message":"Incorrect `trackerUrl` or `siteId` configuration will result in Matomo tracking calls failing silently or reporting to the wrong Matomo instance. This is a common setup error.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure `provideMatomo()` is called in your `main.ts` or `app.config.ts` (for standalone applications) or `MatomoModule.forRoot()` (for legacy module-based applications) is imported in your root module.","cause":"The MatomoService has not been properly provided at the application root or the relevant feature module.","error":"NG0201: No provider for MatomoService!"},{"fix":"Check the `ngx-matomo-client` README's compatibility table and align your `ngx-matomo-client` package version with your Angular version. For example, if on Angular 21, use `ngx-matomo-client@9`.","cause":"A mismatch exists between the `ngx-matomo-client` version and your Angular version, leading to an incompatible peer dependency.","error":"Can't resolve '@angular/common' in 'node_modules/ngx-matomo-client'"},{"fix":"Ensure you are using `ngx-matomo-client` (not legacy `@ngx-matomo/tracker`). Verify your `ngx-matomo-client` version is up-to-date and run `npm install` or `yarn install` to refresh dependencies. Check your `tsconfig.json` for proper type resolution.","cause":"You might be using an older version of the library or have a corrupted `node_modules` installation, or there's a TypeScript type inference issue.","error":"Property 'trackPageView' does not exist on type 'MatomoService'."},{"fix":"Ensure Matomo is initialized before calling tracking methods. For deferred or manual initialization, use `MatomoInitializerService.initialize()` once the necessary configuration (e.g., from an API) is available. For standard setup, ensure `provideMatomo` is correctly configured.","cause":"The Matomo tracker instance (window._paq) might not be initialized when `MatomoService` methods are called, often due to deferred configuration or incorrect initialization timing.","error":"ERROR TypeError: Cannot read properties of undefined (reading 'trackPageView')"}],"ecosystem":"npm"}