From 94bb619b961cfec0b19bc11fb70b89f96e7b2d0c Mon Sep 17 00:00:00 2001 From: Patrick Loughrey Date: Mon, 4 Mar 2024 13:13:42 -0500 Subject: [PATCH] Triplelift Bid Adapter: Optimize EID Signals (#11168) * MPY-77: Updated EID logic to ingest as is * MPY-77: Updated EID logic to ingest as is --- modules/tripleliftBidAdapter.js | 88 +----- .../spec/modules/tripleliftBidAdapter_spec.js | 287 ++++-------------- 2 files changed, 63 insertions(+), 312 deletions(-) diff --git a/modules/tripleliftBidAdapter.js b/modules/tripleliftBidAdapter.js index bfbf1409c1b..fc0d73dc44b 100644 --- a/modules/tripleliftBidAdapter.js +++ b/modules/tripleliftBidAdapter.js @@ -1,4 +1,5 @@ -import { logMessage, logError, isEmpty, isStr, isPlainObject, isArray, logWarn } from '../src/utils.js'; +import * as utils from '../src/utils.js'; +import { logMessage, logError, isEmpty, 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'; @@ -184,17 +185,12 @@ function _buildPostBody(bidRequests, bidderRequest) { return imp; }); - let eids = [ - ...getUnifiedIdEids([bidRequests[0]]), - ...getIdentityLinkEids([bidRequests[0]]), - ...getCriteoEids([bidRequests[0]]), - ...getPubCommonEids([bidRequests[0]]), - ...getUniversalEids(bidRequests[0]) - ]; + let eids = []; - if (eids.length > 0) { + if (bidRequests[0].userIdAsEids) { + eids = utils.deepAccess(bidRequests[0], 'userIdAsEids'); data.user = { - ext: {eids} + ext: { eids } }; } @@ -363,78 +359,6 @@ function _getExt(schain, fpd) { return ext; } -function getUnifiedIdEids(bidRequest) { - return getEids(bidRequest, 'tdid', 'adserver.org', 'TDID'); -} - -function getIdentityLinkEids(bidRequest) { - return getEids(bidRequest, 'idl_env', 'liveramp.com', 'idl'); -} - -function getCriteoEids(bidRequest) { - return getEids(bidRequest, 'criteoId', 'criteo.com', 'criteoId'); -} - -function getPubCommonEids(bidRequest) { - return getEids(bidRequest, 'pubcid', 'pubcid.org', 'pubcid'); -} - -function getUniversalEids(bidRequest) { - let common = ['adserver.org', 'liveramp.com', 'criteo.com', 'pubcid.org']; - let eids = []; - if (bidRequest.userIdAsEids) { - bidRequest.userIdAsEids.forEach(id => { - try { - if (common.indexOf(id.source) === -1) { - let uids = id.uids.map(uid => ({ id: uid.id, ext: { rtiPartner: id.source } })); - eids.push({ source: id.source, uids }); - } - } catch (err) { - logWarn(`Triplelift: Error attempting to add ${id} to bid request`, err); - } - }); - } - return eids; -} - -function getEids(bidRequest, type, source, rtiPartner) { - return bidRequest - .map(getUserId(type)) // bids -> userIds of a certain type - .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]; -} - -function formatEid(source, rtiPartner) { - return (userId) => ({ - source, - uids: [{ - id: userId.id ? userId.id : userId, - ext: { rtiPartner } - }] - }); -} - function _sizes(sizeArray) { let sizes = sizeArray.filter(_isValidSize); return sizes.map(function(size) { diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js index 275b9b3bfee..851425574d0 100644 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ b/test/spec/modules/tripleliftBidAdapter_spec.js @@ -736,258 +736,83 @@ describe('triplelift adapter', function () { }); it('should add tdid to the payload if included', function () { - const id = '6bca7f6b-a98a-46c0-be05-6020f7604598'; - bidRequests[0].userId.tdid = id; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'adserver.org', uids: [{id, ext: {rtiPartner: 'TDID'}}]}]}}); - }); - - it('should add idl_env to the payload if included', function () { - const id = 'XY6104gr0njcH9UDIR7ysFFJcm2XNpqeJTYslleJ_cMlsFOfZI'; - bidRequests[0].userId.idl_env = id; + const tdid = '6bca7f6b-a98a-46c0-be05-6020f7604598'; + bidRequests[0].userIdAsEids = [ + { + source: 'adserver.org', + uids: [ + { + atype: 1, + ext: { + rtiPartner: 'TDID' + }, + id: tdid + } + ] + }, + ]; const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); const payload = request.data; expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'liveramp.com', uids: [{id, ext: {rtiPartner: 'idl'}}]}]}}); + expect(payload.user).to.deep.equal({ext: {eids: [{source: 'adserver.org', uids: [{id: tdid, atype: 1, ext: {rtiPartner: 'TDID'}}]}]}}); }); it('should add criteoId to the payload if included', function () { const id = '53e30ea700424f7bbdd793b02abc5d7'; - bidRequests[0].userId.criteoId = id; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'criteo.com', uids: [{id, ext: {rtiPartner: 'criteoId'}}]}]}}); - }); - - it('should add adqueryId to the payload if included', function () { - const id = '%7B%22qid%22%3A%229c985f8cc31d9b3c000d%22%7D'; - bidRequests[0].userIdAsEids = [{ source: 'adquery.io', uids: [{ id }] }]; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'adquery.io', uids: [{id, ext: {rtiPartner: 'adquery.io'}}]}]}}); - }); - - it('should add amxRtbId to the payload if included', function () { - const id = 'Ok9JQkBM-UFlAXEZQ-UUNBQlZOQzgrUFhW-UUNBQkRQTUBPQVpVWVxNXlZUUF9AUFhAUF9PXFY/'; - bidRequests[0].userIdAsEids = [{ source: 'amxdt.net', uids: [{ id }] }]; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'amxdt.net', uids: [{id, ext: {rtiPartner: 'amxdt.net'}}]}]}}); - }); - - it('should add tdid, idl_env and criteoId to the payload if both are included', function () { - const tdidId = '6bca7f6b-a98a-46c0-be05-6020f7604598'; - const idlEnvId = 'XY6104gr0njcH9UDIR7ysFFJcm2XNpqeJTYslleJ_cMlsFOfZI'; - const criteoId = '53e30ea700424f7bbdd793b02abc5d7'; - bidRequests[0].userId.tdid = tdidId; - bidRequests[0].userId.idl_env = idlEnvId; - bidRequests[0].userId.criteoId = criteoId; - - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ - ext: { - eids: [ - { - source: 'adserver.org', - uids: [ - { - id: tdidId, - ext: { rtiPartner: 'TDID' } - } - ], - }, - { - source: 'liveramp.com', - uids: [ - { - id: idlEnvId, - ext: { rtiPartner: 'idl' } - } - ] - }, + bidRequests[0].userIdAsEids = [ + { + source: 'criteo.com', + uids: [ { - source: 'criteo.com', - uids: [ - { - id: criteoId, - ext: { rtiPartner: 'criteoId' } - } - ] + atype: 1, + ext: { + rtiPartner: 'criteoId' + }, + id: id } ] - } - }); - }); - - it('should consolidate user ids from multiple bid requests', function () { - const tdidId = '6bca7f6b-a98a-46c0-be05-6020f7604598'; - const idlEnvId = 'XY6104gr0njcH9UDIR7ysFFJcm2XNpqeJTYslleJ_cMlsFOfZI'; - const criteoId = '53e30ea700424f7bbdd793b02abc5d7'; - const pubcid = '3261d8ad-435d-481d-abd1-9f1a9ec99f0e'; - - const 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 } } + }, ]; - - const request = tripleliftAdapterSpec.buildRequests(bidRequestsMultiple, bidderRequest); + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); const payload = request.data; - - expect(payload.user).to.deep.equal({ - ext: { - eids: [ - { - source: 'adserver.org', - uids: [ - { - id: tdidId, - ext: { rtiPartner: 'TDID' } - } - ], - }, - { - source: 'liveramp.com', - uids: [ - { - id: idlEnvId, - ext: { rtiPartner: 'idl' } - } - ] - }, - { - source: 'criteo.com', - uids: [ - { - id: criteoId, - ext: { rtiPartner: 'criteoId' } - } - ] - }, - { - source: 'pubcid.org', - uids: [ - { - id: '3261d8ad-435d-481d-abd1-9f1a9ec99f0e', - ext: { rtiPartner: 'pubcid' } - } - ] - } - ] - } - }); - - expect(payload.user.ext.eids).to.be.an('array'); - expect(payload.user.ext.eids).to.have.lengthOf(4); + expect(payload).to.exist; + expect(payload.user).to.deep.equal({ext: {eids: [{source: 'criteo.com', uids: [{id: id, atype: 1, ext: {rtiPartner: 'criteoId'}}]}]}}); }); - 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' } - } - ], - }, + it('should add tdid and criteoId to the payload if both are included', function () { + const tdid = '6bca7f6b-a98a-46c0-be05-6020f7604598'; + const criteoId = '53e30ea700424f7bbdd793b02abc5d7'; + bidRequests[0].userIdAsEids = [ + { + source: 'adserver.org', + uids: [ { - source: 'criteo.com', - uids: [ - { - id: criteoId, - ext: { rtiPartner: 'criteoId' } - } - ] + atype: 1, + ext: { + rtiPartner: 'TDID' + }, + id: tdid } ] - } - }); - - 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: 'criteo.com', + uids: [ { - source: 'pubcid.org', - uids: [ - { - id: pubcid, - ext: { rtiPartner: 'pubcid' } - } - ] + atype: 1, + ext: { + rtiPartner: 'criteoId' + }, + id: criteoId } ] - } - }); - - 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; + const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); + const payload = request.data; + expect(payload).to.exist; expect(payload.user).to.deep.equal({ ext: { eids: [ @@ -995,7 +820,8 @@ describe('triplelift adapter', function () { source: 'adserver.org', uids: [ { - id: '987654', + id: tdid, + atype: 1, ext: { rtiPartner: 'TDID' } } ], @@ -1005,6 +831,7 @@ describe('triplelift adapter', function () { uids: [ { id: criteoId, + atype: 1, ext: { rtiPartner: 'criteoId' } } ]