Skip to content

Commit

Permalink
Triplelift Bid Adapter: get opeCloud data from local storage (#8542)
Browse files Browse the repository at this point in the history
* TL-19850 Finished log error logic around floors functionality

* deprecates getlegacyFpd

* remove console log

* TL-19850 Changed functionlity of tests

* restore logErrorSpy aftereach

* passes 1px segments

* array and malformed json check

* spell check

* single quotes

* TL-27574 Second draft of implementing 1plusx logic

* cleanup around fetchOnePlusX

* replaces segment for ext

* ext should be object

* tests

* update localstorage key name

* rename to opecloud

* add frametype to tlBidAdapter

* removes comments

* clean up + no frame ft

* addressing feedback

* Revert "TL-27859: add frame type to prebid adapter"

* cleanup

* updates tests to work with prebid 7

* permission to access storage

* reset prebid global

Co-authored-by: Dan Goldin <[email protected]>
Co-authored-by: Patrick Loughrey <[email protected]>
Co-authored-by: Patrick Loughrey <[email protected]>
Co-authored-by: gbalboa0 <[email protected]>
Co-authored-by: gbalboa0 <[email protected]>
  • Loading branch information
6 people authored Jun 8, 2022
1 parent f5cf0eb commit 9f14ab2
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
27 changes: 27 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;
export const storage = getStorageManager({gvlid: GVLID, bidderCode: BIDDER_CODE});

export const tripleliftAdapterSpec = {
gvlid: GVLID,
Expand Down Expand Up @@ -197,10 +199,23 @@ function _getGlobalFpd(bidderRequest) {
const context = {}
const user = {};
const ortbData = bidderRequest.ortb2 || {};
const opeCloudStorage = _fetchOpeCloud();

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

if (opeCloudStorage) {
fpdUser.data = fpdUser.data || []
try {
fpdUser.data.push({
name: 'www.1plusx.com',
ext: opeCloudStorage
})
} catch (err) {
logError('Triplelift: error adding 1plusX segments: ', err);
}
}

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

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

function _fetchOpeCloud() {
const opeCloud = storage.getDataFromLocalStorage('opecloud_ctx');
if (!opeCloud) return null;
try {
const parsedJson = JSON.parse(opeCloud);
return parsedJson
} catch (err) {
logError('Triplelift: error parsing JSON: ', err);
return null
}
}

function _getAdUnitFpd(adUnitFpd) {
const fpd = {};
const context = {};
Expand Down
71 changes: 70 additions & 1 deletion test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { tripleliftAdapterSpec } from 'modules/tripleliftBidAdapter.js';
import { tripleliftAdapterSpec, storage } from 'modules/tripleliftBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { deepClone } from 'src/utils.js';
import { config } from 'src/config.js';
Expand Down Expand Up @@ -379,10 +379,17 @@ describe('triplelift adapter', function () {
};
sandbox = sinon.sandbox.create();
logErrorSpy = sinon.spy(utils, 'logError');

$$PREBID_GLOBAL$$.bidderSettings = {
triplelift: {
storageAllowed: true
}
};
});
afterEach(() => {
sandbox.restore();
utils.logError.restore();
$$PREBID_GLOBAL$$.bidderSettings = {};
});

it('exists and is an object', function () {
Expand Down Expand Up @@ -827,6 +834,68 @@ describe('triplelift adapter', function () {
expect(request.data.imp[0].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute');
expect(request.data.imp[1].fpd).to.not.exist;
});
it('should send 1PlusX data as fpd if localStorage is available and no other fpd is defined', function() {
sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => '{"kid":1,"s":"ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==","t":"/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=="}');
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.ext.fpd).to.deep.equal({
'user': {
'data': [
{
'name': 'www.1plusx.com',
'ext': {
'kid': 1,
's': 'ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==',
't': '/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=='
}
}
]
}
})
});
it('should append 1PlusX data to existing user.data entries if localStorage is available', function() {
bidderRequest.ortb2 = {
user: {
data: [
{ name: 'dataprovider.com', ext: { segtax: 4 }, segment: [{ id: '1' }] }
]
}
}
sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => '{"kid":1,"s":"ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==","t":"/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=="}');
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.ext.fpd).to.deep.equal({
'user': {
'data': [
{ 'name': 'dataprovider.com', 'ext': { 'segtax': 4 }, 'segment': [{ 'id': '1' }] },
{
'name': 'www.1plusx.com',
'ext': {
'kid': 1,
's': 'ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==',
't': '/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=='
}
}
]
}
})
});
it('should not append anything if getDataFromLocalStorage returns null', function() {
bidderRequest.ortb2 = {
user: {
data: [
{ name: 'dataprovider.com', ext: { segtax: 4 }, segment: [{ id: '1' }] }
]
}
}
sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => null);
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.ext.fpd).to.deep.equal({
'user': {
'data': [
{ 'name': 'dataprovider.com', 'ext': { 'segtax': 4 }, 'segment': [{ 'id': '1' }] },
]
}
})
});
});

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

0 comments on commit 9f14ab2

Please sign in to comment.