From 62d6121fcb638f9131d165d88391a7fd07d4f72e Mon Sep 17 00:00:00 2001 From: Jason Snellbaker Date: Wed, 23 Feb 2022 15:14:04 -0500 Subject: [PATCH] appnexus bid adapter - convert keywords different for psp endpoint --- modules/appnexusBidAdapter.js | 38 +++++++++++++++++++- test/spec/modules/appnexusBidAdapter_spec.js | 24 +++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 1829323df2a..2b3313562e9 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -360,11 +360,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); @@ -1157,4 +1166,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); diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js index 2cf65bc8a59..4d7b50ccf83 100644 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ b/test/spec/modules/appnexusBidAdapter_spec.js @@ -1439,4 +1439,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(); + }); + }); });