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 {}