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

TL-26984: 1PlusX boilerplate - ALT #50

Merged
merged 15 commits into from
Jun 7, 2022
30 changes: 30 additions & 0 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { tryAppendQueryString, logMessage, logError, isEmpty, isStr, isPlainObje
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import {getStorageManager} from '../src/storageManager.js';

const GVLID = 28;
const BIDDER_CODE = 'triplelift';
Expand All @@ -10,6 +11,7 @@ const BANNER_TIME_TO_LIVE = 300;
const INSTREAM_TIME_TO_LIVE = 3600;
let gdprApplies = true;
let consentString = null;
const storage = getStorageManager({gvlid: GVLID, bidderCode: BIDDER_CODE});

export const tripleliftAdapterSpec = {
gvlid: GVLID,
Expand Down Expand Up @@ -197,10 +199,26 @@ function _getGlobalFpd() {
const context = {}
const user = {};
const ortbData = config.getConfig('ortb2') || {};
const onePlusXStorage = _fetchOnePlusX();
nllerandi3lift marked this conversation as resolved.
Show resolved Hide resolved

const fpdContext = Object.assign({}, ortbData.site);
const fpdUser = Object.assign({}, ortbData.user);

// NEEDS TEST: check that onePlusXStorage is parseable
if (onePlusXStorage) {
fpdUser.data = fpdUser.data || []
nllerandi3lift marked this conversation as resolved.
Show resolved Hide resolved
// NEEDS TEST: check that fpdUser.data is an array before pushing;
// publisher may accidentally make it an object
try {
fpdUser.data.push({
name: '1plusX',
segment: [onePlusXStorage]
})
} catch (err) {
logError('Triplelift: error adding 1plusX segments: ', err);
}
}

_addEntries(context, fpdContext);
_addEntries(user, fpdUser);

Expand All @@ -213,6 +231,18 @@ function _getGlobalFpd() {
return fpd;
}

function _fetchOnePlusX() {
const oneplusx = storage.getDataFromLocalStorage('1plusx');
if (oneplusx == null) return null;
try {
const parsedJson = JSON.parse(oneplusx);
return parsedJson
} catch (err) {
logError('Triplelift: error parsing JSON: ', err);
return null
}
}

function _getAdUnitFpd(adUnitFpd) {
const fpd = {};
const context = {};
Expand Down