Reputation: 231
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
Upvotes: 2
Views: 2699
Reputation: 18402
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);
});
});
Upvotes: 1