maxandriani / ngx-google-analytics

An easy way to use and configure Google Analytics on Angular 6+ applications
MIT License
120 stars 49 forks source link

load traking-code dynamically from server and set #87

Open kaffash999 opened 2 years ago

kaffash999 commented 2 years ago

how can i set traking-code dynamic in NgxGoogleAnalyticsModule.forRoot('traking-code')

avmesquita commented 2 years ago

enviroment.ts => ga = "YOUR-TRACKING-CODE"

NgxGoogleAnalyticsModule.forRoot(enviroment.ga);

Maleki commented 2 years ago

Unfortunately this is not loading it dynamically from the server. Once compiled I believe your environment.ts file is part of the deployed package.

avmesquita commented 2 years ago

Look this article from Daniel Kreider (@dkreider) to observe directly use of gtag.

https://itnext.io/angular-google-analytics-the-complete-guide-6518736096a0

I thing you may use like

this.$gaService.set('config', 'YOUR-TRACKING-CODE');

But I don´t tested.

P.S.: I really sad with Google Analytics technology. I use Brave Browser and it blocks all external resources scripts, then ga shot fail and do not exists an API endpoint to make a http request. For my sites, I am using Matomo into a subdomain.