Skip to content

Commit

Permalink
bidder specific handling removal
Browse files Browse the repository at this point in the history
move bidder specific handling to ortb2
  • Loading branch information
nouchy committed May 18, 2023
1 parent 1e25e29 commit 6daebf3
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ typings/

# MacOS system files
.DS_Store
package-lock.json
package-lock.json
107 changes: 38 additions & 69 deletions modules/sirdataRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export function applyBidderOrtb2Sda(ortb2Fragments, bidder, type, segments, segt

export function setBidderOrtb2(bidderOrtb2Fragments, bidder, path, segments) {
try {
if (isEmpty(segments)) { return; }
if (isEmpty(segments)) { return false; }
let ortb2Conf = {};
deepSetValue(ortb2Conf, path, segments || {});
mergeDeep(bidderOrtb2Fragments, {[bidder]: ortb2Conf});
Expand Down Expand Up @@ -254,7 +254,7 @@ export function getSegAndCatsArray(data, minScore, pid) {
return sirdataData;
}

export function applySdaGetSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit) {
export function applySdaGetSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit) {
// only share SDA data if whitelisted
if (!biddersParamsExist || indexFound) {
// SDA Publisher
Expand All @@ -269,7 +269,8 @@ export function applySdaGetSpecificData(data, sirdataList, biddersParamsExist, m
if (data.shared_taxonomy && data.shared_taxonomy[curationId]) {
// Get Bidder Specific Data
let curationData = getSegAndCatsArray(data.shared_taxonomy[curationId], minScore, null);
sirdataList = sirdataList.concat(curationData.segments).concat(curationData.categories);
sirdataData.segments = sirdataData.segments.concat(curationData.segments);
sirdataData.categories = sirdataData.categories.concat(curationData.categories);

// SDA Partners
let curationDataForSDA = getSegAndCatsArray(data.shared_taxonomy[curationId], minScore, curationId);
Expand All @@ -278,19 +279,22 @@ export function applySdaGetSpecificData(data, sirdataList, biddersParamsExist, m
}

// Apply custom function or return Bidder Specific Data if publisher is ok
if (sirdataList && sirdataList.length > 0 && (!biddersParamsExist || indexFound)) {
if (!biddersParamsExist || indexFound) {
if (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('customFunction')) {
return loadCustomFunction(moduleConfig.params.bidders[bidderIndex].customFunction, adUnit, sirdataList, data, bid);
return loadCustomFunction(moduleConfig.params.bidders[bidderIndex].customFunction, adUnit, sirdataData, data, bid);
} else {
return sirdataList;
return sirdataData;
}
}
}

export function applySdaAndDefaultSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit) {
let specificData = applySdaGetSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
if (specificData && specificData.length > 0) {
setBidderOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'user.ext.data', {sd_rtd: specificData});
export function applySdaAndDefaultSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit) {
sirdataData = applySdaGetSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
if (sirdataData.segments && sirdataData.segments.length > 0) {
setBidderOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'user.ext.data', {sd_rtd: sirdataData.segments});
}
if (sirdataData.categories && sirdataData.categories.length > 0) {
setBidderOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'site.ext.data', {sd_rtd: sirdataData.categories});
}
}

Expand All @@ -301,8 +305,6 @@ export function addSegmentData(reqBids, data, moduleConfig, onDone) {
const globalMinScore = moduleConfig.params.hasOwnProperty('contextualMinRelevancyScore') ? moduleConfig.params.contextualMinRelevancyScore : 30;
var sirdataData = getSegAndCatsArray(data, globalMinScore, null);

const sirdataList = sirdataData.segments.concat(sirdataData.categories);

const biddersParamsExist = (!!(moduleConfig.params && moduleConfig.params.bidders));

// Global ortb2 SDA
Expand All @@ -320,15 +322,17 @@ export function addSegmentData(reqBids, data, moduleConfig, onDone) {
if (typeof window.googletag !== 'undefined' && (moduleConfig.params.setGptKeyValues || !moduleConfig.params.hasOwnProperty('setGptKeyValues'))) {
try {
let gptCurationId = (moduleConfig.params.gptCurationId ? moduleConfig.params.gptCurationId : (partnerIds['sdRtdForGpt'] ? partnerIds['sdRtdForGpt'] : null));
let sirdataMergedList = sirdataList;
let sirdataMergedList = sirdataData.segments.concat(sirdataData.categories);
if (gptCurationId && data.shared_taxonomy && data.shared_taxonomy[gptCurationId]) {
let gamCurationData = getSegAndCatsArray(data.shared_taxonomy[gptCurationId], globalMinScore, null);
sirdataMergedList = sirdataMergedList.concat(gamCurationData.segments).concat(gamCurationData.categories);
}
window.googletag.pubads().getSlots().forEach(function (n) {
if (typeof n.setTargeting !== 'undefined' && sirdataMergedList && sirdataMergedList.length > 0) {
n.setTargeting('sd_rtd', sirdataMergedList);
}
window.googletag.cmd.push(function() {
window.googletag.pubads().getSlots().forEach(function (n) {
if (typeof n.setTargeting !== 'undefined' && sirdataMergedList && sirdataMergedList.length > 0) {
n.setTargeting('sd_rtd', sirdataMergedList);
}
});
});
} catch (e) {
logError(e);
Expand All @@ -340,18 +344,13 @@ export function addSegmentData(reqBids, data, moduleConfig, onDone) {
var indexFound = false;

adUnits.forEach(adUnit => {
if (!biddersParamsExist && !deepAccess(adUnit, 'ortb2Imp.ext.data.sd_rtd')) {
deepSetValue(adUnit, 'ortb2Imp.ext.data.sd_rtd', sirdataList);
}

adUnit.hasOwnProperty('bids') && adUnit.bids.forEach(bid => {
bidderIndex = (moduleConfig.params.hasOwnProperty('bidders') ? findIndex(moduleConfig.params.bidders, function (i) {
return i.bidder === bid.bidder;
}) : false);
indexFound = (!!(typeof bidderIndex == 'number' && bidderIndex >= 0));
try {
let minScore = (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('contextualMinRelevancyScore') ? moduleConfig.params.bidders[bidderIndex].contextualMinRelevancyScore : globalMinScore);
let specificData = null;

switch (bid.bidder) {
case 'appnexus':
Expand All @@ -370,57 +369,24 @@ export function addSegmentData(reqBids, data, moduleConfig, onDone) {
case 'msq_classic':
case 'msq_max':
case '366_apx':
specificData = applySdaGetSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
if (specificData && specificData.length > 0) {
deepSetValue(bid, 'params.keywords.sd_rtd', specificData);
sirdataData = applySdaGetSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
if (sirdataData.segments && sirdataData.segments.length > 0) {
setBidderOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'user.keywords', 'sd_rtd=' + sirdataData.segments.join(',sd_rtd='));
}
break;

case 'smartadserver':
case 'smart':
specificData = applySdaGetSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
if (specificData && specificData.length > 0) {
var target = [];
if (bid.hasOwnProperty('params') && bid.params.hasOwnProperty('target')) {
target.push(bid.params.target);
}
specificData.forEach(function (entry) {
if (target.indexOf('sd_rtd=' + entry) === -1) {
target.push('sd_rtd=' + entry);
}
});
deepSetValue(bid, 'params.target', target.join(';'));
}
break;

case 'ix':
specificData = applySdaGetSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
let ixConfig = config.getConfig('ix.firstPartyData.sd_rtd');
if (!ixConfig && specificData && specificData.length > 0) {
let cappIxCategories = [];
let ixLength = 0;
let ixLimit = (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('sizeLimit') ? moduleConfig.params.bidders[bidderIndex].sizeLimit : 1000);
// Push ids For publisher use and for curation if exists but limit size because the bidder uses GET parameters
specificData.forEach(function (entry) {
if (ixLength < ixLimit) {
cappIxCategories.push(entry);
ixLength += entry.toString().length;
}
});
config.setConfig({ix: {firstPartyData: {sd_rtd: cappIxCategories}}});
if (sirdataData.categories && sirdataData.categories.length > 0) {
setBidderOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'site.content.keywords', 'sd_rtd=' + sirdataData.categories.join(',sd_rtd='));
}
break;

case 'proxistore':
specificData = applySdaGetSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
if (specificData && specificData.length > 0) {
let psCurationId = (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('curationId') ? moduleConfig.params.bidders[bidderIndex].curationId : (partnerIds[bid.bidder] ? partnerIds[bid.bidder] : null));
if (!data.shared_taxonomy || !data.shared_taxonomy[psCurationId]) {
data.shared_taxonomy[psCurationId] = {segments: [], contextual_categories: {}, segtaxid: null, cattaxid: null};
}
let psCurationData = getSegAndCatsArray(data.shared_taxonomy[psCurationId], minScore, null);
sirdataData = applySdaGetSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
let psCurationId = (indexFound && moduleConfig.params.bidders[bidderIndex].hasOwnProperty('curationId') ? moduleConfig.params.bidders[bidderIndex].curationId : (partnerIds[bid.bidder] ? partnerIds[bid.bidder] : null));
if (!data.shared_taxonomy || !data.shared_taxonomy[psCurationId]) {
data.shared_taxonomy[psCurationId] = {segments: [], contextual_categories: {}, segtaxid: null, cattaxid: null};
}
if ((sirdataData.segments && sirdataData.segments.length > 0) || (sirdataData.categories && sirdataData.categories.length > 0)) {
setBidderOrtb2(reqBids.ortb2Fragments?.bidder, bid.bidder, 'user.ext.data', {
segments: sirdataData.segments.concat(psCurationData.segments),
segments: sirdataData.segments,
contextual_categories: {...data.contextual_categories, ...data.shared_taxonomy[psCurationId].contextual_categories}
});
}
Expand All @@ -445,12 +411,15 @@ export function addSegmentData(reqBids, data, moduleConfig, onDone) {
case 'sublime':
case 'rtbhouse':
case 'mediasquare':
applySdaAndDefaultSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
case 'smartadserver':
case 'smart':
case 'ix':
applySdaAndDefaultSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
break;

default:
if (!biddersParamsExist || (indexFound && (!moduleConfig.params.bidders[bidderIndex].hasOwnProperty('adUnitCodes') || moduleConfig.params.bidders[bidderIndex].adUnitCodes.indexOf(adUnit.code) !== -1))) {
applySdaAndDefaultSpecificData(data, sirdataList, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
applySdaAndDefaultSpecificData(data, sirdataData, biddersParamsExist, minScore, reqBids, bid, moduleConfig, indexFound, bidderIndex, adUnit);
}
}
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6daebf3

Please sign in to comment.