Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

callback function for google.ads.search.Ads()

Following the docs on https://developers.google.com/custom-search-ads/docs/implementation-guide I created some code to retrieve ads on a search result page.

This code assumes that you place a container on your webpage where the function

new google.ads.search.Ads(pageOptions, adblock1, adblock2);

appends an iFrame to that may contain ads. I say MAY contain, because sometimes the iFrames stay empty.

Question: Now I need to know whether there are any ads displayed in the containers or not. How do I do this?

  • The call is asynchronous, so when should I initialise the check? (the google reference does not note a callback function)
  • How do I check if there's an ad shown. Because with Javascript I can't look inside the iFrame.

Any suggestions welcome! :)

Regards, Jorn

like image 467
publicJorn Avatar asked Jan 18 '26 08:01

publicJorn


1 Answers

the callback function, that maybe helps you is:

'noAdLoadedCallback':
  function(containerName, adsLoaded) {
      if (!adsLoaded) {
          try {
              ---- do something here ---
          }
          catch (e) {}
      }
  }

You can put this on each adblock.

Cheers Nik

like image 67
Mutatos Avatar answered Jan 20 '26 21:01

Mutatos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!