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: Additional eid filtering and checks #7565

Merged
merged 29 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d65b09a
removes duplicate eids from POST call
nllerandi3lift Feb 19, 2021
0e9deb5
additional tests
nllerandi3lift Feb 22, 2021
224dc40
pubcid support
nllerandi3lift Feb 22, 2021
615e804
Merge pull request #19 from triplelift-internal/TL-19968-pubcid-support
nllerandi3lift Feb 23, 2021
c4b0ff2
Merge remote-tracking branch 'upstream/master'
nllerandi3lift Feb 24, 2021
4565bbc
Merge remote-tracking branch 'upstream/master'
nllerandi3lift Mar 5, 2021
3767f98
Merge remote-tracking branch 'upstream/master'
nllerandi3lift Apr 5, 2021
9d7f1d6
Merge remote-tracking branch 'upstream/master'
nllerandi3lift May 19, 2021
5490b62
Merge remote-tracking branch 'upstream/master'
nllerandi3lift May 21, 2021
2c51a91
Bump elliptic from 6.5.3 to 6.5.4
dependabot[bot] May 21, 2021
767d251
Merge branch 'prebid:master' into master
nllerandi3lift May 25, 2021
cc3ab52
Merge pull request #31 from triplelift-internal/dependabot/npm_and_ya…
Jun 10, 2021
a5f3a37
Revert "Bump elliptic from 6.5.3 to 6.5.4"
dangoldin Jun 10, 2021
3772908
Merge pull request #34 from triplelift-internal/revert-31-dependabot/…
Jun 10, 2021
38f6c04
Merge remote-tracking branch 'upstream/master'
nllerandi3lift Aug 11, 2021
07ba71a
Merge branch 'master' of https://github.com/triplelift-internal/Prebi…
nllerandi3lift Aug 11, 2021
6e94452
Merge branch 'prebid:master' into master
nllerandi3lift Sep 22, 2021
41e1db7
increases instream TTL
nllerandi3lift Sep 22, 2021
87d2f0b
Merge pull request #38 from triplelift-internal/TL-22981-instreamTTL
nllerandi3lift Sep 22, 2021
18b95e9
Merge branch 'prebid:master' into master
nllerandi3lift Oct 5, 2021
825791c
Merge branch 'prebid:master' into master
nllerandi3lift Oct 7, 2021
2a29d92
additional filterEid logic
nllerandi3lift Oct 7, 2021
d09bfc7
use id.id if present
nllerandi3lift Oct 7, 2021
85ecc2f
new tests
nllerandi3lift Oct 8, 2021
89284d2
rename
nllerandi3lift Oct 8, 2021
4c4095e
adds logwarn
nllerandi3lift Oct 8, 2021
63ea169
removes unnecessary try/catch
nllerandi3lift Oct 8, 2021
bf8adc7
uses var name in test
nllerandi3lift Oct 12, 2021
0eb280f
Merge pull request #39 from triplelift-internal/TL-23327-filterEids
nllerandi3lift Oct 12, 2021
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: 22 additions & 5 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { tryAppendQueryString, logMessage, isEmpty } from '../src/utils.js';
import { tryAppendQueryString, logMessage, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
Expand Down Expand Up @@ -262,19 +262,36 @@ function getPubCommonEids(bidRequest) {
function getEids(bidRequest, type, source, rtiPartner) {
return bidRequest
.map(getUserId(type)) // bids -> userIds of a certain type
.filter((x) => !!x) // filter out null userIds
.filter(filterEids(type)) // filter out unqualified userIds
.map(formatEid(source, rtiPartner)); // userIds -> eid objects
}

const filterEids = type => (userId, i, arr) => {
let isValidUserId =
!!userId && // is not null nor empty
(isStr(userId)
? !!userId
: isPlainObject(userId) && // or, is object
!isArray(userId) && // not an array
!isEmpty(userId) && // is not empty
userId.id && // contains nested id field
isStr(userId.id) && // nested id field is a string
!!userId.id); // that is not empty
if (!isValidUserId && arr[0] !== undefined) {
logWarn(`Triplelift: invalid ${type} userId format`);
}
return isValidUserId;
};

function getUserId(type) {
return (bid) => (bid && bid.userId && bid.userId[type]);
return bid => bid && bid.userId && bid.userId[type];
}

function formatEid(source, rtiPartner) {
return (id) => ({
return (userId) => ({
source,
uids: [{
id,
id: userId.id ? userId.id : userId,
ext: { rtiPartner }
}]
});
Expand Down
128 changes: 128 additions & 0 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,134 @@ describe('triplelift adapter', function () {
expect(payload.user.ext.eids).to.have.lengthOf(4);
});

it('should remove malformed ids that would otherwise break call', function () {
let tdidId = '6bca7f6b-a98a-46c0-be05-6020f7604598';
let idlEnvId = null; // fail; can't be null
let criteoId = '53e30ea700424f7bbdd793b02abc5d7';
let pubcid = ''; // fail; can't be empty string

let bidRequestsMultiple = [
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } },
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } },
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }
];

let request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest);
let payload = request.data;

expect(payload.user).to.deep.equal({
ext: {
eids: [
{
source: 'adserver.org',
uids: [
{
id: tdidId,
ext: { rtiPartner: 'TDID' }
}
],
},
{
source: 'criteo.com',
uids: [
{
id: criteoId,
ext: { rtiPartner: 'criteoId' }
}
]
}
]
}
});

expect(payload.user.ext.eids).to.be.an('array');
expect(payload.user.ext.eids).to.have.lengthOf(2);

tdidId = {}; // fail; can't be empty object
idlEnvId = { id: '987654' }; // pass
criteoId = [{ id: '123456' }]; // fail; can't be an array
pubcid = '3261d8ad-435d-481d-abd1-9f1a9ec99f0e'; // pass

bidRequestsMultiple = [
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } },
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } },
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }
];

request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest);
payload = request.data;

expect(payload.user).to.deep.equal({
ext: {
eids: [
{
source: 'liveramp.com',
uids: [
{
id: '987654',
ext: { rtiPartner: 'idl' }
}
]
},
{
source: 'pubcid.org',
uids: [
{
id: pubcid,
ext: { rtiPartner: 'pubcid' }
}
]
}
]
}
});

expect(payload.user.ext.eids).to.be.an('array');
expect(payload.user.ext.eids).to.have.lengthOf(2);

tdidId = { id: '987654' }; // pass
idlEnvId = { id: 987654 }; // fail; can't be an int
criteoId = '53e30ea700424f7bbdd793b02abc5d7'; // pass
pubcid = { id: '' }; // fail; can't be an empty string

bidRequestsMultiple = [
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } },
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } },
{ ...bidRequests[0], userId: { tdid: tdidId, idl_env: idlEnvId, criteoId, pubcid } }
];

request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest);
payload = request.data;

expect(payload.user).to.deep.equal({
ext: {
eids: [
{
source: 'adserver.org',
uids: [
{
id: '987654',
ext: { rtiPartner: 'TDID' }
}
],
},
{
source: 'criteo.com',
uids: [
{
id: criteoId,
ext: { rtiPartner: 'criteoId' }
}
]
}
]
}
});

expect(payload.user.ext.eids).to.be.an('array');
expect(payload.user.ext.eids).to.have.lengthOf(2);
});

it('should return a query string for TL call', function () {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
const url = request.url;
Expand Down