gpt4 book ai didi

javascript - 使用 list v3 将谷歌分析添加到 chrome 扩展中

转载 作者:行者123 更新时间:2023-12-05 01:25:20 25 4
gpt4 key购买 nike

是否可以使用 manifest v3 将 google analytics 添加到 chrome 扩展中?我该怎么做?

我从 stackoverflow 找到这篇文章:Add Google Analytics to a Chrome Extension所以我尝试将代码放入接受的答案中

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

进入我的 manifest.json,但是当我加载我的扩展程序时,我收到了这个错误: 'content_security_policy.extension_pages':指令 'script-源'.

我觉得现在不可能将 google analytics 与 chrome 扩展一起使用,但这很奇怪,因为在 chrome 网上商店仪表板中,我们可以看到这个字段:https://imgur.com/a/PBHGOvu

我错过了什么吗?

最佳答案

我使用这种方式将 google analytics 添加到 list V3 中的 override.html(chrome_url_overrides)popup.html:

override.html:

<head>

// 1- Download from 'https://ssl.google-analytics.com/ga.js' and use locally
<script src="./ga.js"></script>

// 2- Instead of use 'content_security_policy' property in 'manifest.json' add this:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval' http://www.google-analytics.com https://example.com ;style-src 'self' 'unsafe-inline' http://www.google-analytics.com https://example.com; media-src *;img-src *">
// or
<meta http-equiv="Content-Security-Policy" content="default-src *;img-src * 'self' data: https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *;style-src 'self' 'unsafe-inline' *">

</head>

3- 创建 analytics-override.js:

var _gaq = _gaq || [];
_gaq.push(["_setAccount", "UA-01234567-89"]);
_gaq.push(["_trackPageview", "/override.html"]);

4- 在 override.js 中:

window.onload = function(){    
const scriptTag = document.createElement("script");
scriptTag.src = chrome.runtime.getURL("./analytics-override.js");
scriptTag.type = "text/javascript";
document.head.appendChild(scriptTag);
}

希望对你有帮助。

关于javascript - 使用 list v3 将谷歌分析添加到 chrome 扩展中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70908984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com