EmmanuelRoux / ngx-matomo-client

Matomo analytics client for Angular applications
https://matomo.org/
MIT License
74 stars 16 forks source link

Enable routerTracking will throw error #14

Closed retondong closed 3 years ago

retondong commented 3 years ago

Below is error message: Unhandled Promise rejection: R3InjectorError(AppModule)[MatomoModule -> MatomoRouteTracker -> Router -> Router -> Router]: NullInjectorError: No provider for Router! ; Zone: <root> ; Task: Promise.then ; Value: NullInjectorError: R3InjectorError(AppModule)[MatomoModule -> MatomoRouteTracker -> Router -> Router -> Router]: NullInjectorError: No provider for Router! at NullInjector.get (core.js:11100) at R3Injector.get (core.js:11267) at R3Injector.get (core.js:11267) at R3Injector.get (core.js:11267) at injectInjectorOnly (core.js:4751) at Module.ɵɵinject (core.js:4755) at Object.MatomoRouteTracker_Factory [as factory] (ngx-matomo.js:1919) at R3Injector.hydrate (core.js:11437) at R3Injector.get (core.js:11256) at new MatomoModule (ngx-matomo.js:1961) NullInjectorError: R3InjectorError(AppModule)[MatomoModule -> MatomoRouteTracker -> Router -> Router -> Router]: NullInjectorError: No provider for Router! at NullInjector.get (http://localhost:4200/vendor.js:27658:27) at R3Injector.get (http://localhost:4200/vendor.js:27825:33) at R3Injector.get (http://localhost:4200/vendor.js:27825:33) at R3Injector.get (http://localhost:4200/vendor.js:27825:33) at injectInjectorOnly (http://localhost:4200/vendor.js:21309:33) at Module.ɵɵinject (http://localhost:4200/vendor.js:21313:61) at Object.MatomoRouteTracker_Factory [as factory] (http://localhost:4200/vendor.js:233002:308) at R3Injector.hydrate (http://localhost:4200/vendor.js:27995:35) at R3Injector.get (http://localhost:4200/vendor.js:27814:33) at new MatomoModule (http://localhost:4200/vendor.js:233044:27) Use npm install is ok for me but use yarn install will throw this error

EmmanuelRoux commented 3 years ago

Hi @retondong ,

This error is not related to this library: your are likely to be using another library.

If you want to use this library, please install it following README instructions, ie:

npm install --save @ngx-matomo/tracker @ngx-matomo/router or yarn add @ngx-matomo/tracker @ngx-matomo/router

(And remove ngx-matomo from your package.json if present, unless you want to use that other library: but it is not related to this GitHub repository)

Then enable route tracking as described in the README:

@NgModule({
  imports: [
    // ...
    NgxMatomoTrackerModule.forRoot({
      siteId: 'YOUR_MATOMO_SITE_ID', // your Matomo's site ID (find it in your Matomo's settings)
      trackerUrl: 'YOUR_MATOMO_SERVER_URL', // your matomo server root url
    }),
    NgxMatomoRouterModule, // Add this
  ],
  // ...
})
export class AppModule {}

Please let me know if you have any other issue!

retondong commented 3 years ago

Thanks! It worked.