![](/img/trans.png)
[英]Google ad units (DFP) shows number along with the ad on render. How should I hide that number?
[英]How do you render Google ad units in localhost?
根據研究,2014 年有一個先前的問題( Google adsense 是否可用於 localhost? ),建議添加:
data-adtest="on"
在測試和閱讀評論后,解決方案不再有效。 在廣告單元中:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- responsive_ad -->
<ins class="adsbygoogle"
style="display:block"
data-ad-client="ca-pub-####"
data-ad-slot="######"
data-ad-format="auto"
data-adtest="on"
data-full-width-responsive="true">
</ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
在 Chrome 中測試后,Firefox 和 Safari 呈現一個白框。 搜索后,我無法在產品論壇或任何網站上找到任何解決方案。 如何在 localhost 中測試廣告單元?
我還嘗試了data-adtest="on"
方法,但它對我也不起作用。 我發現了兩種不同的測試方法:
如果您打開了開發者控制台,您會看到出現 403 錯誤。 此處進一步解釋了此錯誤的原因: https : //www.shoutmeloud.com/adsense-403-forbidden-error.html 。 簡而言之: Adsense 爬蟲拒絕 Localhost 。 這就是為什么你有一個空白而不是廣告。
但如果有第三種方式,我也會很高興聽到。
正如另一個答案所暗示的那樣,使用 localhost 以外的主機名很重要。 使用0.0.0.0
可能是一個簡單的選擇。
自 2021 年初以來,谷歌似乎需要明確的 TCF v2.0 同意才能加載任何廣告。 以下代碼段可以包含在應用程序代碼或類似Violentmonkey 的代碼中:
window.__tcfapi = (command, parameter, callback) => {
if (command === 'checkConsent') {
callback(true);
}
if (command === 'addEventListener') {
callback({eventStatus: 'tcloaded', gdprApplies: false}, true);
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.