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

Adform Bid Adapter: add global targeting to the request query as parameter #6376

Merged
merged 1 commit into from
Mar 2, 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
30 changes: 30 additions & 0 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { config } from '../src/config.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';
import * as utils from '../src/utils.js';
import includes from 'core-js-pure/features/array/includes.js';

const OUTSTREAM_RENDERER_URL = 'https://s2.adform.net/banners/scripts/video/outstream/render.js';

Expand All @@ -24,13 +25,32 @@ export const spec = {

var request = [];
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ], [ 'eids', eids ] ];
const targetingParams = { mkv: [], mkw: [], msw: [] };

var bids = JSON.parse(JSON.stringify(validBidRequests));
var bidder = (bids[0] && bids[0].bidder) || BIDDER_CODE;

// set common targeting options as query params
if (bids.length > 1) {
for (let key in targetingParams) {
if (targetingParams.hasOwnProperty(key)) {
const collection = bids.map(bid => ((bid.params[key] && bid.params[key].split(',')) || []));
targetingParams[key] = collection.reduce(intersects);
if (targetingParams[key].length) {
bids.forEach((bid, index) => {
bid.params[key] = collection[index].filter(item => !includes(targetingParams[key], item));
});
}
}
}
}

for (i = 0, l = bids.length; i < l; i++) {
bid = bids[i];
if ((bid.params.priceType === 'net') || (bid.params.pt === 'net')) {
netRevenue = 'net';
}

for (j = 0, k = globalParams.length; j < k; j++) {
_key = globalParams[j][0];
_value = bid[_key] || bid.params[_key];
Expand Down Expand Up @@ -65,6 +85,12 @@ export const spec = {
request.push('us_privacy=' + bidderRequest.uspConsent);
}

for (let key in targetingParams) {
if (targetingParams.hasOwnProperty(key)) {
globalParams.push([ key, targetingParams[key].join(',') ]);
}
}

for (i = 1, l = globalParams.length; i < l; i++) {
_key = globalParams[i][0];
_value = globalParams[i][1];
Expand Down Expand Up @@ -114,6 +140,10 @@ export const spec = {
return result;
}, {});
}

function intersects(col1, col2) {
return col1.filter(item => includes(col2, item));
}
},
interpretResponse: function (serverResponse, bidRequest) {
const VALID_RESPONSES = {
Expand Down
31 changes: 31 additions & 0 deletions test/spec/modules/adformBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,37 @@ describe('Adform adapter', function () {
assert.equal(eids, 'some_id_value');
});

it('should add parameter to global parameters if it exists in all bids', function () {
const _bids = [];
_bids.push(bids[0]);
_bids.push(bids[1]);
_bids.push(bids[2]);
_bids[0].params.mkv = 'key:value,key1:value1';
_bids[1].params.mkv = 'key:value,key1:value1,keyR:removed';
_bids[2].params.mkv = 'key:value,key1:value1,keyR:removed,key8:value1';
_bids[0].params.mkw = 'targeting';
_bids[1].params.mkw = 'targeting';
_bids[2].params.mkw = 'targeting,targeting2';
_bids[0].params.msw = 'search:word,search:word2';
_bids[1].params.msw = 'search:word';
_bids[2].params.msw = 'search:word,search:word5';
let bidList = _bids;
let request = spec.buildRequests(bidList);
let parsedUrl = parseUrl(request.url);
assert.equal(parsedUrl.query.mkv, encodeURIComponent('key:value,key1:value1'));
assert.equal(parsedUrl.query.mkw, 'targeting');
assert.equal(parsedUrl.query.msw, encodeURIComponent('search:word'));
assert.ok(!parsedUrl.items[0].mkv);
assert.ok(!parsedUrl.items[0].mkw);
assert.equal(parsedUrl.items[0].msw, 'search:word2');
assert.equal(parsedUrl.items[1].mkv, 'keyR:removed');
assert.ok(!parsedUrl.items[1].mkw);
assert.ok(!parsedUrl.items[1].msw);
assert.equal(parsedUrl.items[2].mkv, 'keyR:removed,key8:value1');
assert.equal(parsedUrl.items[2].mkw, 'targeting2');
assert.equal(parsedUrl.items[2].msw, 'search:word5');
});

describe('user privacy', function () {
it('should send GDPR Consent data to adform if gdprApplies', function () {
let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}});
Expand Down