Google 分析被导航器阻止

Google Analytics blocked by navigator

我向 heroku 部署了一个 jhipster/angular 应用程序,我想添加 Google 分析,但脚本被浏览器 CSP 阻止。

我尝试直接在应用程序中捆绑脚本,但结果相同

知道为什么吗?我不想更改安全配置

编辑

对于面临同样问题的人,这对我有用

安全配置class:

.contentSecurityPolicy("default-src 'self' www.google-analytics.com www.googletagmanager.com; frame-src 'self' data:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://storage.googleapis.com www.google-analytics.com www.googletagmanager.com; style-src 'self' 'unsafe-inline'; img-src 'self' www.google-analytics.com www.googletagmanager.com data:; font-src 'self' data:")

并在 index.html

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXX"></script>
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'UA-XXXX');
</script>

被默认提供的content security policy. By default the CSP is quite strict in jhipster. You can modify it in SecurityConfiguration. This is the template拦截。

为了进行测试,您还可以完全删除 CSP 语句并加载分析。