Skip to content

Commit

Permalink
IX Bid Adapter: add inventory identifiers info to ixDiag (prebid#8683)
Browse files Browse the repository at this point in the history
Co-authored-by: shahin.rahbariasl <[email protected]>
  • Loading branch information
2 people authored and jorgeluisrocha committed May 18, 2023
1 parent 7b94ad2 commit a91d208
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
43 changes: 42 additions & 1 deletion modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ function bidToVideoImp(bid) {
}

imp.video = videoParamRef ? deepClone(bid.params.video) : {};
// populate imp level transactionId
imp.ext.tid = deepAccess(bid, 'ortb2Imp.ext.tid');

// copy all video properties to imp object
for (const adUnitProperty in videoAdUnitRef) {
Expand Down Expand Up @@ -355,6 +357,9 @@ function bidToNativeImp(bid) {
ver: '1.2'
};

// populate imp level transactionId
imp.ext.tid = deepAccess(bid, 'ortb2Imp.ext.tid');

_applyFloor(bid, imp, NATIVE);

return imp;
Expand Down Expand Up @@ -1126,6 +1131,22 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) {
}
}

// add identifiers info to ixDiag
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;
if (requestSize < MAX_REQUEST_SIZE) {
r.ext.ixdiag.pbadslot = pbaAdSlot;
r.ext.ixdiag.tagid = tagId;
r.ext.ixdiag.adunitcode = adUnitCode;
r.ext.ixdiag.divId = divId;
}
}

const isLastAdUnit = adUnitIndex === transactionIds.length - 1;

if (wasAdUnitImpressionsTrimmed || isLastAdUnit) {
Expand Down Expand Up @@ -1259,6 +1280,13 @@ function createNativeImps(validBidRequest, nativeImps) {
nativeImps[validBidRequest.transactionId].ixImps = [];
nativeImps[validBidRequest.transactionId].ixImps.push(imp);
nativeImps[validBidRequest.transactionId].gpid = deepAccess(validBidRequest, 'ortb2Imp.ext.gpid')
nativeImps[validBidRequest.transactionId].pbadslot = deepAccess(validBidRequest, 'ortb2Imp.ext.data.pbadslot');
nativeImps[validBidRequest.transactionId].tagId = deepAccess(validBidRequest, 'params.tagId');

const adUnitCode = validBidRequest.adUnitCode;
const divId = document.getElementById(adUnitCode) ? adUnitCode : getGptSlotInfoForAdUnitCode(adUnitCode).divId;
nativeImps[validBidRequest.transactionId].adUnitCode = adUnitCode;
nativeImps[validBidRequest.transactionId].divId = divId;
}
}

Expand All @@ -1274,7 +1302,13 @@ 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].tid = deepAccess(validBidRequest, 'ortb2Imp.ext.tid');
videoImps[validBidRequest.transactionId].pbadslot = deepAccess(validBidRequest, 'ortb2Imp.ext.data.pbadslot');
videoImps[validBidRequest.transactionId].tagId = deepAccess(validBidRequest, 'params.tagId');

const adUnitCode = validBidRequest.adUnitCode;
const divId = document.getElementById(adUnitCode) ? adUnitCode : getGptSlotInfoForAdUnitCode(adUnitCode).divId;
videoImps[validBidRequest.transactionId].adUnitCode = adUnitCode;
videoImps[validBidRequest.transactionId].divId = divId;
}
}

Expand Down Expand Up @@ -1302,6 +1336,13 @@ function createBannerImps(validBidRequest, missingBannerSizes, bannerImps) {
bannerImps[validBidRequest.transactionId].gpid = deepAccess(validBidRequest, 'ortb2Imp.ext.gpid');
bannerImps[validBidRequest.transactionId].dfp_ad_unit_code = deepAccess(validBidRequest, 'ortb2Imp.ext.data.adserver.adslot');
bannerImps[validBidRequest.transactionId].tid = deepAccess(validBidRequest, 'ortb2Imp.ext.tid');
bannerImps[validBidRequest.transactionId].pbadslot = deepAccess(validBidRequest, 'ortb2Imp.ext.data.pbadslot');
bannerImps[validBidRequest.transactionId].tagId = deepAccess(validBidRequest, 'params.tagId');

const adUnitCode = validBidRequest.adUnitCode;
const divId = document.getElementById(adUnitCode) ? adUnitCode : getGptSlotInfoForAdUnitCode(adUnitCode).divId;
bannerImps[validBidRequest.transactionId].adUnitCode = adUnitCode;
bannerImps[validBidRequest.transactionId].divId = divId;

// Create IX imps from params.size
if (bannerSizeDefined) {
Expand Down
15 changes: 13 additions & 2 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ describe('IndexexchangeAdapter', function () {
{
bidder: 'ix',
params: {
tagId: '123',
siteId: '123',
size: [300, 250],
},
Expand All @@ -304,7 +305,10 @@ describe('IndexexchangeAdapter', function () {
},
ortb2Imp: {
ext: {
tid: '173f49a8-7549-4218-a23c-e7ba59b47230'
tid: '173f49a8-7549-4218-a23c-e7ba59b47230',
data: {
pbadslot: 'div-gpt-ad-1460505748562-0'
}
}
},
adUnitCode: 'div-gpt-ad-1460505748562-0',
Expand All @@ -320,6 +324,7 @@ describe('IndexexchangeAdapter', function () {
{
bidder: 'ix',
params: {
tagId: '123',
siteId: '456',
video: {
skippable: false,
Expand All @@ -344,7 +349,10 @@ describe('IndexexchangeAdapter', function () {
},
ortb2Imp: {
ext: {
tid: '173f49a8-7549-4218-a23c-e7ba59b47230'
tid: '173f49a8-7549-4218-a23c-e7ba59b47230',
data: {
pbadslot: 'div-gpt-ad-1460505748562-0'
}
}
},
adUnitCode: 'div-gpt-ad-1460505748562-0',
Expand Down Expand Up @@ -2614,6 +2622,9 @@ describe('IndexexchangeAdapter', function () {
expect(diagObj.allu).to.equal(2);
expect(diagObj.version).to.equal('$prebid.version$');
expect(diagObj.url).to.equal('http://localhost:9876/context.html')
expect(diagObj.pbadslot).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].ortb2Imp.ext.data.pbadslot)
expect(diagObj.tagid).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.tagId)
expect(diagObj.adunitcode).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].adUnitCode)
});
});
});
Expand Down

0 comments on commit a91d208

Please sign in to comment.