Matomo Client for Angular (ngx-matomo-client)

9.0.1 · active · verified Tue Apr 21

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { Component, OnInit } from '@angular/core';
import { MatomoService, provideMatomo, withRouter } from 'ngx-matomo-client';
import { bootstrapApplication } from '@angular/platform-browser';
import { provideRouter, RouterOutlet } from '@angular/router';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet],
  template: `
    <h1>Welcome to Matomo Tracking!</h1>
    <p>Check your Matomo dashboard for tracking data.</p>
    <button (click)="trackCustomEvent()">Track Custom Event</button>
  `
})
export class AppComponent implements OnInit {
  constructor(private matomoService: MatomoService) {}

  ngOnInit(): void {
    // Manually track a page view if not using router integration
    // this.matomoService.trackPageView();
  }

  trackCustomEvent(): void {
    this.matomoService.trackEvent('UserInteraction', 'ButtonClick', 'CustomButton');
    console.log('Custom event tracked!');
  }
}

bootstrapApplication(AppComponent, {
  providers: [
    provideRouter([]),
    provideMatomo({
      trackerUrl: 'https://your-matomo-domain.com/matomo.php',
      siteId: 1
    }, withRouter())
  ]
});

view raw JSON →