i have also imported HttpClientModule and also properly configure GoogleTagManagerService.
import { HttpClientModule, /* other http imports */ } from "@angular/common/http";
@NgModule({
imports: [
HttpClientModule,
]}),
providers: [
{ provide: 'googleTagManagerId', useValue: 'GTM-XXXXXXX' }
],
});
But i am still getting errors . i am using Google Tag Manager package and import every things properly . and now i clone the project in new system, so now i am getting this error
app.component.ts code
import { GoogleTagManagerService } from 'angular-google-tag-manager';
constructor(
private gtmService: GoogleTagManagerService
) {}
ngOnInit(): void {
this.router.events.subscribe((evt) => {
if (evt instanceof NavigationEnd) {
const gtmTag = {
event: 'page',
pageName: evt.url
};
this.gtmService.pushTag(gtmTag);
}
if (!(evt instanceof NavigationEnd)) {
return;
}
});
}
正如您在此软件包中已解决的问题中所见,您必须将此软件包的旧版本用于 angular 8 ( https://github.com/mzuccaroli/angular-google-tag-manager/issues/38 )
npm i --save angular-google-tag-manager@1.1.4
It seems everything is ok. You can restart your app with ng run
.
I advise you to follow the steps on that blog:
https://itnext.io/how-to-add-google-tag-manager-to-an-angular-application-fc68624386e2
Or, you can cross-check your app with the demo-page.
https://github.com/mzuccaroli/angular-google-tag-manager/tree/master/demo-application
And, last but not least, you can re-install the package.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.