Only Single Ad Unit Loads
Closed this issue · 4 comments
Dropped you an email on a similar issue earlier, got that resolved but now I've ran into something else ðŸ˜
I'm running multiple ad units on one page which share the same data-adunit parameter, however I'm running into an issue where only a single one will load if I use a selector. This is what my HTML looks like:
<div class="adunit-1" data-adunit="alaskadispatch.com" data-dimensions="300x250" data-targeting='{"pos":"a"}'></div>
<div class="adunit-2" data-adunit="alaskadispatch.com" data-dimensions="300x600" data-targeting='{"pos":"b"}'></div>
<div class="adunit-3" data-adunit="alaskadispatch.com" data-dimensions="300x250" data-targeting='{"pos":"c"}'></div>
And the supporting jQuery which is called within inline scripts below each unit on the page:
$(".adunit-1").dfp({
dfpID: '299043',
});
$(".adunit-2").dfp({
dfpID: '299043',
});
$(".adunit-3").dfp({
dfpID: '299043',
});
Everything loads if I make a call like so:
$.dfp({
dfpID: '299043',
});
However I want to selectively choose which ads load. For example if a condition is met I want adunit-1 to load, if not I want it to not load etc. Is there some sort of workaround to this? I've tried a number of possible fixes for this but haven't had any luck.
I'm not sure if the issue is that we're serving multiple line items in the same ad "slot", I'm not hugely knowledgable in DFP. I've created a code pen: http://codepen.io/jamesives/pen/oLvjzZ
Thanks
It looks like doing multiple calls like this with ad units with the same name causes a race condition in the code which means that all of the adunits end up with the same name... breaking the race condition is fairly simple using some setTimeouts as an example....
http://codepen.io/anon/pen/bebVRO
To fix it properly I think I will need to make a global var that is used for the auto naming of ad units.
By the way adding ?google_force_console to the end of your URL is the easiest way to debug these issues normally.... that gave me the error message right away that the adunit name was already defined.
You just saved my life. Thanks for the quick response on this one.
Great plugin btw, you've reduced the footprint of my sites DFP setup to almost nothing. Cheers!
I just updated the codepen above (http://codepen.io/anon/pen/bebVRO) to a new commit I made in a global-uid branch.... seems to work... so I will merge that in when I get a chance.... stops the race condition and means you would not need the setTimeouts to break the race condition.
Legend. Thanks again.