Skip to content

Commit

Permalink
addd GPID support (prebid#7838)
Browse files Browse the repository at this point in the history
Co-authored-by: Love Sharma <love.sharma@indexexchange.com>
  • Loading branch information
2 people authored and Chris Pabst committed Jan 10, 2022
1 parent 7744b03 commit ef40e9d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 6 deletions.
10 changes: 6 additions & 4 deletions modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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]) {
Expand Down Expand Up @@ -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) {
Expand Down
62 changes: 60 additions & 2 deletions test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit ef40e9d

Please sign in to comment.