我正在使用Angulartics2。我正在尝试动态设置跟踪代码以具有以下内容:
ga('create', environment.trackingCode, 'auto');
但我找不到办法做到这一点。
我绝对需要从environment.ts
Is there a way to read it in index.html
from script 标签中读取这个变量。
否则,是否可以删除此行并使用 Angulartics2 执行此操作?
我正在使用Angulartics2。我正在尝试动态设置跟踪代码以具有以下内容:
ga('create', environment.trackingCode, 'auto');
但我找不到办法做到这一点。
我绝对需要从environment.ts
Is there a way to read it in index.html
from script 标签中读取这个变量。
否则,是否可以删除此行并使用 Angulartics2 执行此操作?
我终于在这里找到了答案http://tech.webinterpret.com/how-to-make-google-analytics-work-in-a-single-page-application-spa/
window.ga('create', environment.trackingCode, 'auto');
构造app.module.ts
函数。设置属性窗口,否则会抛出错误:
declare global {
interface Window { ga: any; }
}