2

我在我的 angular2 应用程序中包含了 analytics.js 参考。我已将脚本包含在 index.html 中。问题是我们正在使用 oAuth 登录服务,从那里我们设置一个 cookie 并保存在 Claims 中,根据该 cookie,我们决定是否要为谷歌分析创建 cookie。所以我无法在 index.html 中使用 oAuth cookie。

有没有办法在 typescript(.ts) 文件中包含分析脚本?

    <body>
  <app-root></app-root>
  <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
   </script>
</body>

如果 oAuth cookie 是真的,我只需要在函数之前添加条件,而不是我想运行这个函数。oAuth cookie 保存在可以在我们的 Angular 应用程序中使用的声明中。

4

0 回答 0