如何解决尝试将Google Analytics分析添加到Chrome扩展程序中
我已经浏览了几本other posts,关于将GA添加到我的chrome扩展程序中,但是还没有运气。
到目前为止,这是我的分析代码
analytics.js
(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');
ga('create','UA-XXXXXXX-Y','auto');
ga('send','pageview');
当然,我已经添加了我的GA ID。我一直遇到的主要错误是
analytics.js:3 Refused to load the script 'https://www.google-analytics.com/analytics.js' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem:". Note that 'script-src-elem' was not explicitly set,so 'script-src' is used as a fallback.
关于tutorial,我在manifest.json中添加了以下内容
manifest.json
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
但是,即使将其添加到我的扩展程序中,我仍然会在开发控制台中收到错误消息。
作为参考,这是我的index.html
<html lang="en">
<head>
<title>Polus</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="shortcut icon" type='image/png' href="images/polus_tab_icon.png"/>
<link rel="stylesheet" type="text/css" media="screen" href="./css/calendar-style.css"/>
<script type="text/javascript" src="./js/analytics.js"></script>
</head>
请尽可能提供帮助!
解决方法
您在manifest.json中的内容策略声明无效,因为它引用的域与www.google-analytics.com
不同。另外,要使用Universal Analytics脚本analytics.js
,您还需要调整设置以禁用协议检查。看看本教程https://davidsimpson.me/2014/05/27/add-googles-universal-analytics-tracking-chrome-extension/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。