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

appnexus bid adapter - convert keywords differently for appnexuspsp endpoint #8115

Merged
merged 1 commit into from
Mar 1, 2022
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
38 changes: 37 additions & 1 deletion modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
24 changes: 24 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});