jquery.dfp.js
jquery.dfp.js copied to clipboard
Refreshing on AJAX pages
I can't seem to get ads refreshing every 30 seconds and working for ajax pages. I have the ads refreshing but it currently doesn't work once I change pages two or more times. This is what my code looks like right now.
$('.adunit:not(".display-block")').dfp({ dfpID: '52137663', enableSingleRequest: false, afterAllAdsLoaded: function() { setInterval(function() { jQuery.dfp(); }, '30000'); } });
I have also tried with this code:
`
function ads () {
$('.adunit:not(".display-block")').dfp({
dfpID: '52137663/top-ad-gh-music-web',
enableSingleRequest: false,
afterAllAdsLoaded: function() {
setInterval(function() {
jQuery.dfp();
}, '30000');
}
});
}
$(document)
.on('page:load', function () {
ads();
})
.ready(function () {
ads();
});`
I am running a test on this page http://derekcoleman.me/pzzb6/
I have added this code to refresh the ad whenever the URL changes and it helps it work for the first 'page' change but then it doesn't refresh the ad once it's on the new URL.
function hrefHandler(){
this.oldHref = window.location.href;
this.Check;
var that = this;
var detect = function(){
if(that.oldHref!=window.location.href){
ads();
}
};
this.Check = setInterval(function(){ detect() }, 100);
}
var hrefDetection = new hrefHandler();
Your example page seems to be stuck in some kind of loop... its calling it repeatedly over and over 10 times per second at least...
This jquery mobile test I put together a while back seems to have the same kind of idea... and the same issue with ads not showing up after a while... from what I can see though everything is loading correctly... it just appears to be google limiting the amount of times a creative will appear on a single page within a certain amount of time... if you have more creatives it will be fine I think.
http://coop182.github.io/jquery.dfp.js/dfptests/demo1.html
I removed the last bit of code that was checking if the URL has changed so now I have the same exact code as what is on the demo page but it's not working correctly. It is still having the same problem of not working once I navigated to a new 'page'. Derek Riccardo Coleman
On Monday, February 22, 2016 3:59 AM, Matt Cooper <[email protected]> wrote:
This jquery mobile test I put together a while back seems to have the same kind of idea... and the same issue with ads not showing up after a while... from what I can see though everything is loading correctly... it just appears to be google limiting the amount of times a creative will appear on a single page within a certain amount of time... if you have more creatives it will be fine I think.http://coop182.github.io/jquery.dfp.js/dfptests/demo1.html— Reply to this email directly or view it on GitHub.
@derekcoleman i had the similar problem and solved it by implementing it like this first example: https://support.google.com/dfp_premium/answer/4578089
take notice of the googletag.pubads().refresh([slot]);
@samburgers could you please explain for someone who's not that code savvy how you did it? :)
@boooooooorbs You will need to use some of Google's native methods in jquery.dfp.js beforeEachAdLoaded callback like such:
beforeEachAdLoaded: function (adUnit) {
var slots = googletag.pubads().getSlots(); // returns array of Slot objects
var slot = slots[slots.length - 1];
var slotName = adUnit.attr('id');
googletag.display(slotName);
googletag.pubads().refresh([slot]);
}