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

Adhese Bid Adapter: Per adunit targets #6256

Merged
merged 7 commits into from
Feb 3, 2021
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
13 changes: 9 additions & 4 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ export const spec = {
}
const { gdprConsent, refererInfo } = bidderRequest;

const targets = validBidRequests.map(bid => bid.params.data).reduce(mergeTargets, {});
const gdprParams = (gdprConsent && gdprConsent.consentString) ? { xt: [gdprConsent.consentString] } : {};
const refererParams = (refererInfo && refererInfo.referer) ? { xf: [base64urlEncode(refererInfo.referer)] } : {};
const id5Params = (getId5Id(validBidRequests)) ? { x5: [getId5Id(validBidRequests)] } : {};
const slots = validBidRequests.map(bid => ({ slotname: bidToSlotName(bid) }));
const commonParams = { ...gdprParams, ...refererParams, ...id5Params };

const slots = validBidRequests.map(bid => ({
slotname: bidToSlotName(bid),
parameters: cleanTargets(bid.params.data)
}));

const payload = {
slots: slots,
parameters: { ...targets, ...gdprParams, ...refererParams, ...id5Params }
parameters: commonParams
}

const account = getAccount(validBidRequests);
Expand Down Expand Up @@ -110,7 +114,8 @@ function adResponse(bid, ad) {
return bidResponse;
}

function mergeTargets(targets, target) {
function cleanTargets(target) {
const targets = {};
if (target) {
Object.keys(target).forEach(function (key) {
const val = target[key];
Expand Down
14 changes: 8 additions & 6 deletions test/spec/modules/adheseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,33 @@ describe('AdheseAdapter', function () {
it('should include requested slots', function () {
let req = spec.buildRequests([ minimalBid() ], bidderRequest);

expect(JSON.parse(req.data).slots).to.deep.include({ 'slotname': '_main_page_-leaderboard' });
expect(JSON.parse(req.data).slots[0].slotname).to.equal('_main_page_-leaderboard');
});

it('should include all extra bid params', function () {
let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }) ], bidderRequest);

expect(JSON.parse(req.data).parameters).to.deep.include({ 'ag': [ '25' ] });
expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ag': [ '25' ] });
});

it('should include duplicate bid params once', function () {
it('should assign bid params per slot', function () {
let req = spec.buildRequests([ bidWithParams({ 'ag': '25' }), bidWithParams({ 'ag': '25', 'ci': 'gent' }) ], bidderRequest);

expect(JSON.parse(req.data).parameters).to.deep.include({'ag': ['25']}).and.to.deep.include({ 'ci': [ 'gent' ] });
expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ag': [ '25' ] }).and.not.to.deep.include({ 'ci': [ 'gent' ] });
expect(JSON.parse(req.data).slots[1].parameters).to.deep.include({ 'ag': [ '25' ] }).and.to.deep.include({ 'ci': [ 'gent' ] });
});

it('should split multiple target values', function () {
let req = spec.buildRequests([ bidWithParams({ 'ci': 'london' }), bidWithParams({ 'ci': 'gent' }) ], bidderRequest);

expect(JSON.parse(req.data).parameters).to.deep.include({ 'ci': [ 'london', 'gent' ] });
expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ci': [ 'london' ] });
expect(JSON.parse(req.data).slots[1].parameters).to.deep.include({ 'ci': [ 'gent' ] });
});

it('should filter out empty params', function () {
let req = spec.buildRequests([ bidWithParams({ 'aa': [], 'bb': null, 'cc': '', 'dd': [ '', '' ], 'ee': [ 0, 1, null ], 'ff': 0, 'gg': [ 'x', 'y', '' ] }) ], bidderRequest);

let params = JSON.parse(req.data).parameters;
let params = JSON.parse(req.data).slots[0].parameters;
expect(params).to.not.have.any.keys('aa', 'bb', 'cc', 'dd');
expect(params).to.deep.include({ 'ee': [ 0, 1 ], 'ff': [ 0 ], 'gg': [ 'x', 'y' ] });
});
Expand Down