Skip to content

Commit

Permalink
Merge pull request #98 from theonion/eager-correlators
Browse files Browse the repository at this point in the history
update refreshslots to only update correlator when there are no eager…
  • Loading branch information
brycedorn authored Dec 7, 2018
2 parents 9d1f011 + 9990bf1 commit 1576230
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,18 @@ AdManager.prototype.refreshSlots = function (slotsToLoad) {
return;
}

this.googletag.pubads().updateCorrelator();
// If any of the ads are eager loaded, don't update the correlator
var updateCorrelator = true;
for (var i = 0; i < slotsToLoad.length; i++) {
if (slotsToLoad[i].eagerLoad) {
updateCorrelator = false;
break;
}
}

if (updateCorrelator) {
this.googletag.pubads().updateCorrelator();
}

var useIAS = typeof this.__iasPET !== 'undefined' && this.options.iasEnabled;
var useIndex = typeof window.headertag !== 'undefined' && window.headertag.apiReady === true && this.options.indexExchangeEnabled;
Expand Down
26 changes: 21 additions & 5 deletions src/manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ describe('AdManager', function() {

// Setup method utilized by #refreshSlot & #refreshSlots tests
function adSlotSetup(){
var baseContainer, container1, adSlot1, stubSlot, variableReferences;
var baseContainer, container1, adSlot1, stubSlot, eagerStubSlot, variableReferences;
baseContainer = document.createElement('div');
container1 = document.createElement('div');
container1.className ='expected';
Expand All @@ -1557,12 +1557,16 @@ describe('AdManager', function() {
setTargeting: function () {},
getOutOfPage: function () { return false; }
};

eagerStubSlot = Object.assign({}, stubSlot, { eagerLoad: true });

variableReferences = {
baseContainer: baseContainer,
container1: container1,
adSlot1: adSlot1,
stubSlot: stubSlot
}
stubSlot: stubSlot,
eagerStubSlot: eagerStubSlot
};

adManager.slots = {
'dfp-ad-1': stubSlot
Expand Down Expand Up @@ -1628,20 +1632,21 @@ describe('AdManager', function() {
});

context('always', function() {
var adSlot, stubSlot, baseContainer;
var adSlot, stubSlot, eagerStubSlot, baseContainer;

beforeEach(function(){
var setupRefs = adSlotSetup();
adSlot = setupRefs.adSlot1;
stubSlot = setupRefs.stubSlot;
eagerStubSlot = setupRefs.eagerStubSlot;
baseContainer = setupRefs.baseContainer;
});

afterEach(function() {
$(baseContainer).remove();
});

it('always updates the correlator', function() {
it('updates the correlator when ad is not eager loaded', function() {
adManager = AdManagerWrapper.init({ iasEnabled: true });
TestHelper.stub(adManager, 'fetchAmazonBids');
TestHelper.stub(adManager, 'fetchIasTargeting');
Expand All @@ -1651,6 +1656,17 @@ describe('AdManager', function() {

expect(adManager.googletag.pubads().updateCorrelator.called).to.be.true;
});

it('does not update the correlator when ad is eager loaded', function() {
adManager = AdManagerWrapper.init({ iasEnabled: true });
TestHelper.stub(adManager, 'fetchAmazonBids');
TestHelper.stub(adManager, 'fetchIasTargeting');
TestHelper.stub(adManager, 'setIndexTargetingForSlots');

adManager.refreshSlots([eagerStubSlot]);

expect(adManager.googletag.pubads().updateCorrelator.called).to.be.false;
});
});

context('> prebidEnabled', function(){
Expand Down

0 comments on commit 1576230

Please sign in to comment.