Skip to content

Commit

Permalink
Adagio Bid Adapter: hotfix - detect support for intersectionObserver (p…
Browse files Browse the repository at this point in the history
…rebid#6095)

* Detect support for intersectionObserver

* Fix IE11

* Add special params for non standard integration

* Stronger IntersectionObserver detection

* Fix test and add new params to .md file
  • Loading branch information
osazos authored and stsepelin committed May 28, 2021
1 parent c3780a6 commit 6ee35fc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
19 changes: 16 additions & 3 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,12 @@ function autoDetectEnvironment() {
return environment;
};

function supportIObs() {
const currentWindow = internal.getCurrentWindow();
return !!(currentWindow && currentWindow.IntersectionObserver && currentWindow.IntersectionObserverEntry &&
currentWindow.IntersectionObserverEntry.prototype && 'intersectionRatio' in currentWindow.IntersectionObserverEntry.prototype);
}

function getFeatures(bidRequest, bidderRequest) {
const { adUnitCode, params } = bidRequest;
const { adUnitElementId } = params;
Expand Down Expand Up @@ -569,6 +575,7 @@ export const internal = {
getRefererInfo,
adagioScriptFromLocalStorageCb,
getCurrentWindow,
supportIObs,
canAccessTopWindow,
isRendererPreferredFromPublisher
};
Expand Down Expand Up @@ -692,15 +699,21 @@ 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();

// insure auto-detected params are kept in `bid` object.
bid.params = {
...params,
adUnitElementId,
environment
environment,
placement,
supportIObs
};

const debugData = () => ({
Expand Down
4 changes: 4 additions & 0 deletions modules/adagioBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down
37 changes: 34 additions & 3 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -229,7 +242,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',
Expand All @@ -249,7 +263,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',
Expand All @@ -260,6 +275,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 = {
Expand All @@ -274,8 +290,22 @@ 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);
sandbox.stub(adagio, 'supportIObs').returns(true);

spec.isBidRequestValid(bid01);
spec.isBidRequestValid(bid02);
Expand Down Expand Up @@ -740,7 +770,8 @@ describe('Adagio bid adapter', () => {
pagetype: 'ARTICLE',
category: 'NEWS',
subcategory: 'SPORT',
environment: 'desktop'
environment: 'desktop',
supportIObs: true
},
adUnitCode: 'adunit-code',
mediaTypes: {
Expand Down

0 comments on commit 6ee35fc

Please sign in to comment.