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

prebid 8 - read ortb segment data in appnexus keywords library functions #10082

Merged
merged 2 commits into from
Jun 12, 2023
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
40 changes: 37 additions & 3 deletions libraries/appnexusKeywords/anKeywords.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import {_each, getValueString, isArray, isStr, mergeDeep, isNumber} from '../../src/utils.js';
import {_each, deepAccess, getValueString, isArray, isStr, mergeDeep, isNumber} from '../../src/utils.js';
import {getAllOrtbKeywords} from '../keywords/keywords.js';
import {CLIENT_SECTIONS} from '../../src/fpd/oneClient.js';

const ORTB_SEGTAX_KEY_MAP = {
526: '1plusx',
527: '1plusx',
541: 'captify_segments',
540: 'perid'
};
const ORTB_SEG_PATHS = ['user.data'].concat(
CLIENT_SECTIONS.map((prefix) => `${prefix}.content.data`)
);

/**
* Converts an object of arrays (either strings or numbers) into an array of objects containing key and value properties
Expand Down Expand Up @@ -85,7 +96,7 @@ function convertKeywordsToANMap(kwarray) {
* @param ortb2
* @return {{}} appnexus-style keyword map using all keywords contained in ortb2
*/
export function getANMapFromOrtb(ortb2) {
export function getANMapFromOrtbKeywords(ortb2) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it makes sense to simplify this to get rid of the key=value parsing now (and treat keywords as just simple keywords); since with this there's no need for the hack anymore - but if we release it and people start using it you'll be stuck with it for a while.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The issue is people may already be using it; I don't know how to confirm, so I think it's safer to leave it be (and not advertise it). If others push for this change, then I guess it could happen.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's never been released - the only dependence on it comes from recent updates that are also still to be released with 8. But fair enough, it's better to undo this only after those are updated yet again to use segments instead.

return convertKeywordsToANMap(getAllOrtbKeywords(ortb2));
}

Expand All @@ -100,7 +111,30 @@ export function getANKewyordParamFromMaps(...anKeywordMaps) {

export function getANKeywordParam(ortb2, ...anKeywordsMaps) {
return getANKewyordParamFromMaps(
getANMapFromOrtb(ortb2),
getANMapFromOrtbKeywords(ortb2),
getANMapFromOrtbSegments(ortb2),
...anKeywordsMaps
)
}

export function getANMapFromOrtbSegments(ortb2) {
let ortbSegData = {};
ORTB_SEG_PATHS.forEach(path => {
let ortbSegsArrObj = deepAccess(ortb2, path) || [];
ortbSegsArrObj.forEach(segObj => {
// only read segment data from known sources
const segtax = ORTB_SEGTAX_KEY_MAP[deepAccess(segObj, 'ext.segtax')];
if (segtax) {
segObj.segment.forEach(seg => {
// if source was in multiple locations of ortb or had multiple segments in same area, stack them together into an array
if (ortbSegData[segtax]) {
ortbSegData[segtax].push(seg.id);
} else {
ortbSegData[segtax] = [seg.id]
}
});
}
});
});
return ortbSegData;
}
63 changes: 63 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,69 @@ describe('AppNexusAdapter', function () {
config.getConfig.restore();
});

it('adds ortb2 segments to auction request as keywords', function() {
let bidRequest = Object.assign({}, bidRequests[0]);
const bidderRequest = {
ortb2: {
site: {
keywords: 'drill',
content: {
data: [{
name: 'siteseg1',
ext: {
segtax: 540
},
segment: [{
id: 's123',
}, {
id: 's234'
}]
}, {
name: 'sitseg2',
ext: {
segtax: 1
},
segment: [{
id: 'unknown'
}]
}, {
name: 'siteseg3',
ext: {
segtax: 526
},
segment: [{
id: 'dog'
}]
}]
}
},
user: {
data: [{
name: 'userseg1',
ext: {
segtax: 526
},
segment: [{
id: 'cat'
}]
}]
}
}
};
const request = spec.buildRequests([bidRequest], bidderRequest);
const payload = JSON.parse(request.data);

expectKeywords(payload.keywords, [{
'key': 'drill'
}, {
'key': '1plusx',
'value': ['cat', 'dog']
}, {
'key': 'perid',
'value': ['s123', 's234']
}]);
});

if (FEATURES.NATIVE) {
it('should attach native params to the request', function () {
let bidRequest = Object.assign({},
Expand Down