Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with variable GAID? #2

Open
deejbee opened this issue Aug 2, 2018 · 2 comments
Open

How to use with variable GAID? #2

deejbee opened this issue Aug 2, 2018 · 2 comments

Comments

@deejbee
Copy link

deejbee commented Aug 2, 2018

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?

@dj-at-work
Copy link

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?

@chaitanyasm
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants