'How I can preload Google Tag manager ads? To tackle waiting time

I came to know that gtm ads sometimes takes few seconds to fetch and play ads to avoid this I am trying to preload ads initially. So it can be played without getting delayed.

I am trying to preload ads... But I did not find any listener which get called upon calling fetchAD()...

When I called playAD() function all those listener are getting triggered.

function fetchAD() {
    
    googletag.cmd.push(function () {
        // create and assign ad to slot
        rewardedSlot3 = googletag.defineOutOfPageSlot('/1056029/dwi_test_video', googletag.enums.OutOfPageFormat.REWARDED).addService(googletag.pubads());

        googletag.pubads().enableSingleRequest();   // Configure SRA
        googletag.enableServices();     // Start ad fetching    
    });
    
    console.log("fetchAD() func done");
}

function playAD() {

    googletag.display(rewardedSlot3);
        
    console.log("playAD() func done");
}

How am I supposed to preload ad and play it directly without waiting few seconds? Thanks in advance...



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source