Closed ciekals11 closed 11 months ago
TL;DR Injecting GoogleTagManagerService into component that is preloaded with ssr results in ReferenceError: document is not defined
GoogleTagManagerService
ReferenceError: document is not defined
I'm using SSR with my angular application and I'm facing an issue with angular-google-tag-manager example code:
angular-google-tag-manager
export class AppComponent implements OnInit { constructor( protected gtmService: GoogleTagManagerService, @Inject(PLATFORM_ID) private platformId: Object ) {} ngOnInit(): void { if (!isPlatformBrowser(this.platformId)) { void this.gtmService.addGtmToDom(); } } }
This results in:
ReferenceError: document is not defined at Object.documentRef (/dist/<project_name>/server/main.js:232935:9)
After inspecting this file i have found faulty peace of code:
this.browserGlobals = { windowRef() { return window; }, documentRef() { return document; // <------- this generates mentioned error } };
In constructor of GoogleTagManagerService
TL;DR Injecting
GoogleTagManagerService
into component that is preloaded with ssr results inReferenceError: document is not defined
I'm using SSR with my angular application and I'm facing an issue with
angular-google-tag-manager
example code:This results in:
After inspecting this file i have found faulty peace of code:
In constructor of
GoogleTagManagerService