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

Triplelift: FPD key value pair support #5

Merged
merged 2 commits into from
Sep 10, 2020
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
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