Last Updated: February 25, 2016
· rizwaniqbal

Detecting when a Google Ad loads on a page

There are times when you are working on an application and the business teams spec says, make the unicorns fly after the user sees the google adsense ad. The unicorns should be stationary till the user has not seen the ad on the page.

Now, Google Ads load inside an iframe and there are many other ways of detecting DOM changes, but, sometimes DOM selectors just don't cut it.

I found the event callback AdsLoadedEvent.ADS_LOADED you can subscribe to.

You can figure out when the ad is successfully returned by subscribing to the event AdsLoadedEvent.ADS_LOADED

adsLoader.addEventListener(AdsLoadedEvent.ADS_LOADED, onAdsLoaded);

There's some documentation available on