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 Module: update to include MCM support #7242

Merged
merged 5 commits into from
Aug 2, 2021
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
12 changes: 11 additions & 1 deletion modules/gptPreAuction.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@ export const appendGptSlots = adUnits => {
const context = adUnit.ortb2Imp.ext.data;
context.adserver = context.adserver || {};
context.adserver.name = 'gam';
context.adserver.adslot = slot.getAdUnitPath();
context.adserver.adslot = sanitizeSlotPath(slot.getAdUnitPath());
}
});
};

const sanitizeSlotPath = (path) => {
const gptConfig = config.getConfig('gptPreAuction') || {};

if (gptConfig.mcmEnabled) {
return path.replace(/(^\/\d*),\d*\//, '$1/');
}

return path;
}

export const appendPbAdSlot = adUnit => {
adUnit.ortb2Imp = adUnit.ortb2Imp || {};
adUnit.ortb2Imp.ext = adUnit.ortb2Imp.ext || {};
Expand Down
25 changes: 25 additions & 0 deletions test/spec/modules/gptPreAuction_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ describe('GPT pre-auction module', () => {
expect(adUnit.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([
makeSlot({ code: '/12345,21212/slotCode1', divId: 'div1' }),
makeSlot({ code: '/12345,21212/slotCode2', divId: 'div2' }),
makeSlot({ code: '/12345,21212/slotCode3', divId: 'div3' })
]);
const adUnit = { code: '/12345,21212/slotCode2', ortb2Imp: { ext: { data: {} } } };
appendGptSlots([adUnit]);
expect(adUnit.ortb2Imp.ext.data.adserver).to.be.an('object');
expect(adUnit.ortb2Imp.ext.data.adserver).to.deep.equal({ name: 'gam', adslot: '/12345/slotCode2' });
});

it('will not trim child id if mcmEnabled is not set to true', () => {
window.googletag.pubads().setSlots([
makeSlot({ code: '/12345,21212/slotCode1', divId: 'div1' }),
makeSlot({ code: '/12345,21212/slotCode2', divId: 'div2' }),
makeSlot({ code: '/12345,21212/slotCode3', divId: 'div3' })
]);
const adUnit = { code: '/12345,21212/slotCode2', ortb2Imp: { ext: { data: {} } } };
appendGptSlots([adUnit]);
expect(adUnit.ortb2Imp.ext.data.adserver).to.be.an('object');
expect(adUnit.ortb2Imp.ext.data.adserver).to.deep.equal({ name: 'gam', adslot: '/12345,21212/slotCode2' });
});

it('should use the customGptSlotMatching function if one is given', () => {
config.setConfig({
gptPreAuction: {
Expand Down