Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refreshing on AJAX pages #120

Open
derekcoleman opened this issue Feb 19, 2016 · 9 comments
Open

Refreshing on AJAX pages #120

derekcoleman opened this issue Feb 19, 2016 · 9 comments

Comments

@derekcoleman
Copy link

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'); } });

@derekcoleman
Copy link
Author

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();
        });`

@derekcoleman
Copy link
Author

I am running a test on this page http://derekcoleman.me/pzzb6/

@derekcoleman
Copy link
Author

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();

@coop182
Copy link
Owner

coop182 commented Feb 22, 2016

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...

@coop182
Copy link
Owner

coop182 commented Feb 22, 2016

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

@derekcoleman
Copy link
Author

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.

@samburgers
Copy link

@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]);

@boooooooorbs
Copy link

@samburgers could you please explain for someone who's not that code savvy how you did it? :)

@tinyearth
Copy link

@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]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants