diff --git a/modules/gptPreAuction.js b/modules/gptPreAuction.js index ee2b5406453..c351a5181a9 100644 --- a/modules/gptPreAuction.js +++ b/modules/gptPreAuction.js @@ -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 || {}; diff --git a/test/spec/modules/gptPreAuction_spec.js b/test/spec/modules/gptPreAuction_spec.js index c4a81c21d5c..3e8dbfe8d92 100644 --- a/test/spec/modules/gptPreAuction_spec.js +++ b/test/spec/modules/gptPreAuction_spec.js @@ -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: {