angular-gtag
angular-gtag copied to clipboard
How to use with variable GAID?
If I need to load a different GAID when the app loads (from a config file that varies between different applications), what is the best approach since I can't put a hard coded GAI in the app.module.ts imports @NgModule imports array since the GtagModule.forRoot() is run very early in the liefecycle?
Same issue here, we have different environments like DEV and PROD and can't go with the same GAID for both. I would like to initialize it in the app.component.ts, how can I achieve this?
I defined tracking ids in environment files and initialize Gtag in app module like this.
GtagModule.forRoot({trackingId: '', trackPageviews: true })
and provide environment specific tracking id in app component constructor.
this.gtag = new Gtag({trackingId: environment.gaTrackingID, trackPageviews: true }, this.router);
This enabled me to track on different GAIDs based on environment the app is built for.