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 3 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
17 changes: 14 additions & 3 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -569,6 +573,7 @@ export const internal = {
getRefererInfo,
adagioScriptFromLocalStorageCb,
getCurrentWindow,
supportIObs,
canAccessTopWindow,
isRendererPreferredFromPublisher
};
Expand Down Expand Up @@ -692,15 +697,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
24 changes: 21 additions & 3 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -260,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 = {
Expand All @@ -274,8 +277,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 +757,8 @@ describe('Adagio bid adapter', () => {
pagetype: 'ARTICLE',
category: 'NEWS',
subcategory: 'SPORT',
environment: 'desktop'
environment: 'desktop',
supportIObs: true
},
adUnitCode: 'adunit-code',
mediaTypes: {
Expand Down