Skip to content

Commit

Permalink
Triplelift: FPD key value pair support (#5)
Browse files Browse the repository at this point in the history
* Triplelift: Add support for global fpd

* don't filter fpd
  • Loading branch information
colbertk authored Sep 10, 2020
1 parent e8c165e commit f0ba084
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
42 changes: 38 additions & 4 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function _getSyncType(syncOptions) {
function _buildPostBody(bidRequests) {
let data = {};
let { schain } = bidRequests[0];
const globalFpd = _getGlobalFpd();

data.imp = bidRequests.map(function(bidRequest, index) {
let imp = {
id: index,
Expand All @@ -133,10 +135,10 @@ function _buildPostBody(bidRequests) {
};
}

if (schain) {
data.ext = {
schain
}
let ext = _getExt(schain, globalFpd);

if (!utils.isEmpty(ext)) {
data.ext = ext;
}
return data;
}
Expand Down Expand Up @@ -168,6 +170,38 @@ function _getFloor (bid) {
return floor !== null ? floor : bid.params.floor;
}

function _getGlobalFpd() {
let fpd = {};
const fpdContext = Object.assign({}, config.getConfig('fpd.context'));
const fpdUser = Object.assign({}, config.getConfig('fpd.user'));

_addEntries(fpd, fpdContext);
_addEntries(fpd, fpdUser);

return fpd;
}

function _addEntries(target, source) {
if (!utils.isEmpty(source)) {
Object.keys(source).forEach(key => {
if (source[key] != null) {
target[key] = source[key];
}
});
}
}

function _getExt(schain, fpd) {
let ext = {};
if (!utils.isEmpty(schain)) {
ext.schain = { ...schain };
}
if (!utils.isEmpty(fpd)) {
ext.fpd = { ...fpd };
}
return ext;
}

function getUnifiedIdEids(bidRequests) {
return getEids(bidRequests, 'tdid', 'adserver.org', 'TDID');
}
Expand Down
31 changes: 31 additions & 0 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { newBidder } from 'src/adapters/bidderFactory.js';
import { deepClone } from 'src/utils.js';
import { config } from 'src/config.js';
import prebid from '../../../package.json';
import * as utils from 'src/utils.js';

const ENDPOINT = 'https://tlx.3lift.com/header/auction?';
const GDPR_CONSENT_STR = 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY';

describe('triplelift adapter', function () {
const adapter = newBidder(tripleliftAdapterSpec);
let bid, instreamBid;
let sandbox;

this.beforeEach(() => {
bid = {
Expand Down Expand Up @@ -194,6 +196,10 @@ describe('triplelift adapter', function () {
gdprApplies: true
},
};
sandbox = sinon.sandbox.create();
});
afterEach(() => {
sandbox.restore();
});

it('exists and is an object', function () {
Expand Down Expand Up @@ -383,6 +389,31 @@ describe('triplelift adapter', function () {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[0].floor).to.equal(1.99);
});
it('should send fpd on root level ext if kvps are available', function() {
const sens = null;
const category = ['news', 'weather', 'hurricane'];
const pmp_elig = 'true';
const fpd = {
context: {
pmp_elig,
category,
},
user: {
sens,
}
}
sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
fpd
};
return utils.deepAccess(config, key);
});
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const { data: payload } = request;
expect(payload.ext.fpd).to.not.haveOwnProperty('sens');
expect(payload.ext.fpd).to.haveOwnProperty('category');
expect(payload.ext.fpd).to.haveOwnProperty('pmp_elig');
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit f0ba084

Please sign in to comment.