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 Bid Adapter: get opeCloud data from local storage #8542

Merged
merged 49 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4fc8912
Merge pull request #42 from prebid/master
Jan 6, 2022
d7e59af
Merge branch 'prebid:master' into master
nllerandi3lift Jan 14, 2022
1101d6c
Merge branch 'prebid:master' into master
nllerandi3lift Jan 31, 2022
6fff6f3
Merge branch 'prebid:master' into master
nllerandi3lift Feb 18, 2022
06a815e
Merge branch 'prebid:master' into master
nllerandi3lift Mar 7, 2022
a41b5d4
Merge branch 'prebid:master' into master
nllerandi3lift Mar 14, 2022
66ab3c8
Merge branch 'prebid:master' into master
nllerandi3lift Mar 23, 2022
33c780c
TL-19850 Finished log error logic around floors functionality
Apr 5, 2022
7fc0801
Merge branch 'prebid:master' into master
nllerandi3lift Apr 5, 2022
905e884
deprecates getlegacyFpd
nllerandi3lift Apr 7, 2022
c2650c2
remove console log
nllerandi3lift Apr 7, 2022
9bb44c6
Merge branch 'prebid:master' into master
nllerandi3lift Apr 8, 2022
450cfb6
Merge pull request #48 from triplelift-internal/TL-26965-deprecateLeg…
nllerandi3lift Apr 8, 2022
0ebf51c
TL-19850 Changed functionlity of tests
patrickloughrey Apr 20, 2022
9072383
Merge branch 'prebid:master' into master
nllerandi3lift Apr 21, 2022
da47d96
Merge pull request #47 from triplelift-internal/TL-19850-floors-modul…
nllerandi3lift Apr 21, 2022
edcf99b
Merge branch 'prebid:master' into master
nllerandi3lift Apr 29, 2022
3b34724
restore logErrorSpy aftereach
nllerandi3lift Apr 29, 2022
103814f
Merge branch 'prebid:master' into master
nllerandi3lift Apr 29, 2022
5b93e6d
Merge branch 'prebid:master' into master
nllerandi3lift May 3, 2022
f98715f
passes 1px segments
nllerandi3lift May 3, 2022
20e40e2
array and malformed json check
nllerandi3lift May 3, 2022
96c4020
spell check
nllerandi3lift May 3, 2022
3954cea
single quotes
nllerandi3lift May 3, 2022
dd8cc27
TL-27574 Second draft of implementing 1plusx logic
patrickloughrey May 4, 2022
2c5d243
cleanup around fetchOnePlusX
nllerandi3lift May 4, 2022
839a34c
replaces segment for ext
nllerandi3lift May 6, 2022
dac52d9
ext should be object
nllerandi3lift May 9, 2022
bc6de82
Merge branch 'prebid:master' into master
nllerandi3lift May 9, 2022
a8c43a1
tests
nllerandi3lift May 13, 2022
277d269
update localstorage key name
nllerandi3lift May 16, 2022
4f12fb9
rename to opecloud
nllerandi3lift May 16, 2022
8552d36
add frametype to tlBidAdapter
gbalboa0 May 20, 2022
ac384c3
removes comments
nllerandi3lift May 23, 2022
7cd76f1
clean up + no frame ft
gbalboa0 May 26, 2022
ba37f05
Merge pull request #51 from triplelift-internal/TL-27859-add-frame-ty…
gbalboa0 May 27, 2022
7709fda
Merge branch 'prebid:master' into master
nllerandi3lift Jun 1, 2022
3bd185f
Merge branch 'master' into TL-27574-ingest1PX-alt
nllerandi3lift Jun 1, 2022
c778e00
addressing feedback
nllerandi3lift Jun 1, 2022
a94b99b
Revert "TL-27859: add frame type to prebid adapter"
gbalboa0 Jun 7, 2022
adcaf03
Merge pull request #52 from triplelift-internal/revert-51-TL-27859-ad…
gbalboa0 Jun 7, 2022
f57b5c0
Merge branch 'prebid:master' into master
nllerandi3lift Jun 7, 2022
2a0b221
Merge branch 'master' into TL-27574-ingest1PX-alt
nllerandi3lift Jun 7, 2022
06cf77b
Merge pull request #50 from triplelift-internal/TL-27574-ingest1PX-alt
nllerandi3lift Jun 7, 2022
93a3a3d
cleanup
nllerandi3lift Jun 7, 2022
044a109
Merge branch 'master' into TL-prebid7-mergeConflicts
nllerandi3lift Jun 8, 2022
af4f3a1
updates tests to work with prebid 7
nllerandi3lift Jun 8, 2022
0f7df9a
permission to access storage
nllerandi3lift Jun 8, 2022
d60cdd2
reset prebid global
nllerandi3lift Jun 8, 2022
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
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
70 changes: 69 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,6 +379,12 @@ describe('triplelift adapter', function () {
};
sandbox = sinon.sandbox.create();
logErrorSpy = sinon.spy(utils, 'logError');

$$PREBID_GLOBAL$$.bidderSettings = {
nllerandi3lift marked this conversation as resolved.
Show resolved Hide resolved
triplelift: {
storageAllowed: true
}
};
});
afterEach(() => {
sandbox.restore();
Expand Down Expand Up @@ -827,6 +833,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