Skip to content

Commit

Permalink
remove key=value keyword parsing for appnexus and its clones
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed Jun 12, 2023
1 parent d6450d1 commit 80567cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 114 deletions.
20 changes: 3 additions & 17 deletions libraries/appnexusKeywords/anKeywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,10 @@ export function convertKeywordStringToANMap(keyStr) {
function convertKeywordsToANMap(kwarray) {
const result = {};
kwarray.forEach(kw => {
// if = exists, then split
if (kw.indexOf('=') !== -1) {
let kwPair = kw.split('=');
let key = kwPair[0];
let val = kwPair[1];

// then check for existing key in result > if so add value to the array > if not, add new key and create value array
if (result.hasOwnProperty(key)) {
result[key].push(val);
} else {
result[key] = [val];
}
} else {
if (!result.hasOwnProperty(kw)) {
result[kw] = [];
}
if (!result.hasOwnProperty(kw)) {
result[kw] = [];
}
})
});
return result;
}

Expand Down
3 changes: 1 addition & 2 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {hasPurpose1Consent} from '../src/utils/gpdr.js';
import {convertOrtbRequestToProprietaryNative} from '../src/native.js';
import {APPNEXUS_CATEGORY_MAPPING} from '../libraries/categoryTranslationMapping/index.js';
import {
convertKeywordStringToANMap,
getANKewyordParamFromMaps,
getANKeywordParam,
transformBidderParamKeywords
Expand Down Expand Up @@ -783,7 +782,7 @@ function bidToTag(bid) {
tag.external_imp_id = bid.params.external_imp_id;
}

const auKeywords = getANKewyordParamFromMaps(convertKeywordStringToANMap(deepAccess(bid, 'ortb2Imp.ext.data.keywords')), bid.params?.keywords);
const auKeywords = getANKewyordParamFromMaps(bid.params?.keywords);
if (auKeywords.length > 0) {
tag.keywords = auKeywords;
}
Expand Down
103 changes: 8 additions & 95 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,26 +757,27 @@ describe('AppNexusAdapter', function () {
'value': ['rock', 'pop']
}, {
'key': 'test'
}, {
key: 'tools=industrial',
}, {
key: 'tools=home',
}, {
'key': 'tools',
'value': ['power', 'industrial', 'home']
'value': ['power']
}, {
'key': 'power tools'
}, {
'key': 'drills'
}, {
'key': 'video'
}, {
'key': 'source',
'value': ['streaming']
'key': 'source=streaming',
}, {
'key': 'renting'
}, {
'key': 'app',
'value': ['iphone 11']
'key': 'app=iphone 11',
}, {
'key': 'appcontent',
'value': ['home repair']
'key': 'appcontent=home repair',
}, {
'key': 'dyi'
}]);
Expand Down Expand Up @@ -908,94 +909,6 @@ describe('AppNexusAdapter', function () {
])
});

it('should convert adUnit ortb2 keywords (when there are no bid param keywords) to proper form and attaches to request', function () {
let bidRequest = Object.assign({},
bidRequests[0],
{
ortb2Imp: {
ext: {
data: {
keywords: 'ortb2=yes,ortb2test, multiValMixed=4, singleValNum=456'
}
}
}
}
);

const request = spec.buildRequests([bidRequest]);
const payload = JSON.parse(request.data);

expectKeywords(payload.tags[0].keywords, [{
'key': 'ortb2',
'value': ['yes']
}, {
'key': 'ortb2test'
}, {
'key': 'multiValMixed',
'value': ['4']
}, {
'key': 'singleValNum',
'value': ['456']
}]);
});

it('should convert keyword params and adUnit ortb2 keywords to proper form and attaches to request', function () {
let bidRequest = Object.assign({},
bidRequests[0],
{
params: {
placementId: '10433394',
keywords: {
single: 'val',
singleArr: ['val'],
singleArrNum: [5],
multiValMixed: ['value1', 2, 'value3'],
singleValNum: 123,
emptyStr: '',
emptyArr: [''],
badValue: { 'foo': 'bar' } // should be dropped
}
},
ortb2Imp: {
ext: {
data: {
keywords: 'ortb2=yes,ortb2test, multiValMixed=4, singleValNum=456'
}
}
}
}
);

const request = spec.buildRequests([bidRequest]);
const payload = JSON.parse(request.data);

expectKeywords(payload.tags[0].keywords, [{
'key': 'single',
'value': ['val']
}, {
'key': 'singleArr',
'value': ['val']
}, {
'key': 'singleArrNum',
'value': ['5']
}, {
'key': 'multiValMixed',
'value': ['value1', '2', 'value3', '4']
}, {
'key': 'singleValNum',
'value': ['123', '456']
}, {
'key': 'emptyStr'
}, {
'key': 'emptyArr'
}, {
'key': 'ortb2',
'value': ['yes']
}, {
'key': 'ortb2test'
}]);
});

it('should add payment rules to the request', function () {
let bidRequest = Object.assign({},
bidRequests[0],
Expand Down

0 comments on commit 80567cd

Please sign in to comment.