0

after installing Ngx Google Analytics module from NPM, I have implemented it in my app module, for auto tracking I have imported two modules, NgxGoogleAnalyticsModule and NgxGoogleAnalyticsRouterModule, and I got this error:

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";

import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { SharedModule } from "./shared/shared.module";
import { HttpClientModule } from "@angular/common/http";

import {
  NgxGoogleAnalyticsModule,
  NgxGoogleAnalyticsRouterModule,
} from "ngx-google-analytics";

const pages = [];

@NgModule({
  declarations: [AppComponent, pages],
  imports: [
    AppRoutingModule,
    BrowserModule,
    HttpClientModule,
    SharedModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    NgxGoogleAnalyticsModule.forRoot(environment.ga),
    NgxGoogleAnalyticsRouterModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Error after ng serve in the console:

My Solution I was trying to solve it and I have fixed it this way:

in providers, I have added this service >>> GoogleAnalyticsService

@NgModule({
  declarations: [AppComponent, pages],
  imports: [
    AppRoutingModule,
    BrowserModule,
    HttpClientModule,
    SharedModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    NgxGoogleAnalyticsModule.forRoot(environment.ga),
    NgxGoogleAnalyticsRouterModule
  ],
  providers: [
    GoogleAnalyticsService
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}
  • 2
    [When asking a question about a problem with code, people who are volunteering to help need the text of the code. Images of the code are not an acceptable substitute.](https://idownvotedbecau.se/imageofcode). That goes for error messages too. – Liam Feb 22 '21 at 09:07
  • thanks for the feedback, I will add a code snippet too – davit tskhvariashvili Feb 22 '21 at 09:15

0 Answers0