Testing Ads on Localhost

Jefferson Licet
2 min readAug 28, 2018

--

Photo by Saketh Garuda on Unsplash

Testing is a fundamental step of software production, but there are difficult things to test in our local environment, one of them is Ads. When you try to render an Ad slot in localhost you will get an empty ad or (if your lucky) a blank div.

Today i’m going to show you how i managed to display and test Google Ad Manager banners in localhost.

Using test credentials

You can use this approach if you want to test your code instead of your Google Slots settings.

In this way you can render and obtain all the information that google callbacks provide, you can also execute actions such as refreshing the banner but you are limited to the sizes and test settings.

Using your own domain

In this approach we are going to edit the /etc/hosts file in order to create an alias between localhost and our production domain. Don’t forget to write your own domain.

$ sudo nano /etc/hosts
Add at the end of the file
127.0.0.1 dev.domain.com
Save and exit.

Now go to http://dev.domain.com and see de magic.

Apparently Prebid, GPT and Adsense use cookies that are necessary to render ads and they are not added in localhost. We must also take into account domain limitations.

I strongly recommend this approach not only for ad testing purposes but for general developing.

--

--