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

Adagio Bid Adapter : add new params splitKeyword and dl to bidRequest payload #9694

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
41 changes: 41 additions & 0 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
logInfo,
logWarn,
mergeDeep,
isStr,
} from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
Expand Down Expand Up @@ -924,6 +925,46 @@ export const spec = {
adunit_position: getSlotPosition(bidRequest.params.adUnitElementId) // adUnitElementId à déplacer ???
};

// Force the Split Keyword to be a String
if (bidRequest.params.splitKeyword) {
if (isStr(bidRequest.params.splitKeyword) || isNumber(bidRequest.params.splitKeyword)) {
bidRequest.params.splitKeyword = bidRequest.params.splitKeyword.toString();
} else {
delete bidRequest.params.splitKeyword;

logWarn(LOG_PREFIX, 'The splitKeyword param have been removed because the type is invalid, accepted type: number or string.');
}
}

// Force the Data Layer key and value to be a String
if (bidRequest.params.dataLayer) {
if (isStr(bidRequest.params.dataLayer) || isNumber(bidRequest.params.dataLayer) || isArray(bidRequest.params.dataLayer) || isFn(bidRequest.params.dataLayer)) {
logWarn(LOG_PREFIX, 'The dataLayer param is invalid, only object is accepted as a type.');
delete bidRequest.params.dataLayer;
} else {
let invalidDlParam = false;

bidRequest.params.dl = bidRequest.params.dataLayer
// Remove the dataLayer from the BidRequest to send the `dl` instead of the `dataLayer`
delete bidRequest.params.dataLayer

Object.keys(bidRequest.params.dl).forEach((key) => {
if (bidRequest.params.dl[key]) {
if (isStr(bidRequest.params.dl[key]) || isNumber(bidRequest.params.dl[key])) {
bidRequest.params.dl[key] = bidRequest.params.dl[key].toString();
} else {
invalidDlParam = true;
delete bidRequest.params.dl[key];
}
}
});

if (invalidDlParam) {
logWarn(LOG_PREFIX, 'Some parameters of the dataLayer property have been removed because the type is invalid, accepted type: number or string.');
}
}
}

Object.keys(features).forEach((prop) => {
if (features[prop] === '') {
delete features[prop];
Expand Down
6 changes: 6 additions & 0 deletions modules/adagioBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Below, the list of Adagio params and where they can be set.
| debug | | x |
| video | | x |
| native | | x |
| splitKeyword | | x |
| dataLayer | | x |

_* These params are deprecated in favor the Global configuration setup, see below._

Expand Down Expand Up @@ -115,6 +117,10 @@ var adUnits = [
context: 1,
plcmttype: 2
},
splitKeyword: 'splitrule-one',
dl: {
placement: '1234'
}
}
}]
}
Expand Down
70 changes: 70 additions & 0 deletions test/spec/modules/adagioBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,76 @@ describe('Adagio bid adapter', () => {
expect(requests[0].data.adUnits[0].features.url).to.not.exist;
});

it('should force split keyword param into a string', function() {
const bid01 = new BidRequestBuilder().withParams({
splitKeyword: 1234
}).build();
const bid02 = new BidRequestBuilder().withParams({
splitKeyword: ['1234']
}).build();
const bidderRequest = new BidderRequestBuilder().build();

const requests = spec.buildRequests([bid01, bid02], bidderRequest);

expect(requests).to.have.lengthOf(1);
expect(requests[0].data).to.have.all.keys(expectedDataKeys);
expect(requests[0].data.adUnits[0].params).to.exist;
expect(requests[0].data.adUnits[0].params.splitKeyword).to.exist;
expect(requests[0].data.adUnits[0].params.splitKeyword).to.equal('1234');
expect(requests[0].data.adUnits[1].params.splitKeyword).to.not.exist;
});

it('should force key and value from data layer param into a string', function() {
const bid01 = new BidRequestBuilder().withParams({
dataLayer: {
1234: 'dlparam',
goodkey: 1234,
objectvalue: {
random: 'result'
},
arrayvalue: ['1234']
}
}).build();

const bid02 = new BidRequestBuilder().withParams({
dataLayer: 'a random string'
}).build();

const bid03 = new BidRequestBuilder().withParams({
dataLayer: 1234
}).build();

const bid04 = new BidRequestBuilder().withParams({
dataLayer: ['an array']
}).build();

const bidderRequest = new BidderRequestBuilder().build();

const requests = spec.buildRequests([bid01, bid02, bid03, bid04], bidderRequest);

expect(requests).to.have.lengthOf(1);
expect(requests[0].data).to.have.all.keys(expectedDataKeys);
expect(requests[0].data.adUnits[0].params).to.exist;
expect(requests[0].data.adUnits[0].params.dataLayer).to.not.exist;
expect(requests[0].data.adUnits[0].params.dl).to.exist;
expect(requests[0].data.adUnits[0].params.dl['1234']).to.equal('dlparam');
expect(requests[0].data.adUnits[0].params.dl.goodkey).to.equal('1234');
expect(requests[0].data.adUnits[0].params.dl.objectvalue).to.not.exist;
expect(requests[0].data.adUnits[0].params.dl.arrayvalue).to.not.exist;

expect(requests[0].data.adUnits[1].params).to.exist;
expect(requests[0].data.adUnits[1].params.dl).to.not.exist;
expect(requests[0].data.adUnits[1].params.dataLayer).to.not.exist;

expect(requests[0].data.adUnits[2].params).to.exist;
expect(requests[0].data.adUnits[2].params.dl).to.not.exist;
expect(requests[0].data.adUnits[2].params.dataLayer).to.not.exist;

expect(requests[0].data.adUnits[3].params).to.exist;
expect(requests[0].data.adUnits[3].params.dl).to.not.exist;
expect(requests[0].data.adUnits[3].params.dataLayer).to.not.exist;
});

describe('With video mediatype', function() {
context('Outstream video', function() {
it('should logWarn if user does not set renderer.backupOnly: true', function() {
Expand Down