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

Adagio Bid Adapter: hotfix - detect support for intersectionObserver #6095

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @osazos , I don't see useAdUnitCodeAsPlacement and useAdUnitCodeAsAdUnitElementId params mentioned in the adagioBidAdapter.md, nor do I see them in the Prebid.js docs repo, I think you should describe them there. Also you should also cover these params with some unit test.

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