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 Rtd Provider: ensure fallback when adUnit.ortb2Imp is missing #11886

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
16 changes: 9 additions & 7 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,18 @@ function onGetBidRequestData(bidReqConfig, callback, config) {

const adUnits = bidReqConfig.adUnits || getGlobal().adUnits || [];
adUnits.forEach(adUnit => {
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
const ortb2Imp = deepAccess(adUnit, 'ortb2Imp');

// A divId is required to compute the slot position and later to track viewability.
// If nothing has been explicitly set, we try to get the divId from the GPT slot and fallback to the adUnit code in last resort.
if (!deepAccess(ortb2Imp, 'ext.data.divId')) {
const divId = getGptSlotInfoForAdUnitCode(adUnit.code).divId;
let divId = deepAccess(ortb2Imp, 'ext.data.divId')
if (!divId) {
divId = getGptSlotInfoForAdUnitCode(adUnit.code).divId;
deepSetValue(ortb2Imp, `ext.data.divId`, divId || adUnit.code);
}

const slotPosition = getSlotPosition(adUnit);
const slotPosition = getSlotPosition(divId);
deepSetValue(ortb2Imp, `ext.data.adg_rtd.adunit_position`, slotPosition);

// It is expected that the publisher set a `adUnits[].ortb2Imp.ext.data.placement` value.
Expand Down Expand Up @@ -430,7 +433,7 @@ function getElementFromTopWindow(element, currentWindow) {
}
};

function getSlotPosition(adUnit) {
function getSlotPosition(divId) {
if (!isSafeFrameWindow() && !canAccessWindowTop()) {
return '';
}
Expand All @@ -451,16 +454,15 @@ function getSlotPosition(adUnit) {
// window.top based computing
const wt = getWindowTop();
const d = wt.document;
const adUnitElementId = deepAccess(adUnit, 'ortb2Imp.ext.data.divId');

let domElement;

if (inIframe() === true) {
const ws = getWindowSelf();
const currentElement = ws.document.getElementById(adUnitElementId);
const currentElement = ws.document.getElementById(divId);
domElement = getElementFromTopWindow(currentElement, ws);
} else {
domElement = wt.document.getElementById(adUnitElementId);
domElement = wt.document.getElementById(divId);
}

if (!domElement) {
Expand Down
12 changes: 12 additions & 0 deletions test/spec/modules/adagioRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,18 @@ describe('Adagio Rtd Provider', function () {
expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp');
expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.not.exist;
});

it('ensure we create the `ortb2Imp` object if it does not exist', function() {
const configCopy = utils.deepClone(config);
configCopy.params.placementSource = PLACEMENT_SOURCES.ADUNITCODE;

const bidRequest = utils.deepClone(bidReqConfig);
delete bidRequest.adUnits[0].ortb2Imp;

adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy);
expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp');
expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal('div-gpt-ad-1460505748561-0');
});
});
});

Expand Down