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

GPT Pre Auction: setting GPID #7671

Merged
merged 4 commits into from
Nov 10, 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
16 changes: 11 additions & 5 deletions modules/gptPreAuction.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ export const appendPbAdSlot = adUnit => {
const context = adUnit.ortb2Imp.ext.data;
const { customPbAdSlot } = _currentConfig;

if (customPbAdSlot) {
context.pbadslot = customPbAdSlot(adUnit.code, deepAccess(context, 'adserver.adslot'));
// use context.pbAdSlot if set (if someone set it already, it will take precedence over others)
if (context.pbadslot) {
return;
}

// use context.pbAdSlot if set
if (context.pbadslot) {
if (customPbAdSlot) {
context.pbadslot = customPbAdSlot(adUnit.code, deepAccess(context, 'adserver.adslot'));
return;
}

// use data attribute 'data-adslotid' if set
try {
const adUnitCodeDiv = document.getElementById(adUnit.code);
Expand All @@ -78,12 +79,17 @@ export const appendPbAdSlot = adUnit => {
return;
}
context.pbadslot = adUnit.code;
return true;
};

export const makeBidRequestsHook = (fn, adUnits, ...args) => {
appendGptSlots(adUnits);
adUnits.forEach(adUnit => {
appendPbAdSlot(adUnit);
const usedAdUnitCode = appendPbAdSlot(adUnit);
// gpid should be set to itself if already set, or to what pbadslot was (as long as it was not adUnit code)
if (!adUnit.ortb2Imp.ext.gpid && !usedAdUnitCode) {
adUnit.ortb2Imp.ext.gpid = adUnit.ortb2Imp.ext.data.pbadslot;
}
});
return fn.call(this, adUnits, ...args);
};
Expand Down
62 changes: 58 additions & 4 deletions test/spec/modules/gptPreAuction_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,69 @@ describe('GPT pre-auction module', () => {
code: 'slotCode3',
}];

// first two adUnits directly pass in pbadslot => gpid is same
const expectedAdUnits = [{
code: 'adUnit1',
ortb2Imp: { ext: { data: { pbadslot: '12345' } } }
}, {
ortb2Imp: {
ext: {
data: {
pbadslot: '12345'
},
gpid: '12345'
}
}
},
// second adunit
{
code: 'slotCode1',
ortb2Imp: { ext: { data: { pbadslot: '67890', adserver: { name: 'gam', adslot: 'slotCode1' } } } }
ortb2Imp: {
ext: {
data: {
pbadslot: '67890',
adserver: {
name: 'gam',
adslot: 'slotCode1'
}
},
gpid: '67890'
}
}
}, {
code: 'slotCode3',
ortb2Imp: { ext: { data: { pbadslot: 'slotCode3', adserver: { name: 'gam', adslot: 'slotCode3' } } } }
ortb2Imp: {
ext: {
data: {
pbadslot: 'slotCode3',
adserver: {
name: 'gam',
adslot: 'slotCode3'
}
},
gpid: 'slotCode3'
}
}
}];

window.googletag.pubads().setSlots(testSlots);
runMakeBidRequests(testAdUnits);
expect(returnedAdUnits).to.deep.equal(expectedAdUnits);
});

it('should not apply gpid if pbadslot was set by adUnitCode', () => {
const testAdUnits = [{
code: 'noMatchCode',
}];

// first two adUnits directly pass in pbadslot => gpid is same
const expectedAdUnits = [{
code: 'noMatchCode',
ortb2Imp: {
ext: {
data: {
pbadslot: 'noMatchCode'
},
}
}
}];

window.googletag.pubads().setSlots(testSlots);
Expand Down