Skip to content
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

Merged
merged 7 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
82 changes: 31 additions & 51 deletions modules/1plusXRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 }))
Expand All @@ -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);
Copy link
Collaborator

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 to

const bidderConfig = biddersOrtb2[bidder] = biddersOrtb2[bidder] || {}

Copy link
Contributor Author

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:

  mergeDeep(biddersOrtb2, { [bidder]: {} });

That way I'll be sure to set something in the bidderConfig.

If I did

const bidderConfig = biddersOrtb2[bidder] = biddersOrtb2[bidder] || {}

I would set values to an object I'll lose after exiting the function


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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 site.keywords as you have set them up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, removing

Expand All @@ -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);
}
}

Expand All @@ -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) {
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