Skip to content

Commit

Permalink
Grid Bid Adapter: Fix GPID priorities (#10315)
Browse files Browse the repository at this point in the history
Issue: #10187
  • Loading branch information
dzhang-criteo committed Aug 3, 2023
1 parent 9d8dc18 commit c2cf122
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 8 deletions.
9 changes: 1 addition & 8 deletions modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,9 @@ export const spec = {
}

if (ortb2Imp.ext) {
impObj.ext.gpid = ortb2Imp.ext.gpid?.toString() || ortb2Imp.ext.data?.pbadslot?.toString() || ortb2Imp.ext.data?.adserver?.adslot?.toString();
if (ortb2Imp.ext.data) {
impObj.ext.data = ortb2Imp.ext.data;
if (impObj.ext.data.adserver && impObj.ext.data.adserver.adslot) {
impObj.ext.gpid = impObj.ext.data.adserver.adslot.toString();
} else if (ortb2Imp.ext.data.pbadslot) {
impObj.ext.gpid = ortb2Imp.ext.data.pbadslot.toString();
}
}
if (ortb2Imp.ext.gpid) {
impObj.ext.gpid = ortb2Imp.ext.gpid.toString();
}
}
}
Expand Down
68 changes: 68 additions & 0 deletions test/spec/modules/gridBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,74 @@ describe('TheMediaGrid Adapter', function () {
});
});

it('should prioritize pbadslot over adslot', function() {
const ortb2Imp = [{
ext: {
data: {
adserver: {
adslot: 'adslot'
}
}
}
}, {
ext: {
data: {
adserver: {
adslot: 'adslot'
},
pbadslot: 'pbadslot'
}
}
}];
const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 2).map((bid, ind) => {
return Object.assign({}, bid, ortb2Imp[ind] ? { ortb2Imp: {...bid.ortb2Imp, ...ortb2Imp[ind]} } : {});
});
const [request] = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest);
expect(request.data).to.be.an('string');
const payload = parseRequest(request.data);
expect(payload.imp[0].ext.gpid).to.equal(ortb2Imp[0].ext.data.adserver.adslot);
expect(payload.imp[1].ext.gpid).to.equal(ortb2Imp[1].ext.data.pbadslot);
});

it('should prioritize gpid over pbadslot and adslot', function() {
const ortb2Imp = [{
ext: {
gpid: 'gpid',
data: {
adserver: {
adslot: 'adslot'
},
pbadslot: 'pbadslot'
}
}
}, {
ext: {
gpid: 'gpid',
data: {
adserver: {
adslot: 'adslot'
}
}
}
}, {
ext: {
gpid: 'gpid',
data: {
pbadslot: 'pbadslot'
}
}
}];
const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 3).map((bid, ind) => {
return Object.assign({}, bid, ortb2Imp[ind] ? { ortb2Imp: {...bid.ortb2Imp, ...ortb2Imp[ind]} } : {});
});
const [request] = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest);
expect(request.data).to.be.an('string');
const payload = parseRequest(request.data);
expect(payload.imp[0].ext.gpid).to.equal(ortb2Imp[0].ext.gpid);
expect(payload.imp[1].ext.gpid).to.equal(ortb2Imp[1].ext.gpid);
expect(payload.imp[2].ext.gpid).to.equal(ortb2Imp[2].ext.gpid);
});

it('should contain imp[].instl if available', function() {
const ortb2Imp = [{
instl: 1
Expand Down

0 comments on commit c2cf122

Please sign in to comment.