npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-matomo

v2.0.0

Published

Matomo (aka. Piwik) web analytics for Angular applications.

Downloads

18,521

Readme

ngx-Matomo

GitHub stars Build Status (GitHub) NPM version Next NPM version Codacy Badge Conventional Commits MIT license

Wrapper for Matomo (aka. Piwik) analytics tracker for Angular applications.

Choose the version corresponding to your Angular version:

| Angular | ngx-matomo | | --------- | ------------- | | 16 | 2.x | | 14 and 15 | 1.x | | 13 | not available | | 9 to 12 | 1.0.0-rc1 | | 5 to 8 | 0.x |

Installation

Use npm or yarn to add the module to your current project:

npm install --save ngx-matomo

or

yarn add ngx-matomo

Using ngxMatomo

Injecting the tracker

In order to add Matomo capabilities to your application, you need to import MatomoModule into your root NgModule.

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MatomoModule } from 'ngx-matomo';

import { AppComponent } from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    ...
    MatomoModule.forRoot({
      scriptUrl: '//matomo.example.com/matomo.js',
      trackers: [
        {
          trackerUrl: 'http://matomo.example.com/matomo.php',
          siteId: 1
        }
      ],
      routeTracking: {
        enable: true
      }
    }),
    ...
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }

If you are using an old version of Matomo (3.x or less), please add scriptVersion with the version number (2, 3, 4…) to the configuration object passed the the MatomoModule.forRoot() function. This will activate some features present in Matomo 3 that were deprecated in Matomo 4.

Customizing tracking

Once that's done you can import MatomoTracker into any component of your application.

import { Component } from '@angular/core';
import { MatomoTracker } from 'ngx-matomo';

@Component({
  selector: 'app-root',
  template: `<router-outlet></router-outlet>`,
})
export class AppComponent {
  constructor(private matomoTracker: MatomoTracker) {}

  ngOnInit() {
    this.matomoTracker.setUserId('UserId');
    this.matomoTracker.setDocumentTitle('ngxMatomo Test');
  }
}

Then, let's find an action you would like to track:

<button (click)="whatHappensOnClick($event)"></button>

Just add the MatomoTracker to your component and use the trackEvent function.

import { Component } from '@angular/core';
import { MatomoTracker } from 'ngx-matomo';

@Component({
  selector: 'app-my',
  templateUrl: './myButton.html',
})
export class MyComponent {
  constructor(private matomoTracker: MatomoTracker) {}

  whatHappensOnClick(someVal) {
    /*
     * some code...
     */
    this.matomoTracker.trackEvent('category', 'action', 'name', someVal);
  }
}

Test driving ngxMatomo

A demo application is available in order to get you quickly up to speed.

  1. Clone the ngxMatomo repository: git clone https://github.com/Arnaud73/ngx-matomo.git
  2. cd into the repository
  3. Build the ngxMatomo library: npm run build:ngx-matomo:prod
  4. Run the demo application: npm run test

Migrating from earlier versions (0.x)

ngxMatomo 1.0 is a major evolution from previous versions. If you plan migrating from a previous release, follow the next steps:

  • Remove any Matomo injection script in your index.html if you chose to inject the tracker this way.
  • Remove any use of MatomoInjector in your code if you chose to inject the tracker this way.
  • Import the MatomoModule with MatomoModule.forRoot() call and provide a MatomoConfiguration object so that the tracker is correctly injected into your application.
  • Decide if you want to take advantage of the newly added features (route tracking, consent management) and update you configuration accordingly.

Original Source

This module is inspired from Angular2Piwik, which was also inspired from Angulartics 2.

License

MIT

See also

Matomo's site has the detailed documentation on how to use Matomo and integrate it in an application. See also: