I'm using Angulartics2. I'm trying to set tracking code dynamically to have something like this:
ga('create', environment.trackingCode, 'auto');
But I couldn't find a way to do that.
I absolutely need to read this variable from environment.ts
Is there a way to read it in index.html
from script tag.
Otherwise, Is it possible to remove this line and do it with Angulartics2 ?
I've finally found the answer here http://tech.webinterpret.com/how-to-make-google-analytics-work-in-a-single-page-application-spa/
window.ga('create', environment.trackingCode, 'auto');
inapp.module.ts
constructor.Set the property window otherwise it would throw an error:
declare global { interface Window { ga: any; } }