Question

Does anyone know if it's possible to use one of the GPT API functions to check if a specific slot has loaded or not? I would like to add a slot_loaded CSS class to the iframe or tag div if possible.

I have taken a look at the addEventListener code but I'm not sure how I can use it to work with just one slot as per docs page.

Was it helpful?

Solution

While the event is fired for for 'any' slot on the page, you could check the values for each call to addEventListener, and interrogate the event.slot property. You'll need to test against a value that is available either globally or hard-coded.

Here is a code example from Google:

var targetSlot = googletag.defineSlot(...);
googletag.pubads().addEventListener('slotRenderEnded', function(event) {
    if (event.slot === targetSlot) {
      // Slot specific logic
    }
});'

See: GPT Reference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top