Is Google adsense available for localhost?

2019-02-05 20:34发布

问题:

Is it possible to run google adsense ads on a local server as a try out for a example application? I want to implement Google adsense ads in my web application which is running on a localost befor implementing in a live website. If possible then please suggest me the way.

Thank you.

回答1:

Yes it is possible. There is a special parameter, to use Adsense on Localhost without risks.

Today the AdSense code is different. If you want to add the adtest-parameter use data-adtest="on" within an ins block. Here is an example code:

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- XYZ 336 x 280 -->
<ins class="adsbygoogle"
 style="display:inline-block;width:336px;height:280px"
 data-ad-client="ca-pub-XXXXXXXXXXXXX"
 data-adtest="on"
 data-ad-slot="XXXXXXXXXXX"></ins>
<script>
  (adsbygoogle = window.adsbygoogle || []).push({});
</script>


回答2:

You can put this line in the code.

google_adtest = “on”;

as the first line of the code.

test-adsense-ads-on-your-site

Note that you must put the semicolon (;) at the end of this line.

Once you add this line to the code, for the adsense unit, it will be displayed as a test unit and it's impressions won’t be counted.

Very Important Note - Once you are satisfied with the adsense unit, don't forget to remove the line,

google_adtest = “on”;

from its code.

Check out this link http://www.hacktrix.com/2-ways-to-safely-test-google-adsense-ads-on-your-site