Skip to content

Commit 1576230

Browse files
authored
Merge pull request #98 from theonion/eager-correlators
update refreshslots to only update correlator when there are no eager…
2 parents 9d1f011 + 9990bf1 commit 1576230

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

src/manager.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,18 @@ AdManager.prototype.refreshSlots = function (slotsToLoad) {
777777
return;
778778
}
779779

780-
this.googletag.pubads().updateCorrelator();
780+
// If any of the ads are eager loaded, don't update the correlator
781+
var updateCorrelator = true;
782+
for (var i = 0; i < slotsToLoad.length; i++) {
783+
if (slotsToLoad[i].eagerLoad) {
784+
updateCorrelator = false;
785+
break;
786+
}
787+
}
788+
789+
if (updateCorrelator) {
790+
this.googletag.pubads().updateCorrelator();
791+
}
781792

782793
var useIAS = typeof this.__iasPET !== 'undefined' && this.options.iasEnabled;
783794
var useIndex = typeof window.headertag !== 'undefined' && window.headertag.apiReady === true && this.options.indexExchangeEnabled;

src/manager.spec.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ describe('AdManager', function() {
15311531

15321532
// Setup method utilized by #refreshSlot & #refreshSlots tests
15331533
function adSlotSetup(){
1534-
var baseContainer, container1, adSlot1, stubSlot, variableReferences;
1534+
var baseContainer, container1, adSlot1, stubSlot, eagerStubSlot, variableReferences;
15351535
baseContainer = document.createElement('div');
15361536
container1 = document.createElement('div');
15371537
container1.className ='expected';
@@ -1557,12 +1557,16 @@ describe('AdManager', function() {
15571557
setTargeting: function () {},
15581558
getOutOfPage: function () { return false; }
15591559
};
1560+
1561+
eagerStubSlot = Object.assign({}, stubSlot, { eagerLoad: true });
1562+
15601563
variableReferences = {
15611564
baseContainer: baseContainer,
15621565
container1: container1,
15631566
adSlot1: adSlot1,
1564-
stubSlot: stubSlot
1565-
}
1567+
stubSlot: stubSlot,
1568+
eagerStubSlot: eagerStubSlot
1569+
};
15661570

15671571
adManager.slots = {
15681572
'dfp-ad-1': stubSlot
@@ -1628,20 +1632,21 @@ describe('AdManager', function() {
16281632
});
16291633

16301634
context('always', function() {
1631-
var adSlot, stubSlot, baseContainer;
1635+
var adSlot, stubSlot, eagerStubSlot, baseContainer;
16321636

16331637
beforeEach(function(){
16341638
var setupRefs = adSlotSetup();
16351639
adSlot = setupRefs.adSlot1;
16361640
stubSlot = setupRefs.stubSlot;
1641+
eagerStubSlot = setupRefs.eagerStubSlot;
16371642
baseContainer = setupRefs.baseContainer;
16381643
});
16391644

16401645
afterEach(function() {
16411646
$(baseContainer).remove();
16421647
});
16431648

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

16521657
expect(adManager.googletag.pubads().updateCorrelator.called).to.be.true;
16531658
});
1659+
1660+
it('does not update the correlator when ad is eager loaded', function() {
1661+
adManager = AdManagerWrapper.init({ iasEnabled: true });
1662+
TestHelper.stub(adManager, 'fetchAmazonBids');
1663+
TestHelper.stub(adManager, 'fetchIasTargeting');
1664+
TestHelper.stub(adManager, 'setIndexTargetingForSlots');
1665+
1666+
adManager.refreshSlots([eagerStubSlot]);
1667+
1668+
expect(adManager.googletag.pubads().updateCorrelator.called).to.be.false;
1669+
});
16541670
});
16551671

16561672
context('> prebidEnabled', function(){

0 commit comments

Comments
 (0)