From 9cffe9385201ad1bfaa68a97011ac67bd439e96c Mon Sep 17 00:00:00 2001 From: Olivier Date: Tue, 8 Dec 2020 00:16:15 +0100 Subject: [PATCH 1/5] Detect support for intersectionObserver --- modules/adagioBidAdapter.js | 9 ++++++++- test/spec/modules/adagioBidAdapter_spec.js | 21 ++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/adagioBidAdapter.js b/modules/adagioBidAdapter.js index cab233d5387..d65d02fd7e2 100644 --- a/modules/adagioBidAdapter.js +++ b/modules/adagioBidAdapter.js @@ -495,6 +495,10 @@ function autoDetectEnvironment() { return environment; }; +function supportIObs() { + return !!(internal.getCurrentWindow().IntersectionObserver); +} + function getFeatures(bidRequest, bidderRequest) { const { adUnitCode, params } = bidRequest; const { adUnitElementId } = params; @@ -569,6 +573,7 @@ export const internal = { getRefererInfo, adagioScriptFromLocalStorageCb, getCurrentWindow, + supportIObs, canAccessTopWindow, isRendererPreferredFromPublisher }; @@ -695,12 +700,14 @@ export const spec = { const { organizationId, site, placement } = params; const adUnitElementId = params.adUnitElementId || internal.autoDetectAdUnitElementId(adUnitCode); const environment = params.environment || internal.autoDetectEnvironment(); + const supportIObs = internal.supportIObs(); // insure auto-detected params are kept in `bid` object. bid.params = { ...params, adUnitElementId, - environment + environment, + supportIObs }; const debugData = () => ({ diff --git a/test/spec/modules/adagioBidAdapter_spec.js b/test/spec/modules/adagioBidAdapter_spec.js index 2cf97a1129b..7d8bce6b10a 100644 --- a/test/spec/modules/adagioBidAdapter_spec.js +++ b/test/spec/modules/adagioBidAdapter_spec.js @@ -229,7 +229,8 @@ describe('Adagio bid adapter', () => { placement: 'PAVE_ATF', site: 'SITE-NAME', adUnitElementId: 'gpt-adunit-code', - environment: 'desktop' + environment: 'desktop', + supportIObs: true } }], auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', @@ -249,7 +250,8 @@ describe('Adagio bid adapter', () => { placement: 'PAVE_ATF', site: 'SITE-NAME', adUnitElementId: 'gpt-adunit-code', - environment: 'desktop' + environment: 'desktop', + supportIObs: true } }], auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', @@ -274,6 +276,18 @@ describe('Adagio bid adapter', () => { expect(find(window.top.ADAGIO.pbjsAdUnits, aU => aU.code === 'adunit-code-02')).to.deep.eql(expected[1]); }); + it('should detect IntersectionObserver support', function() { + sandbox.stub(adagio, 'getCurrentWindow').returns(window.top); + sandbox.stub(adagio, 'supportIObs').returns(false); + window.top.ADAGIO = { + ...window.ADAGIO + }; + + spec.isBidRequestValid(bid01); + const validBidReq = find(window.top.ADAGIO.pbjsAdUnits, aU => aU.code === 'adunit-code-01'); + expect(validBidReq.bids[0].params.supportIObs).to.equal(false); + }); + it('should store bids config once by bid in current window', function() { sandbox.stub(adagio, 'getCurrentWindow').returns(window.self); @@ -740,7 +754,8 @@ describe('Adagio bid adapter', () => { pagetype: 'ARTICLE', category: 'NEWS', subcategory: 'SPORT', - environment: 'desktop' + environment: 'desktop', + supportIObs: true }, adUnitCode: 'adunit-code', mediaTypes: { From 3f239db285b26f101b49e2d8df2078d391032de6 Mon Sep 17 00:00:00 2001 From: Olivier Date: Tue, 8 Dec 2020 09:15:23 +0100 Subject: [PATCH 2/5] Fix IE11 --- test/spec/modules/adagioBidAdapter_spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/spec/modules/adagioBidAdapter_spec.js b/test/spec/modules/adagioBidAdapter_spec.js index 7d8bce6b10a..764931ba3e2 100644 --- a/test/spec/modules/adagioBidAdapter_spec.js +++ b/test/spec/modules/adagioBidAdapter_spec.js @@ -262,6 +262,7 @@ describe('Adagio bid adapter', () => { it('should store bids config once by bid in window.top if it accessible', function() { sandbox.stub(adagio, 'getCurrentWindow').returns(window.top); + sandbox.stub(adagio, 'supportIObs').returns(true); // replace by the values defined in beforeEach window.top.ADAGIO = { @@ -279,6 +280,7 @@ describe('Adagio bid adapter', () => { it('should detect IntersectionObserver support', function() { sandbox.stub(adagio, 'getCurrentWindow').returns(window.top); sandbox.stub(adagio, 'supportIObs').returns(false); + window.top.ADAGIO = { ...window.ADAGIO }; @@ -290,6 +292,7 @@ describe('Adagio bid adapter', () => { it('should store bids config once by bid in current window', function() { sandbox.stub(adagio, 'getCurrentWindow').returns(window.self); + sandbox.stub(adagio, 'supportIObs').returns(true); spec.isBidRequestValid(bid01); spec.isBidRequestValid(bid02); From e58475f5383493cbab17d255f4c507e247ba15cc Mon Sep 17 00:00:00 2001 From: Olivier Date: Tue, 8 Dec 2020 18:40:09 +0100 Subject: [PATCH 3/5] Add special params for non standard integration --- modules/adagioBidAdapter.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/adagioBidAdapter.js b/modules/adagioBidAdapter.js index d65d02fd7e2..f74a93525db 100644 --- a/modules/adagioBidAdapter.js +++ b/modules/adagioBidAdapter.js @@ -697,8 +697,11 @@ export const spec = { return false; } - const { organizationId, site, placement } = params; - const adUnitElementId = params.adUnitElementId || internal.autoDetectAdUnitElementId(adUnitCode); + const { organizationId, site } = params; + const adUnitElementId = (params.useAdUnitCodeAsAdUnitElementId === true) + ? adUnitCode + : params.adUnitElementId || internal.autoDetectAdUnitElementId(adUnitCode); + const placement = (params.useAdUnitCodeAsPlacement === true) ? adUnitCode : params.placement; const environment = params.environment || internal.autoDetectEnvironment(); const supportIObs = internal.supportIObs(); @@ -707,6 +710,7 @@ export const spec = { ...params, adUnitElementId, environment, + placement, supportIObs }; From 4121949e95a37c174ce9c2c4f7bf1cbdf166849d Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 9 Dec 2020 19:10:10 +0100 Subject: [PATCH 4/5] Stronger IntersectionObserver detection --- modules/adagioBidAdapter.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/adagioBidAdapter.js b/modules/adagioBidAdapter.js index f74a93525db..6f7feec59c9 100644 --- a/modules/adagioBidAdapter.js +++ b/modules/adagioBidAdapter.js @@ -496,7 +496,9 @@ function autoDetectEnvironment() { }; function supportIObs() { - return !!(internal.getCurrentWindow().IntersectionObserver); + const currentWindow = internal.getCurrentWindow(); + return !!(currentWindow && currentWindow.IntersectionObserver && currentWindow.IntersectionObserverEntry && + currentWindow.IntersectionObserverEntry.prototype && 'intersectionRatio' in currentWindow.IntersectionObserverEntry.prototype); } function getFeatures(bidRequest, bidderRequest) { From f828536d28f9b026318de7a9a075b6e0b7c25052 Mon Sep 17 00:00:00 2001 From: Olivier Date: Wed, 9 Dec 2020 19:26:46 +0100 Subject: [PATCH 5/5] Fix test and add new params to .md file --- modules/adagioBidAdapter.md | 4 ++++ test/spec/modules/adagioBidAdapter_spec.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/modules/adagioBidAdapter.md b/modules/adagioBidAdapter.md index c55a24f1115..aa79338d79e 100644 --- a/modules/adagioBidAdapter.md +++ b/modules/adagioBidAdapter.md @@ -38,6 +38,8 @@ Connects to Adagio demand source to fetch bids. category: 'sport', // Recommended. Category of the content displayed in the page. subcategory: 'handball', // Optional. Subcategory of the content displayed in the page. postBid: false, // Optional. Use it in case of Post-bid integration only. + useAdUnitCodeAsAdUnitElementId: false // Optional. Use it by-pass adUnitElementId and use the adUnit code as value + useAdUnitCodeAsPlacement: false // Optional. Use it to by-pass placement and use the adUnit code as value // Optional debug mode, used to get a bid response with expected cpm. debug: { enabled: true, @@ -76,6 +78,8 @@ Connects to Adagio demand source to fetch bids. category: 'sport', // Recommended. Category of the content displayed in the page. subcategory: 'handball', // Optional. Subcategory of the content displayed in the page. postBid: false, // Optional. Use it in case of Post-bid integration only. + useAdUnitCodeAsAdUnitElementId: false // Optional. Use it by-pass adUnitElementId and use the adUnit code as value + useAdUnitCodeAsPlacement: false // Optional. Use it to by-pass placement and use the adUnit code as value video: { skip: 0 // OpenRTB 2.5 video options defined here override ones defined in mediaTypes. diff --git a/test/spec/modules/adagioBidAdapter_spec.js b/test/spec/modules/adagioBidAdapter_spec.js index 764931ba3e2..0a585caaa1a 100644 --- a/test/spec/modules/adagioBidAdapter_spec.js +++ b/test/spec/modules/adagioBidAdapter_spec.js @@ -144,6 +144,19 @@ describe('Adagio bid adapter', () => { sinon.assert.callCount(utils.logWarn, 1); }); + it('should use adUnit code for adUnitElementId and placement params', function() { + const bid01 = new BidRequestBuilder({ params: { + organizationId: '1000', + site: 'site-name', + useAdUnitCodeAsPlacement: true, + useAdUnitCodeAsAdUnitElementId: true + }}).build(); + + expect(spec.isBidRequestValid(bid01)).to.equal(true); + expect(bid01.params.adUnitElementId).to.equal('adunit-code'); + expect(bid01.params.placement).to.equal('adunit-code'); + }) + it('should return false when a required param is missing', function() { const bid01 = new BidRequestBuilder({ params: { organizationId: '1000',