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

Duplicated afterEachAdLoaded when $.dfp() has been called more than once #135

Open
tatai opened this issue Sep 2, 2016 · 4 comments
Open

Comments

@tatai
Copy link

tatai commented Sep 2, 2016

Hi,

First of all, thanks for creating this plugin.

I have a page with an infinite scroll and I have followed the steps given in the instructions and also explained in some issues like #112, but when I create a callback to afterEachAdLoaded, each time I invoke dfp() to define the new ad, afterEachAdLoaded receives a repeated callback.

I have followed the code and I think the issue is related to the pubadsService.addEventListener('slotRenderEnded') made on line 137. This listener is added with each call to dfp().

I cannot show public code right now, but it can be reproduced with:

var options = {
    dfpID: 'xxxxxxxxx',
    enableSingleRequest: false,
    afterEachAdLoaded: function(ad) {
        console.log('afterEachAdLoaded', ad);
    }
};

$(document).ready(function() {
    $.dfp(options);
});

// This event is triggered when a new page is loaded using ajax
$(document).on('new-page-loaded', function($page) {
    console.log('New page');
    $page.find('.adunit').dfp(options);
});

The output shown in the console will be something like:

afterEachAdLoaded banner1
New page
afterEachAdLoaded banner2
afterEachAdLoaded banner2

After some develop I have created a version that distinguishes between "init" and "new ad" calls.

I am going to make a pull request for your consideration. I have made a strong effort to make it backward-compatible with current code.

I have not added the minified version or propose changes in the readme prior to your comments.

@pribeh
Copy link

pribeh commented Oct 5, 2016

@tatai Any chance you'd be able to share the code here? I'm trying to get this going as well but to no avail.

@tatai
Copy link
Author

tatai commented Oct 10, 2016

@pribeh I created pul request #136 but it does not passed all tests so it cannot be evaluated for merging. Hopefully this week or next I will have some time to fix it. Feedback is welcomed

@mkhazov
Copy link

mkhazov commented Nov 11, 2016

#136 didn't help me, slotRenderEnded listener is still being added on each $.dfp call.

@BowlingX
Copy link
Contributor

#143 should fix this issue.

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

4 participants