From db0b1bdc23fd89b94dbd43bad652d3997ed15b15 Mon Sep 17 00:00:00 2001 From: Nick Llerandi Date: Tue, 9 Apr 2024 11:19:52 -0400 Subject: [PATCH] refactors code for userIds; updates userId tests (#29) (#11298) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: “Nick <“nick.llerandi”@kargo.com> --- modules/kargoBidAdapter.js | 41 ++++++++++++----------- test/spec/modules/kargoBidAdapter_spec.js | 36 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index e86d7022987..fe22915223e 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -359,56 +359,57 @@ function getUserIds(tdidAdapter, usp, gdpr, eids, gpp) { crbIDs: crb.syncIds || {} }; - // Pull Trade Desk ID from adapter - if (tdidAdapter) { - userIds.tdID = tdidAdapter; - } - - // Pull Trade Desk ID from our storage + // Pull Trade Desk ID if (!tdidAdapter && crb.tdID) { userIds.tdID = crb.tdID; + } else if (tdidAdapter) { + userIds.tdID = tdidAdapter; } + // USP if (usp) { userIds.usp = usp; } - try { - if (gdpr) { - userIds['gdpr'] = { - consent: gdpr.consentString || '', - applies: !!gdpr.gdprApplies, - } - } - } catch (e) { + // GDPR + if (gdpr) { + userIds.gdpr = { + consent: gdpr.consentString || '', + applies: !!gdpr.gdprApplies, + }; } + // Kargo ID if (crb.lexId != null) { userIds.kargoID = crb.lexId; } + // Client ID if (crb.clientId != null) { userIds.clientID = crb.clientId; } + // Opt Out if (crb.optOut != null) { userIds.optOut = crb.optOut; } + // User ID Sub-Modules (userIdAsEids) if (eids != null) { userIds.sharedIDEids = eids; } + // GPP if (gpp) { - const parsedGPP = {} - if (gpp && gpp.consentString) { - parsedGPP.gppString = gpp.consentString + const parsedGPP = {}; + if (gpp.consentString) { + parsedGPP.gppString = gpp.consentString; } - if (gpp && gpp.applicableSections) { - parsedGPP.applicableSections = gpp.applicableSections + if (gpp.applicableSections) { + parsedGPP.applicableSections = gpp.applicableSections; } if (!isEmpty(parsedGPP)) { - userIds.gpp = parsedGPP + userIds.gpp = parsedGPP; } } diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index 20a43d0397f..eb8f310201d 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -112,6 +112,24 @@ describe('kargo adapter tests', function () { } } ] + }, + { + 'source': 'adquery.io', + 'uids': [ + { + 'id': 'adqueryId-123', + 'atype': 1 + } + ] + }, + { + 'source': 'criteo.com', + 'uids': [ + { + 'id': 'criteoId-456', + 'atype': 1 + } + ] } ], floorData: { @@ -582,6 +600,24 @@ describe('kargo adapter tests', function () { } } ] + }, + { + source: 'adquery.io', + uids: [ + { + id: 'adqueryId-123', + atype: 1 + } + ] + }, + { + source: 'criteo.com', + uids: [ + { + id: 'criteoId-456', + atype: 1 + } + ] } ], data: [