Skip to content

Commit

Permalink
appnexus bid adapter - convert keywords different for psp endpoint (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnellbaker authored Mar 1, 2022
1 parent 997961f commit 5217bef
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
38 changes: 37 additions & 1 deletion modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,20 @@ export const spec = {
},

transformBidParams: function (params, isOpenRtb) {
let conversionFn = transformBidderParamKeywords;
if (isOpenRtb === true) {
let s2sConfig = config.getConfig('s2sConfig');
let s2sEndpointUrl = deepAccess(s2sConfig, 'endpoint.p1Consent');
if (s2sEndpointUrl && s2sEndpointUrl.match('/openrtb2/prebid')) {
conversionFn = convertKeywordsToString;
}
}

params = convertTypes({
'member': 'string',
'invCode': 'string',
'placementId': 'number',
'keywords': transformBidderParamKeywords,
'keywords': conversionFn,
'publisherId': 'number'
}, params);

Expand Down Expand Up @@ -1164,4 +1173,31 @@ function getBidFloor(bid) {
return null;
}

// keywords: { 'genre': ['rock', 'pop'], 'pets': ['dog'] } goes to 'genre=rock,genre=pop,pets=dog'
function convertKeywordsToString(keywords) {
let result = '';
Object.keys(keywords).forEach(key => {
// if 'text' or ''
if (isStr(keywords[key])) {
if (keywords[key] !== '') {
result += `${key}=${keywords[key]},`
} else {
result += `${key},`;
}
} else if (isArray(keywords[key])) {
if (keywords[key][0] === '') {
result += `${key},`
} else {
keywords[key].forEach(val => {
result += `${key}=${val},`
});
}
}
});

// remove last trailing comma
result = result.substring(0, result.length - 1);
return result;
}

registerBidder(spec);
24 changes: 24 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1464,4 +1464,28 @@ describe('AppNexusAdapter', function () {
expect(Object.keys(result[0].meta.advertiserDomains)).to.deep.equal([]);
});
});

describe('transformBidParams', function () {
it('convert keywords param differently for psp endpoint', function () {
sinon.stub(config, 'getConfig')
.withArgs('s2sConfig')
.returns({
endpoint: {
p1Consent: 'https://ib.adnxs.com/openrtb2/prebid'
}
});

const oldParams = {
keywords: {
genre: ['rock', 'pop'],
pets: 'dog'
}
};

const newParams = spec.transformBidParams(oldParams, true);
expect(newParams.keywords).to.equal('genre=rock,genre=pop,pets=dog');

config.getConfig.restore();
});
});
});

0 comments on commit 5217bef

Please sign in to comment.