Skip to content

effective-ember/ember-metrics-matomo-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ember-metrics-matomo-adapter Build Status

An addon that provides a metrics-adapter for Matomo for ember-metrics.

Features (from ember-metrics)

  • Lazy initialization
  • Fastboot aware

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

ember install ember-metrics-matomo-adapter

Usage

Configure the adapter in config/environment.js as any other adapter for ember-metrics:

metricsAdapters: [
  {
    name: 'Matomo',
    environments: ['development', 'production'], // see ember-metrics docs
    config: {
      scriptUrl: '//cdn.matomo.cloud/<your-domain>.matomo.cloud',
      trackerUrl: 'https://<your-domain>.matomo.cloud',
      siteId: '<your-site-id>',
      disableCookies: true // <- for GDPR
    }
  }
]

You can use the adapter as you would any other ember-metrics-metrics-adapter:

// app/routes/application.ts

import Route from '@ember/routing/route';
import RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';

import MetricsService from 'ember-metrics/services/metrics';

export default class ApplicationRoute extends Route {
  @service declare readonly metrics: MetricsService;

  @service declare readonly router: RouterService;

  constructor() {
    super(...arguments);

    this.setupTracking();
  }

  private setupTracking() {
    this.router.on('routeDidChange', () => {
      const { currentURL, currentRouteName } = this.router;

      this.metrics.trackPage({
        page: currentURL,
        title: currentRouteName,
      });
    });
  }
}

Matomo-specific methods

Matomo implements some methods that aren't part of ember-metrics main api. These methods can be called through ember-metrics invoke.
Below is a list of Matomo-specific methods that are implemented by ember-metrics-matomo-adapter.

  • trackSiteSearch
    this.metrics.invoke('trackSiteSearch', {
      keyword: 'myKeyWord',
      category: 'myCategory',
      searchCount: 2,
    });

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.