-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
1plus x RTD Adapter: remove bidder specific handling enforcement (DC 3634) #10001
Changes from 4 commits
c0bd1f1
d268554
dd6751b
126402e
e2e6aeb
d16fae7
7f474a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ import { config } from '../src/config.js'; | |
import { ajax } from '../src/ajax.js'; | ||
import { | ||
logMessage, logError, | ||
deepAccess, mergeDeep, | ||
isNumber, isArray, deepSetValue | ||
deepAccess, deepSetValue, | ||
isNumber, isArray | ||
} from '../src/utils.js'; | ||
|
||
// Constants | ||
|
@@ -14,7 +14,6 @@ const ORTB2_NAME = '1plusX.com' | |
const PAPI_VERSION = 'v1.0'; | ||
const LOG_PREFIX = '[1plusX RTD Module]: '; | ||
const OPE_FPID = 'ope_fpid' | ||
const LEGACY_SITE_KEYWORDS_BIDDERS = ['appnexus']; | ||
export const segtaxes = { | ||
// cf. https://github.com/InteractiveAdvertisingBureau/openrtb/pull/108 | ||
AUDIENCE: 526, | ||
|
@@ -151,18 +150,7 @@ const getTargetingDataFromPapi = (papiUrl) => { | |
* @param {string[]} topics Represents the topics of the page | ||
* @returns {Object} Object describing the updates to make on bidder configs | ||
*/ | ||
export const buildOrtb2Updates = ({ segments = [], topics = [] }, bidder) => { | ||
// Currently appnexus bidAdapter doesn't support topics in `site.content.data.segment` | ||
// Therefore, writing them in `site.keywords` until it's supported | ||
// Other bidAdapters do fine with `site.content.data.segment` | ||
const writeToLegacySiteKeywords = LEGACY_SITE_KEYWORDS_BIDDERS.includes(bidder); | ||
if (writeToLegacySiteKeywords) { | ||
const site = { | ||
keywords: topics.join(',') | ||
}; | ||
return { site }; | ||
} | ||
|
||
export const buildOrtb2Updates = ({ segments = [], topics = [] }) => { | ||
const userData = { | ||
name: ORTB2_NAME, | ||
segment: segments.map((segmentId) => ({ id: segmentId })) | ||
|
@@ -172,48 +160,49 @@ export const buildOrtb2Updates = ({ segments = [], topics = [] }, bidder) => { | |
segment: topics.map((topicId) => ({ id: topicId })), | ||
ext: { segtax: segtaxes.CONTENT } | ||
} | ||
return { userData, siteContentData }; | ||
// Currently appnexus bidAdapter doesn't support topics in `site.content.data.segment` | ||
// Therefore, writing them in `site.keywords` until it's supported | ||
// Other bidAdapters do fine with `site.content.data.segment` | ||
const siteKeywords = topics.map(topic => `1plusX=${topic}`).join(','); | ||
|
||
return { userData, siteContentData, siteKeywords }; | ||
} | ||
|
||
/** | ||
* Merges the targeting data with the existing config for bidder and updates | ||
* @param {string} bidder Bidder for which to set config | ||
* @param {Object} ortb2Updates Updates to be applied to bidder config | ||
* @param {Object} bidderConfigs All current bidder configs | ||
* @returns {Object} Updated bidder config | ||
* @param {Object} biddersOrtb2 All current bidder configs | ||
*/ | ||
export const updateBidderConfig = (bidder, ortb2Updates, bidderConfigs) => { | ||
const { site, siteContentData, userData } = ortb2Updates; | ||
const bidderConfigCopy = mergeDeep({}, bidderConfigs[bidder]); | ||
export const updateBidderConfig = (bidder, ortb2Updates, biddersOrtb2) => { | ||
const { siteKeywords, siteContentData, userData } = ortb2Updates; | ||
const bidderConfig = deepAccess(biddersOrtb2, bidder); | ||
|
||
if (site) { | ||
// Legacy : cf. comment on buildOrtb2Updates first lines | ||
const currentSite = deepAccess(bidderConfigCopy, 'ortb2.site'); | ||
const updatedSite = mergeDeep(currentSite, site); | ||
deepSetValue(bidderConfigCopy, 'ortb2.site', updatedSite); | ||
{ | ||
// Legacy : cf. comment on buildOrtb2Updates | ||
const siteKeywordsPath = 'site.keywords'; | ||
deepSetValue(bidderConfig, siteKeywordsPath, siteKeywords); | ||
} | ||
|
||
if (siteContentData) { | ||
const siteDataPath = 'ortb2.site.content.data'; | ||
const currentSiteContentData = deepAccess(bidderConfigCopy, siteDataPath) || []; | ||
{ | ||
const siteDataPath = 'site.content.data'; | ||
const currentSiteContentData = deepAccess(bidderConfig, siteDataPath) || []; | ||
const updatedSiteContentData = [ | ||
...currentSiteContentData.filter(({ name }) => name != siteContentData.name), | ||
siteContentData | ||
]; | ||
deepSetValue(bidderConfigCopy, siteDataPath, updatedSiteContentData); | ||
deepSetValue(bidderConfig, siteDataPath, updatedSiteContentData); | ||
} | ||
|
||
if (userData) { | ||
const userDataPath = 'ortb2.user.data'; | ||
const currentUserData = deepAccess(bidderConfigCopy, userDataPath) || []; | ||
{ | ||
const userDataPath = 'user.data'; | ||
const currentUserData = deepAccess(bidderConfig, userDataPath) || []; | ||
const updatedUserData = [ | ||
...currentUserData.filter(({ name }) => name != userData.name), | ||
userData | ||
]; | ||
deepSetValue(bidderConfigCopy, userDataPath, updatedUserData); | ||
deepSetValue(bidderConfig, userDataPath, updatedUserData); | ||
} | ||
|
||
return bidderConfigCopy; | ||
}; | ||
|
||
const setAppnexusAudiences = (audiences) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is no longer needed since appnexus now also picks it up from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay, removing |
||
|
@@ -230,23 +219,13 @@ const setAppnexusAudiences = (audiences) => { | |
* @param {Object} config Module configuration | ||
* @param {string[]} config.bidders Bidders specified in module's configuration | ||
*/ | ||
export const setTargetingDataToConfig = (papiResponse, { bidders }) => { | ||
const bidderConfigs = config.getBidderConfig(); | ||
export const setTargetingDataToConfig = (papiResponse, { bidders, biddersOrtb2 }) => { | ||
const { s: segments, t: topics } = papiResponse; | ||
|
||
const ortb2Updates = buildOrtb2Updates({ segments, topics }); | ||
for (const bidder of bidders) { | ||
const ortb2Updates = buildOrtb2Updates({ segments, topics }, bidder); | ||
const updatedBidderConfig = updateBidderConfig(bidder, ortb2Updates, bidderConfigs); | ||
if (updatedBidderConfig) { | ||
config.setBidderConfig({ | ||
bidders: [bidder], | ||
config: updatedBidderConfig | ||
}); | ||
} | ||
if (bidder === 'appnexus') { | ||
// Do the legacy stuff for appnexus with segments | ||
setAppnexusAudiences(segments); | ||
} | ||
updateBidderConfig(bidder, ortb2Updates, biddersOrtb2); | ||
setAppnexusAudiences(segments); | ||
} | ||
} | ||
|
||
|
@@ -272,13 +251,14 @@ const getBidRequestData = (reqBidsConfigObj, callback, moduleConfig, userConsent | |
try { | ||
// Get the required config | ||
const { customerId, bidders } = extractConfig(moduleConfig, reqBidsConfigObj); | ||
const { ortb2Fragments: { bidder: biddersOrtb2 } } = reqBidsConfigObj; | ||
// Get PAPI URL | ||
const papiUrl = getPapiUrl(customerId, extractConsent(userConsent) || {}, extractFpid()) | ||
// Call PAPI | ||
getTargetingDataFromPapi(papiUrl) | ||
.then((papiResponse) => { | ||
logMessage(LOG_PREFIX, 'Get targeting data request successful'); | ||
setTargetingDataToConfig(papiResponse, { bidders }); | ||
setTargetingDataToConfig(papiResponse, { bidders, biddersOrtb2 }); | ||
callback(); | ||
}) | ||
} catch (error) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bidderConfig
can be undefined here, if you are the first to set it up for a particular bidder. You want to change this toThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, right before this line, I'll do a:
That way I'll be sure to set something in the bidderConfig.
If I did
I would set values to an object I'll lose after exiting the function