From ef40e9dda7d3be544be6b00be1bff75c5926c6ce Mon Sep 17 00:00:00 2001 From: Love Sharma Date: Mon, 13 Dec 2021 14:54:10 -0500 Subject: [PATCH] addd GPID support (#7838) Co-authored-by: Love Sharma --- modules/ixBidAdapter.js | 10 +++-- test/spec/modules/ixBidAdapter_spec.js | 62 +++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index a2d690b18ee..6217cd107be 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -680,6 +680,7 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) { if (impressionObjects.length && BANNER in impressionObjects[0]) { const { id, banner: { topframe }, ext } = impressionObjects[0]; + const gpid = impressions[transactionIds[adUnitIndex]].gpid; const _bannerImpression = { id, banner: { @@ -688,10 +689,10 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) { }, } - if (ext.dfp_ad_unit_code) { - _bannerImpression.ext = { - dfp_ad_unit_code: ext.dfp_ad_unit_code - } + if (ext.dfp_ad_unit_code || gpid) { + _bannerImpression.ext = {}; + _bannerImpression.ext.dfp_ad_unit_code = ext.dfp_ad_unit_code; + _bannerImpression.ext.gpid = gpid; } if ('bidfloor' in impressionObjects[0]) { @@ -911,6 +912,7 @@ function createBannerImps(validBidRequest, missingBannerSizes, bannerImps) { bannerImps[validBidRequest.transactionId].ixImps = [] } bannerImps[validBidRequest.transactionId].ixImps.push(imp); + bannerImps[validBidRequest.transactionId].gpid = deepAccess(validBidRequest, 'ortb2Imp.ext.gpid'); } if (ixConfig.hasOwnProperty('detectMissingSizes') && ixConfig.detectMissingSizes) { diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index af8e683de8b..c6579a544fa 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -4,6 +4,7 @@ import { expect } from 'chai'; import { newBidder } from 'src/adapters/bidderFactory.js'; import { spec, storage, ERROR_CODES } from '../../../modules/ixBidAdapter.js'; import { createEidsArray } from 'modules/userId/eids.js'; +import { deepAccess } from '../../../src/utils.js'; describe('IndexexchangeAdapter', function () { const IX_SECURE_ENDPOINT = 'https://htlb.casalemedia.com/cygnus'; @@ -1440,12 +1441,69 @@ describe('IndexexchangeAdapter', function () { expect(dfp_ad_unit_code).to.equal(AD_UNIT_CODE); }); + it('should send gpid in request if ortb2Imp.ext.gpid exists', function () { + const GPID = '/19968336/some-adunit-path'; + const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); + validBids[0].ortb2Imp = { + ext: { + gpid: GPID + } + }; + const requests = spec.buildRequests(validBids, DEFAULT_OPTION); + const { ext: { gpid } } = JSON.parse(requests[0].data.r).imp[0]; + expect(gpid).to.equal(GPID); + }); + it('should not send dfp_adunit_code in request if ortb2Imp.ext.data.adserver.adslot does not exists', function () { + const GPID = '/19968336/some-adunit-path'; + const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); + validBids[0].ortb2Imp = { + ext: { + gpid: GPID + } + }; + const requests = spec.buildRequests(validBids, DEFAULT_OPTION); + const imp = JSON.parse(requests[0].data.r).imp[0]; + expect(deepAccess(imp, 'ext.dfp_ad_unit_code')).to.not.exist; + }); + + it('should not send gpid in request if ortb2Imp.ext.gpid does not exists', function () { + const AD_UNIT_CODE = '/19968336/some-adunit-path'; const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); + validBids[0].ortb2Imp = { + ext: { + data: { + adserver: { + name: 'gam', + adslot: AD_UNIT_CODE + } + } + } + }; const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const { ext } = JSON.parse(requests[0].data.r).imp[0]; + const imp = JSON.parse(requests[0].data.r).imp[0]; + expect(deepAccess(imp, 'ext.gpid')).to.not.exist; + }); - expect(ext).to.not.exist; + it('should send gpid & dfp_adunit_code if they exist in ortb2Imp.ext', function () { + const AD_UNIT_CODE = '/1111/home'; + const GPID = '/1111/home-left'; + const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); + validBids[0].ortb2Imp = { + ext: { + gpid: GPID, + 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]; + expect(deepAccess(imp, 'ext.gpid')).to.equal(GPID); + expect(deepAccess(imp, 'ext.dfp_ad_unit_code')).to.equal(AD_UNIT_CODE); }); it('payload should have correct format and value', function () {