Arnaud73 / ngx-matomo

Matomo (aka. Piwik) web analytics for Angular applications
MIT License
102 stars 48 forks source link

Dynamic configuration of scriptUrl, trackerUrl and siteId #98

Closed venkatpalakodety closed 1 year ago

venkatpalakodety commented 1 year ago

I am using the latest version of ngx-matomo (1.1.0). As per the documentation, I have the following set up:

app.module.ts

imports: [
MatomoModule.forRoot({
      scriptUrl: '',
      trackers: [
        {
          trackerUrl: '',
          siteId: 0
        }
      ],
      routeTracking: {
        enable: true
      }
    })
]

app.component.ts

import { MatomoTracker } from 'ngx-matomo';
import { AppConfigService } from './services/app-config.service';

 constructor(
private readonly matomoTracker: MatomoTracker,
private readonly appConfigService: AppConfigService
) {
    this.matomoTracker.setApiUrl(this.appConfigService.matomoUrl().concat('matomo.js'));
    this.matomoTracker.setTrackerUrl(this.appConfigService.matomoUrl());
    this.matomoTracker.setSiteId(this.appConfigService.matomoSiteId());
}

I am using an application config service to pull configurations mentioned in appConfig.json and dynamically set the Matomo Configuration, as per environment. Is there a recommended approach to set the scriptUrl, trackerUrl and siteId dynamically?