Skip to content

Commit

Permalink
AdOcean Bid Adapter: send slave ids which are taking part in auction.…
Browse files Browse the repository at this point in the history
… (#8694)
  • Loading branch information
mmuras authored and ahmadlob committed Jul 27, 2022
1 parent 513930a commit 152eb1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions modules/adoceanBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { _each, parseSizesInput, isStr, isArray } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'adocean';
const URL_SAFE_FIELDS = {
schain: true,
slaves: true
};

function buildEndpointUrl(emiter, payloadMap) {
const payload = [];
_each(payloadMap, function(v, k) {
payload.push(k + '=' + (k === 'schain' ? v : encodeURIComponent(v)));
payload.push(k + '=' + (URL_SAFE_FIELDS[k] ? v : encodeURIComponent(v)));
});

const randomizedPart = Math.random().toString().slice(2);
Expand All @@ -17,7 +21,8 @@ function buildRequest(masterBidRequests, masterId, gdprConsent) {
let emiter;
const payload = {
id: masterId,
aosspsizes: []
aosspsizes: [],
slaves: []
};
if (gdprConsent) {
payload.gdpr_consent = gdprConsent.consentString || undefined;
Expand All @@ -29,7 +34,7 @@ function buildRequest(masterBidRequests, masterId, gdprConsent) {
}

const bidIdMap = {};

const uniquePartLength = 10;
_each(masterBidRequests, function(bid, slaveId) {
if (!emiter) {
emiter = bid.params.emiter;
Expand All @@ -38,11 +43,13 @@ function buildRequest(masterBidRequests, masterId, gdprConsent) {
const slaveSizes = parseSizesInput(bid.mediaTypes.banner.sizes).join('_');
const rawSlaveId = bid.params.slaveId.replace('adocean', '');
payload.aosspsizes.push(rawSlaveId + '~' + slaveSizes);
payload.slaves.push(rawSlaveId.slice(-uniquePartLength));

bidIdMap[slaveId] = bid.bidId;
});

payload.aosspsizes = payload.aosspsizes.join('-');
payload.slaves = payload.slaves.join(',');

return {
method: 'GET',
Expand Down
5 changes: 4 additions & 1 deletion test/spec/modules/adoceanBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,20 @@ describe('AdoceanAdapter', function () {
expect(request.url).to.include('gdpr_consent=' + bidderRequest.gdprConsent.consentString);
});

it('should attach sizes information to url', function () {
it('should attach sizes and slaves information to url', function () {
let requests = spec.buildRequests(bidRequests, bidderRequest);
expect(requests[0].url).to.include('aosspsizes=myaozpniqismex~300x250_300x600');
expect(requests[0].url).to.include('slaves=zpniqismex');
expect(requests[1].url).to.include('aosspsizes=myaozpniqismex~300x200_600x250');
expect(requests[1].url).to.include('slaves=zpniqismex');

const differentSlavesBids = deepClone(bidRequests);
differentSlavesBids[1].params.slaveId = 'adoceanmyaowafpdwlrks';
requests = spec.buildRequests(differentSlavesBids, bidderRequest);
expect(requests.length).to.equal(1);
expect(requests[0].url).to.include('aosspsizes=myaozpniqismex~300x250_300x600-myaowafpdwlrks~300x200_600x250');
expect((requests[0].url.match(/aosspsizes=/g) || []).length).to.equal(1);
expect(requests[0].url).to.include('slaves=zpniqismex,wafpdwlrks');
});

it('should attach schain parameter if available', function() {
Expand Down

0 comments on commit 152eb1e

Please sign in to comment.