0

我使用 Bower 安装了Angulartics以获得 Google Analytics 支持:

bower install --save angulartics
bower install --save angulartics-google-analytics

不幸的是,我的index.html文件现在堆满了大量不需要加载的脚本:

<script src="bower_components/angulartics/src/angulartics-clicky.js"></script>
<script src="bower_components/angulartics/src/angulartics-cnzz.js"></script>
<script src="bower_components/angulartics/src/angulartics-ga-cordova.js"></script>
<script src="bower_components/angulartics/src/angulartics-gtm.js"></script>
<script src="bower_components/angulartics/src/angulartics-piwik.js"></script>
<script src="bower_components/angulartics/src/angulartics-scroll.js"></script>
<script src="bower_components/angulartics/src/angulartics-splunk.js"></script>
<script src="bower_components/angulartics/src/angulartics-woopra.js"></script>
<script src="bower_components/angulartics/src/angulartics-marketo.js"></script>
<script src="bower_components/angulartics/src/angulartics-intercom.js"></script>
<script src="bower_components/angulartics/src/angulartics-inspectlet.js"></script>
<script src="bower_components/angulartics/src/angulartics-newrelic-insights.js"></script>

有没有办法只为其中一个安装 Angulartics (在我的情况下是 Google Analytics)?

4

2 回答 2

0

如果你使用wiredep grunt 插件,你可以使用exclude 选项来确保unsed 文件不会出现在你的发行版中。只需将以下内容添加到您的 Gruntfile.js 中:

wiredep: {
   app: {
       exclude: [
           '/bower_components/angulartics/src/angulartics-baidu.js',
           '/bower_components/angulartics/src/angulartics-clicky.js',
           '/bower_components/angulartics/src/angulartics-cnzz.js',
           '/bower_components/angulartics/src/angulartics-ga-cordova.js',
           '/bower_components/angulartics/src/angulartics-gtm.js',
           '/bower_components/angulartics/src/angulartics-inspectlet.js',
           '/bower_components/angulartics/src/angulartics-intercom.js',
           '/bower_components/angulartics/src/angulartics-marketo.js',
           etc...
       ]
    }
}
于 2016-01-08T15:41:25.687 回答
0

对于谷歌分析,你只需要两个 Angulartics 脚本文件。

  1. angulartics.min.js
  2. angulartics-google-analytics.min.js

只需在您的页面中引用这些内容,它就可以正常工作。Angulartics 不仅支持 Google Analytics,还支持众多供应商,其余的都是支持其他供应商跟踪的插件。

于 2015-12-21T07:12:41.873 回答