Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda