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

gptPreAuction: fix bug where adServer object are not set in case of twin ad unit #10330

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 12 additions & 10 deletions modules/gptPreAuction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const appendGptSlots = adUnits => {
}

const adUnitMap = adUnits.reduce((acc, adUnit) => {
acc[adUnit.code] = adUnit;
acc[adUnit.code] = acc[adUnit.code] || [];
acc[adUnit.code].push(adUnit);
return acc;
}, {});

Expand All @@ -25,15 +26,16 @@ export const appendGptSlots = adUnits => {
: isAdUnitCodeMatchingSlot(slot));

if (matchingAdUnitCode) {
const adUnit = adUnitMap[matchingAdUnitCode];
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
adUnit.ortb2Imp.ext = adUnit.ortb2Imp.ext || {};
adUnit.ortb2Imp.ext.data = adUnit.ortb2Imp.ext.data || {};

const context = adUnit.ortb2Imp.ext.data;
context.adserver = context.adserver || {};
context.adserver.name = 'gam';
context.adserver.adslot = sanitizeSlotPath(slot.getAdUnitPath());
adUnitMap[matchingAdUnitCode].forEach((adUnit) => {
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
adUnit.ortb2Imp.ext = adUnit.ortb2Imp.ext || {};
adUnit.ortb2Imp.ext.data = adUnit.ortb2Imp.ext.data || {};

const context = adUnit.ortb2Imp.ext.data;
context.adserver = context.adserver || {};
context.adserver.name = 'gam';
context.adserver.adslot = sanitizeSlotPath(slot.getAdUnitPath());
});
Copy link
Collaborator

@dgirardi dgirardi Aug 21, 2023

Choose a reason for hiding this comment

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

Suggested change
adUnitMap[matchingAdUnitCode].forEach((adUnit) => {
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
adUnit.ortb2Imp.ext = adUnit.ortb2Imp.ext || {};
adUnit.ortb2Imp.ext.data = adUnit.ortb2Imp.ext.data || {};
const context = adUnit.ortb2Imp.ext.data;
context.adserver = context.adserver || {};
context.adserver.name = 'gam';
context.adserver.adslot = sanitizeSlotPath(slot.getAdUnitPath());
});
if (matchingAdUnitCode) {
const adserver = {
name: 'gam',
adslot: sanitizeSlotPath(slot.getAdUnitPath())
};
adUnitMap[matchingAdUnitCode].forEach((adUnit) => {
deepSetValue(adUnit, 'ortb2Imp.ext.data.adserver', Object.assign({}, adUnit.ortb2Imp?.ext?.data?.adserver, adserver));
});
}

Copy link
Contributor Author

@katsuo5 katsuo5 Aug 22, 2023

Choose a reason for hiding this comment

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

@dgirardi
Thanks for review and suggestion.

I can't figure out how to add import {deepSetValue} from '../src/utils.js'; to the GH suggestion

me too.
so I fixed and committed it in local machine.

}
});
};
Expand Down
12 changes: 12 additions & 0 deletions test/spec/modules/gptPreAuction_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ describe('GPT pre-auction module', () => {
expect(adUnit.ortb2Imp.ext.data.adserver).to.deep.equal({ name: 'gam', adslot: 'slotCode2' });
});

it('should add adServer object to context if matching slot is found (in case of twin ad unit)', () => {
window.googletag.pubads().setSlots(testSlots);
const adUnit1 = { code: 'slotCode2', ortb2Imp: { ext: { data: {} } } };
const adUnit2 = { code: 'slotCode2', ortb2Imp: { ext: { data: {} } } };
appendGptSlots([adUnit1, adUnit2]);
expect(adUnit1.ortb2Imp.ext.data.adserver).to.be.an('object');
expect(adUnit1.ortb2Imp.ext.data.adserver).to.deep.equal({ name: 'gam', adslot: 'slotCode2' });

expect(adUnit2.ortb2Imp.ext.data.adserver).to.be.an('object');
expect(adUnit2.ortb2Imp.ext.data.adserver).to.deep.equal({ name: 'gam', adslot: 'slotCode2' });
});

it('will trim child id if mcmEnabled is set to true', () => {
config.setConfig({ gptPreAuction: { enabled: true, mcmEnabled: true } });
window.googletag.pubads().setSlots([
Expand Down