Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you render Google ad units in localhost?

Per research there was a previous question from 2014 (Is Google adsense available for localhost?) that suggested adding:

data-adtest="on"

and after testing and reading the comments the solution no longer works. In an ad unit:

<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>

After testing in Chrome, Firefox and Safari a white box is rendered. After searching I'm not able to locate any solution in product forums or on any site. How can I test an ad unit in localhost?

like image 729
DᴀʀᴛʜVᴀᴅᴇʀ Avatar asked Jan 04 '19 16:01

DᴀʀᴛʜVᴀᴅᴇʀ


People also ask

Does Google AdSense work on localhost?

Yes it is possible (as of 2015). There is a special parameter, to use Adsense on Localhost without risks.

What is ad unit in Google AdSense?

An ad unit is one or more Google ads displayed as a result of one piece of the AdSense ad code. You can create, customize and manage ad units on the Ads page in your AdSense account. Ad units give you control over where ads appear, and our native ad units offer lots of flexibility in terms of customization.


1 Answers

I also tried the data-adtest="on" approach and it didnt work for me either. I found two different approaches for testing:

  • Using Placeholders, the way most Google Adsense Forum Entry suggesting it. e. g. here: https://productforums.google.com/forum/#!msg/adsense/RLeUEq6na-w/i93-TFVRiHUJ (I've tried it on my own and I was satisfied with the solution)
  • Use your own (dev) domain explained here: https://medium.com/@jeffersonlicet/testing-ads-on-localhost-300215b415d6 (I was not able to tried this on my own, because I dont have a domain)

If you have opened the developer console you would have saw that you got an 403 Error. The reasons for this error are further explained here: https://www.shoutmeloud.com/adsense-403-forbidden-error.html. To make it short: Adsense Crawlers reject Localhost. Thats why you got a white space instead of ads.

But if there is a third way I would also be glad to hear it.

like image 122
tschomacker Avatar answered Sep 20 '22 00:09

tschomacker