Need to configure tracking code for Angulartics2

467 views Asked by At

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 ?

1

There are 1 answers

0
Ghita On

I've finally found the answer here http://tech.webinterpret.com/how-to-make-google-analytics-work-in-a-single-page-application-spa/

  1. Add window.ga('create', environment.trackingCode, 'auto'); in app.module.ts constructor.
  2. Set the property window otherwise it would throw an error:

    declare global { interface Window { ga: any; } }