Skip to content

deepintent & pubmatic bid adapters: import deals getter from library #13680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions libraries/dealUtils/dealUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isStr, isArray, logWarn } from '../../src/utils.js';

export const addDealCustomTargetings = (imp, dctr, logPrefix = "") => {
if (isStr(dctr) && dctr.length > 0) {
const arr = dctr.split('|').filter(val => val.trim().length > 0);
dctr = arr.map(val => val.trim()).join('|');
imp.ext['key_val'] = dctr;
} else {
logWarn(logPrefix + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
}

export const addPMPDeals = (imp, deals, logPrefix = "") => {
if (!isArray(deals)) {
logWarn(`${logPrefix}Error: bid.params.deals should be an array of strings.`);
return;
}
deals.forEach(deal => {
if (typeof deal === 'string' && deal.length > 3) {
if (!imp.pmp) {
imp.pmp = { private_auction: 0, deals: [] };
}
imp.pmp.deals.push({ id: deal });
} else {
logWarn(`${logPrefix}Error: deal-id present in array bid.params.deals should be a string with more than 3 characters length, deal-id ignored: ${deal}`);
}
});
}
9 changes: 9 additions & 0 deletions modules/deepintentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { generateUUID, deepSetValue, deepAccess, isArray, isFn, isPlainObject, l
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { COMMON_ORTB_VIDEO_PARAMS, formatResponse } from '../libraries/deepintentUtils/index.js';
import { addDealCustomTargetings, addPMPDeals } from '../libraries/dealUtils/dealUtils.js';

const LOG_WARN_PREFIX = 'DeepIntent: ';
const BIDDER_CODE = 'deepintent';
const GVL_ID = 541;
const BIDDER_ENDPOINT = 'https://prebid.deepintent.com/prebid';
Expand Down Expand Up @@ -155,6 +158,12 @@ function buildImpression(bid) {
if (deepAccess(bid, 'mediaTypes.video')) {
impression['video'] = _buildVideo(bid);
}
if (deepAccess(bid, 'params.deals')) {
addPMPDeals(impression, deepAccess(bid, 'params.deals'), LOG_WARN_PREFIX);
}
if (deepAccess(bid, 'params.dctr')) {
addDealCustomTargetings(impression, deepAccess(bid, 'params.dctr'), LOG_WARN_PREFIX);
}
return impression;
}

Expand Down
32 changes: 3 additions & 29 deletions modules/pubmaticBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { isViewabilityMeasurable, getViewability } from '../libraries/percentInV
import { bidderSettings } from '../src/bidderSettings.js';
import { ortbConverter } from '../libraries/ortbConverter/converter.js';
import { NATIVE_ASSET_TYPES, NATIVE_IMAGE_TYPES, PREBID_NATIVE_DATA_KEYS_TO_ORTB, NATIVE_KEYS_THAT_ARE_NOT_ASSETS, NATIVE_KEYS } from '../src/constants.js';
import { addDealCustomTargetings, addPMPDeals } from '../libraries/dealUtils/dealUtils.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -73,8 +74,8 @@ const converter = ortbConverter({
if (!imp.hasOwnProperty('banner') && !imp.hasOwnProperty('video') && !imp.hasOwnProperty('native')) {
return null;
}
if (deals) addPMPDeals(imp, deals);
if (dctr) addDealCustomTargetings(imp, dctr);
if (deals) addPMPDeals(imp, deals, LOG_WARN_PREFIX);
if (dctr) addDealCustomTargetings(imp, dctr, LOG_WARN_PREFIX);
if (rtd?.jwplayer) addJWPlayerSegmentData(imp, rtd.jwplayer);
imp.bidfloor = _parseSlotParam('kadfloor', kadfloor);
imp.bidfloorcur = currency ? _parseSlotParam('currency', currency) : DEFAULT_CURRENCY;
Expand Down Expand Up @@ -375,33 +376,6 @@ const addJWPlayerSegmentData = (imp, jwplayer) => {
imp.ext.key_val = imp.ext.key_val ? `${imp.ext.key_val}|${jwPlayerData}` : jwPlayerData;
};

const addDealCustomTargetings = (imp, dctr) => {
if (isStr(dctr) && dctr.length > 0) {
const arr = dctr.split('|').filter(val => val.trim().length > 0);
dctr = arr.map(val => val.trim()).join('|');
imp.ext['key_val'] = dctr;
} else {
logWarn(LOG_WARN_PREFIX + 'Ignoring param : dctr with value : ' + dctr + ', expects string-value, found empty or non-string value');
}
}

const addPMPDeals = (imp, deals) => {
if (!isArray(deals)) {
logWarn(`${LOG_WARN_PREFIX}Error: bid.params.deals should be an array of strings.`);
return;
}
deals.forEach(deal => {
if (typeof deal === 'string' && deal.length > 3) {
if (!imp.pmp) {
imp.pmp = { private_auction: 0, deals: [] };
}
imp.pmp.deals.push({ id: deal });
} else {
logWarn(`${LOG_WARN_PREFIX}Error: deal-id present in array bid.params.deals should be a string with more than 3 characters length, deal-id ignored: ${deal}`);
}
});
}

const updateRequestExt = (req, bidderRequest) => {
const allBiddersList = ['all'];
const allowedBiddersList = bidderSettings.get(bidderRequest.bidderCode, 'allowedAlternateBidderCodes');
Expand Down
113 changes: 113 additions & 0 deletions test/spec/modules/deepintentBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,117 @@ describe('Deepintent adapter', function () {
expect(data.regs.coppa).to.equal(1);
});
});
describe('deals functionality', function() {
it('should add PMP deals when valid deals array is provided', function() {
const requestWithDeals = [{
bidder: 'deepintent',
bidId: 'test-bid-id',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
tagId: '100013',
deals: ['deal1234', 'deal5678']
}
}];

const bRequest = spec.buildRequests(requestWithDeals);
const data = JSON.parse(bRequest.data);

expect(data.imp[0].pmp).to.be.an('object');
expect(data.imp[0].pmp.private_auction).to.equal(0);
expect(data.imp[0].pmp.deals).to.be.an('array').with.length(2);
expect(data.imp[0].pmp.deals[0].id).to.equal('deal1234');
expect(data.imp[0].pmp.deals[1].id).to.equal('deal5678');
});

it('should filter out invalid deal IDs and handle edge cases', function() {
const requestWithMixedDeals = [{
bidder: 'deepintent',
bidId: 'test-bid-id',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
tagId: '100013',
deals: ['abc', 'valid_deal', 12345, null, 'xy']
}
}];

const bRequest = spec.buildRequests(requestWithMixedDeals);
const data = JSON.parse(bRequest.data);

expect(data.imp[0].pmp.deals).to.be.an('array').with.length(1);
expect(data.imp[0].pmp.deals[0].id).to.equal('valid_deal');
});

it('should not add pmp when deals is not a valid array', function() {
const requestWithInvalidDeals = [{
bidder: 'deepintent',
bidId: 'test-bid-id',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
tagId: '100013',
deals: 'not-an-array'
}
}];

const bRequest = spec.buildRequests(requestWithInvalidDeals);
const data = JSON.parse(bRequest.data);

expect(data.imp[0].pmp).to.be.undefined;
});

it('should add and clean deal custom targeting', function() {
const requestWithDctr = [{
bidder: 'deepintent',
bidId: 'test-bid-id',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
tagId: '100013',
dctr: ' key1=val1 | key2=val2 | | key3=val3 '
}
}];

const bRequest = spec.buildRequests(requestWithDctr);
const data = JSON.parse(bRequest.data);

expect(data.imp[0].ext.key_val).to.equal('key1=val1|key2=val2|key3=val3');
});

it('should handle both deals and dctr together', function() {
const requestWithBoth = [{
bidder: 'deepintent',
bidId: 'test-bid-id',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
params: {
tagId: '100013',
deals: ['deal1234'],
dctr: 'key1=val1|key2=val2'
}
}];

const bRequest = spec.buildRequests(requestWithBoth);
const data = JSON.parse(bRequest.data);

expect(data.imp[0].pmp.deals[0].id).to.equal('deal1234');
expect(data.imp[0].ext.key_val).to.equal('key1=val1|key2=val2');
});
});
});