Skip to content

Commit

Permalink
gptPreAuction: fix bug where adServer object are not set in case of t…
Browse files Browse the repository at this point in the history
…win ad unit (#10330)

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

* refactor(GH suggestion): ortb2Imp.ext.data.adserver parameter settings
  • Loading branch information
katsuo5 authored Aug 29, 2023
1 parent ff42caf commit 0138111
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
28 changes: 17 additions & 11 deletions modules/gptPreAuction.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import {deepAccess, isAdUnitCodeMatchingSlot, isGptPubadsDefined, logInfo, pick} from '../src/utils.js';
import {
deepAccess,
isAdUnitCodeMatchingSlot,
isGptPubadsDefined,
logInfo,
pick,
deepSetValue
} from '../src/utils.js';
import {config} from '../src/config.js';
import {getHook} from '../src/hook.js';
import {find} from '../src/polyfill.js';
Expand All @@ -15,7 +22,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 +33,13 @@ 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());
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));
});
}
});
};
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

0 comments on commit 0138111

Please sign in to comment.