我在扩展中包含 ga.js 时遇到问题。请帮忙。我的代码:
包括 list
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'"
分析.js
var _AnalyticsCode = 'UA-XXX';//instead XXX my number
var _gaq = _gaq || [];
_gaq.push(['_setAccount', _AnalyticsCode]);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
该脚本在 2 页中添加 - popup.html 和 options.html。 弹出窗口没问题 ,但选项页面显示:
Refused to load the script 'data:application/javascript;base64,dmFyIHVyY2hpblRyYWNrZXI9ZnVuY3Rpb24oKXt9…JVcmw6ZnVuY3Rpb24obyl7cmV0dXJuIG87fSxfdHJhY2tFdmVudDpmdW5jdGlvbigpe319fX07' because it violates the following Content Security Policy directive: "script-src 'self' https://ssl.google-analytics.com".
最佳答案
嗯,这个问题与使用 Ghostery 扩展有关 - 它阻止分析师脚本,用 stub 替换它们。自然, stub 脚本不满足内容安全策略条件。
也许答案对某人有用
关于google-chrome-extension - 不要在 Chrome 扩展程序中使用 Google Analytics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29318313/