Skip to content

Commit

Permalink
IX Bid Adapter : GPID and Bug Fix (#8698)
Browse files Browse the repository at this point in the history
* beginning work

* wip

* Build GPID manually when dp_ad_unit_code is present and gpid doesnt already exist

* resolve conflict

* remove pb ad slot

* merge conflict resolved

* fixed video warning

Co-authored-by: Chris Corbo <[email protected]>
Co-authored-by: Love Sharma <[email protected]>
  • Loading branch information
3 people authored and ahmadlob committed Jul 27, 2022
1 parent b6f6821 commit 513930a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 14 deletions.
34 changes: 20 additions & 14 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1053,9 +1053,14 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) {
currentImpressionSize = encodeURIComponent(JSON.stringify({ impressionObjects })).length;
}

const gpid = impressions[transactionIds[adUnitIndex]].gpid;
let gpid = impressions[transactionIds[adUnitIndex]].gpid;
const dfpAdUnitCode = impressions[transactionIds[adUnitIndex]].dfp_ad_unit_code;
const tid = impressions[transactionIds[adUnitIndex]].tid
const tid = impressions[transactionIds[adUnitIndex]].tid;
const divId = impressions[transactionIds[adUnitIndex]].divId;

if (!gpid && dfpAdUnitCode && divId) {
gpid = `${dfpAdUnitCode}#${divId}`
}
if (impressionObjects.length && BANNER in impressionObjects[0]) {
const { id, banner: { topframe } } = impressionObjects[0];
const _bannerImpression = {
Expand Down Expand Up @@ -1135,7 +1140,6 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) {
const pbaAdSlot = impressions[transactionIds[adUnitIndex]].pbadslot
const tagId = impressions[transactionIds[adUnitIndex]].tagId
const adUnitCode = impressions[transactionIds[adUnitIndex]].adUnitCode
const divId = impressions[transactionIds[adUnitIndex]].divId
if (pbaAdSlot || tagId || adUnitCode || divId) {
const clonedRObject = deepClone(r);
const requestSize = `${baseUrl}${parseQueryStringParameters({ ...payload, r: JSON.stringify(clonedRObject) })}`.length;
Expand Down Expand Up @@ -1279,7 +1283,8 @@ function createNativeImps(validBidRequest, nativeImps) {
nativeImps[validBidRequest.transactionId] = {};
nativeImps[validBidRequest.transactionId].ixImps = [];
nativeImps[validBidRequest.transactionId].ixImps.push(imp);
nativeImps[validBidRequest.transactionId].gpid = deepAccess(validBidRequest, 'ortb2Imp.ext.gpid')
nativeImps[validBidRequest.transactionId].gpid = deepAccess(validBidRequest, 'ortb2Imp.ext.gpid');
nativeImps[validBidRequest.transactionId].dfp_ad_unit_code = deepAccess(validBidRequest, 'ortb2Imp.ext.data.adserver.adslot');
nativeImps[validBidRequest.transactionId].pbadslot = deepAccess(validBidRequest, 'ortb2Imp.ext.data.pbadslot');
nativeImps[validBidRequest.transactionId].tagId = deepAccess(validBidRequest, 'params.tagId');

Expand All @@ -1302,6 +1307,7 @@ function createVideoImps(validBidRequest, videoImps) {
videoImps[validBidRequest.transactionId].ixImps = [];
videoImps[validBidRequest.transactionId].ixImps.push(imp);
videoImps[validBidRequest.transactionId].gpid = deepAccess(validBidRequest, 'ortb2Imp.ext.gpid');
videoImps[validBidRequest.transactionId].dfp_ad_unit_code = deepAccess(validBidRequest, 'ortb2Imp.ext.data.adserver.adslot');
videoImps[validBidRequest.transactionId].pbadslot = deepAccess(validBidRequest, 'ortb2Imp.ext.data.pbadslot');
videoImps[validBidRequest.transactionId].tagId = deepAccess(validBidRequest, 'params.tagId');

Expand Down Expand Up @@ -1651,7 +1657,17 @@ export const spec = {
}

if (mediaTypeVideoRef && paramsVideoRef) {
const videoImp = bidToVideoImp(bid).video;
const errorList = checkVideoParams(mediaTypeVideoRef, paramsVideoRef);
if (deepAccess(bid, 'mediaTypes.video.context') === OUTSTREAM && isIndexRendererPreferred(bid) && videoImp) {
const outstreamPlayerSize = [deepAccess(videoImp, 'w'), deepAccess(videoImp, 'h')];
const isValidSize = outstreamPlayerSize[0] >= OUTSTREAM_MINIMUM_PLAYER_SIZE[0] && outstreamPlayerSize[1] >= OUTSTREAM_MINIMUM_PLAYER_SIZE[1];
if (!isValidSize) {
logError(`IX Bid Adapter: ${outstreamPlayerSize} is an invalid size for IX outstream renderer`);
return false;
}
}

if (errorList.length) {
errorList.forEach((err) => {
logError(err, { bidder: BIDDER_CODE, code: ERROR_CODES.PROPERTY_NOT_INCLUDED });
Expand All @@ -1660,16 +1676,6 @@ export const spec = {
}
}

const videoImp = bidToVideoImp(bid).video;
if (deepAccess(bid, 'mediaTypes.video.context') === OUTSTREAM && isIndexRendererPreferred(bid) && videoImp) {
const outstreamPlayerSize = [deepAccess(videoImp, 'w'), deepAccess(videoImp, 'h')];
const isValidSize = outstreamPlayerSize[0] >= OUTSTREAM_MINIMUM_PLAYER_SIZE[0] && outstreamPlayerSize[1] >= OUTSTREAM_MINIMUM_PLAYER_SIZE[1];
if (!isValidSize) {
logError(`IX Bid Adapter: ${outstreamPlayerSize} is an invalid size for IX outstream renderer`);
return false;
}
}

return nativeMediaTypeValid(mediaTypeNativeRef);
},

Expand Down
64 changes: 64 additions & 0 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,70 @@ describe('IndexexchangeAdapter', function () {
expect(gpid).to.equal(GPID);
});

it('should still build gpid in request if ortb2Imp.ext.gpid does not exist', function () {
const AD_UNIT_CODE = '/1111/home';
const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID);
sinon.stub(utils, 'getGptSlotInfoForAdUnitCode')
.returns({ gptSlot: AD_UNIT_CODE, divId: 'adunit-code-3-div-id' });
validBids[0].ortb2Imp = {
ext: {
data: {
adserver: {
name: 'gam',
adslot: AD_UNIT_CODE
}
}
}
}
const requests = spec.buildRequests(validBids, DEFAULT_OPTION);
const { ext: { gpid } } = JSON.parse(requests[0].data.r).imp[0];
utils.getGptSlotInfoForAdUnitCode.restore();
expect(gpid).to.equal(`${AD_UNIT_CODE}#adunit-code-3-div-id`);
});

it('should not build gpid if divid doesnt exist when ortb2Imp.ext.gpid does not exist', function () {
const AD_UNIT_CODE = '/1111/home';
const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID);
sinon.stub(utils, 'getGptSlotInfoForAdUnitCode')
.returns({ gptSlot: AD_UNIT_CODE });
validBids[0].ortb2Imp = {
ext: {
data: {
adserver: {
name: 'gam',
adslot: AD_UNIT_CODE
}
}
}
}
const requests = spec.buildRequests(validBids, DEFAULT_OPTION);
const imp = JSON.parse(requests[0].data.r).imp[0];
utils.getGptSlotInfoForAdUnitCode.restore();
expect(imp.ext.gpid).to.be.undefined;
expect(imp.ext.dfp_ad_unit_code).to.equal(AD_UNIT_CODE)
});

it('should not build gpid if dfp ad unit code / divid doesnt exist when ortb2Imp.ext.gpid does not exist', function () {
const AD_UNIT_CODE = '/1111/home';
const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID);
sinon.stub(utils, 'getGptSlotInfoForAdUnitCode')
.returns({});
validBids[0].ortb2Imp = {
ext: {
data: {
adserver: {
name: 'gam',
}
}
}
}
const requests = spec.buildRequests(validBids, DEFAULT_OPTION);

const imp = JSON.parse(requests[0].data.r).imp[0];
utils.getGptSlotInfoForAdUnitCode.restore();
expect(imp.ext).to.be.undefined;
});

it('should send gpid in request if ortb2Imp.ext.gpid exists when no size present', function () {
const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID_PARAM_NO_SIZE);
validBids[0].ortb2Imp = {
Expand Down

0 comments on commit 513930a

Please sign in to comment.