angular-gtag icon indicating copy to clipboard operation
angular-gtag copied to clipboard

How to use with variable GAID?

Open deejbee opened this issue 7 years ago • 2 comments

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?

deejbee avatar Aug 02 '18 08:08 deejbee

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?

dj-at-work avatar Sep 14 '18 11:09 dj-at-work

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.

chaitanyasm avatar Sep 26 '18 18:09 chaitanyasm