簡體   English   中英

您如何在 localhost 中呈現 Google 廣告單元?

[英]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);
    }
};

我嘗試了很多選擇,但沒有奏效。

我看到白屏和 403 錯誤。

我發現解決方法“邊框:1px 純紅色;” 它有效

<ins style=".....   border:1px solid red;"></ins>

我可以看到廣告區域,我將嘗試無邊框制作

我可以看到廣告區

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM