import { NgModule , ModuleWithProviders , Inject , PLATFORM_ID , Injector } from '@angular/core' ; import { isPlatformBrowser } from '@angular/common' ; import { MatomoModuleConfiguration , MATOMO_CONFIGURATION , defaultConfiguration , } from './matomo-configuration' ; import { MatomoInjector } from './matomo-injector.service' ; import { MatomoTracker } from './matomo-tracker.service' ; import { MatomoRouteTracker } from './matomo-route-tracker.service' ; /**
 * Angular module encapsulating Matomo features.
 */ @ NgModule ( { declarations : [ ] , imports : [ ] , exports : [ ] , providers : [ MatomoInjector , MatomoTracker , MatomoRouteTracker ] , } ) export class MatomoModule { param platformId param injector param configuration param matomoInjector constructor ( @ Inject ( PLATFORM_ID ) private readonly platformId , private readonly injector , @ Inject ( MATOMO_CONFIGURATION ) private readonly configuration , private readonly matomoInjector ) { if ( ! isPlatformBrowser ( this . platformId ) ) { console . warn ( 'ngx-Matomo does not support server platform' ) ; } this . matomoInjector . init ( ) ; if ( this . configuration ?. routeTracking ?. enable === true ) { this . injector . get ( MatomoRouteTracker ) . startTracking ( ) ; } } /**
     * Use this method in your root module to provide the MatomoTracker service.
     * // TODO Investigate if the TransLoco way of injecting the module with its configuration is a better idea.
     */ static forRoot ( configuration ? ) { return { ngModule : MatomoModule , providers : [ { provide : MATOMO_CONFIGURATION , useValue : ! ! configuration ? { ... defaultConfiguration , ... configuration } : defaultConfiguration , } , MatomoTracker , MatomoRouteTracker , ] , } ; } }