Skip to content

Commit

Permalink
Adagio Bid Adapter : add new params splitKeyword and dl to bidReq…
Browse files Browse the repository at this point in the history
…uest payload (#9694)

* Add splitKeyword and dl params

* Update the `dl` to `dataLayer` for user and check the type

* Fix code convention, remove the toString on object properties
  • Loading branch information
Clement3 authored Mar 24, 2023
1 parent c780b80 commit 9ef8d25
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
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

0 comments on commit 9ef8d25

Please sign in to comment.