2
votes

I am using a googletag.cmd.push in a file which will load a creative as expected

googletag.cmd.push(function() {
        console.log("pushing now from js file with " + AdServerID + " and " + AdUnit);
        googletag.defineSlot('/' + AdServerID + '/' + AdUnit, [[728, 90], [800, 250]], 'div-gpt-ad-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
    });

however placing the script in a document.ready like this and looking in the googlefc

 $(document).ready(function() {
    googletag.cmd.push(function() {
        console.log("pushing now from js file with " + AdServerID + " and " + AdUnit);
        googletag.defineSlot('/' + AdServerID + '/' + AdUnit, [[728, 90], [800, 250]], 'div-gpt-ad-0').addService(googletag.pubads());
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
});

always gives me a

Ad unit did not fetch. Ad unit did not render. Ad fetch count: 0

Unfortunately I have to use a document ready due to first working out which slots are delivered.

Initially I thought it was a scope issue but after a few hours my hair loss has become significant...

Thanks for any pointers anyone can offer, Taff

1
Do you, by any chance, have a DEMO page or could you create a small one? No JS errors btw? - yvanavermaet
Nope, no JS errors apparent in the console. There was although an error which meant the ad unit could not be fetched, apparently though the error was suppressed by the googletag.cmd.push - Taff

1 Answers

1
votes

Easy doing by disabling the initial ads load (googletag.pubads().disableInitialLoad()) and refresh the a slots on document ready:

window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
    googletag.pubads().disableInitialLoad(); // important
    googletag.pubads().enableSingleRequest();
    googletag.enableServices();
});

/** Document ready jQuery **/
$(function () {
    googletag.cmd.push(function() {
        var units = [];
        units.push(googletag.defineSlot(/** .... your ads slots definition */);
        googletag.pubads().refresh(units);
    });
});