不要在 Chrome 扩展程序中使用 Google 分析

Do not work Google Analytics in Chrome extension

我在扩展中包含 ga.js 时遇到问题。请帮忙。我的代码:

包含清单

"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'"

analytics.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 扩展有关 - 它阻止了分析师脚本,用存根替换它们。存根脚本自然不满足内容安全策略条件。

也许答案对某人有用