Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
How to catch error in googletag.cmd.push(function() { googletag.display('div-id'); });?

I am trying to catch the error on
 googletag.cmd.push(function() { googletag.display('div-id'); });

While I know the root of the problem is because the slot is not defined in the head, how can I catch the error? I'm facing a problem where the definedSlot is messy and all over the place so I think catching the error in the googletag.cmd.push would be an easier solution.
Thank you.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can check wether the targeted ID in the googletag defined slots exists in the DOM before displaying it :

    //get all the defined slots
    var definedSlots = googletag.pubads().getSlots();
    //loop through the definedSlots
    for (var x = 0; x < definedSlots.length; x++) {
       //retrieve the targeted ID
       var slotId = definedSlots[x].getSlotId().getDomId();
       //if it exists
       if (document.querySelector('#'+ slotId)) {
          //then dislay it
          googletag.cmd.push(function() { googletag.display(slotId); });
       }
     }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!