javascript - 在 Chrome 扩展程序中实现广告?

标签 javascript google-chrome google-chrome-extension

根据 Google 开发者计划政策 (https://developer.chrome.com/webstore/program_policies),将广告添加到您的 chrome 扩展中是完全可以接受的:

Ads must be presented in context or clearly state which app or extension they are bundled with. Ads must also be easily removable by either adjusting the settings or uninstalling the app or extension altogether. Ads may not simulate or impersonate system notifications or warnings.

因此,我正在尝试添加广告,为此我正在使用 Chitika,因为 AdSense 是不允许的。我花了很长时间才接近广告,我不得不编辑缩小的文件等等,以符合 Chrome 扩展 list content_security_policy .无论如何,截至目前,只有 1 家公司的广告显示,但其余的都被阻止并显示错误消息:

getads.js:340 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' https://www.google-analytics.com https://secure.adnxs.com https://gum.criteo.com https://ib.adnxs.com https://mm.chitika.net https://cdn.chitika.net". Either the 'unsafe-inline' keyword, a hash ('sha256-KaerrywnDX+trLhtIG9qlTDyP6iiK4PCLN7LWCvctFc='), or a nonce ('nonce-...') is required to enable inline execution.

我该怎么做才能解决这个问题?我试过添加 keyworkd unsafe-inline但我只收到另一条错误消息:

Ignored insecure CSP value "'unsafe-inline'" in directive 'object-src'.

此时我能做什么?我并不能真正控制广告是如何嵌入到我的软件中的,所以我有点受限。有人有想法吗?如果没有,是否有其他广告平台可以与 Chrome 扩展程序配合使用?我不想要任何烦人的东西.. 只是一个 320x50 的广告或其他东西.. 它变得如此令人沮丧,因为我的 chrome 扩展程序每月有 800 万次页面展示,但我无法产生任何收入!

感谢您的帮助。

编辑:这是我的广告代码:

( function() {
if (window.CHITIKA === undefined) { window.CHITIKA = { 'units' : [] }; };
var unit = {"calltype":"async[2]","publisher":"USER_NAME","width":300,"height":250,"sid":"Chitika Default"};
var placement_id = window.CHITIKA.units.length;
window.CHITIKA.units.push(unit);
document.write('<div id="chitikaAdBlock-' + placement_id + '"></div>');
}());

你必须包括:

<script type="text/javascript" src="../../js/getads.js" async></script>可以在这里找到:http://cdn.chitika.net/getads.js .我用 https 替换了所有域名版本。

编辑 2:我的 content_security_policy看起来像这样:

"content_security_policy": "script-src 'self' https://www.google-analytics.com https://secure.adnxs.com https://gum.criteo.com https://ib.adnxs.com https://mm.chitika.net https://cdn.chitika.net; object-src 'self'",

最佳答案

关于 developer program policies您可以在网站上找到以下备注:

Currently, AdSense may not be used to serve ads in Chrome Extensions or Chrome Apps, per AdSense policies.

所以实际上这意味着现在您不能在 chrome 扩展程序中使用广告。

关于javascript - 在 Chrome 扩展程序中实现广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38516478/

相关文章:

google-chrome - chrome.extension.onRequest 是否已弃用?

javascript - Chrome 扩展中后台页面和弹出页面之间的通信

google-chrome-extension - chrome 扩展在启动时触发警报

google-chrome - 视觉 : Chrome tab crashes when trying to display a long string

javascript - jQuery 表单验证适用于 Mozilla 和 Internet Explorer,但不适用于 Chrome 或 Safari

javascript - JQuery 前置函数

javascript - Ionic 2 Angular 2 - 无法从方法访问 NavController

javascript - Jasmine:模拟单例的内部方法

javascript - 对filter()函数的澄清;怎么运行的

image - 图片数据 : URI invalid