From e388cc3811c37c5d5dd1e7037121ad1d54d09ddc Mon Sep 17 00:00:00 2001 From: Jeremy Sadwith Date: Fri, 14 Apr 2023 17:34:10 -0400 Subject: [PATCH] KargoBidAdapter: GPP Support --- modules/kargoBidAdapter.js | 26 +++++++++++++++++++---- test/spec/modules/kargoBidAdapter_spec.js | 21 ++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index ecc40b26aa2..b612c88bb12 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -47,7 +47,7 @@ const SUA_ATTRIBUTES = [ const CERBERUS = Object.freeze({ KEY: 'krg_crb', - SYNC_URL: 'https://crb.kargo.com/api/v1/initsyncrnd/{UUID}?seed={SEED}&idx={INDEX}&gdpr={GDPR}&gdpr_consent={GDPR_CONSENT}&us_privacy={US_PRIVACY}', + SYNC_URL: 'https://crb.kargo.com/api/v1/initsyncrnd/{UUID}?seed={SEED}&idx={INDEX}&gdpr={GDPR}&gdpr_consent={GDPR_CONSENT}&us_privacy={US_PRIVACY}&gpp={GPP_STRING}&gpp_sid={GPP_SID}', SYNC_COUNT: 5, PAGE_VIEW_ID: 'pageViewId', PAGE_VIEW_TIMESTAMP: 'pageViewTimestamp', @@ -94,7 +94,7 @@ function buildRequests(validBidRequests, bidderRequest) { ] }, imp: impressions, - user: getUserIds(tdidAdapter, bidderRequest.uspConsent, bidderRequest.gdprConsent, firstBidRequest.userIdAsEids), + user: getUserIds(tdidAdapter, bidderRequest.uspConsent, bidderRequest.gdprConsent, firstBidRequest.userIdAsEids, bidderRequest.gppConsent), }); const reqCount = getRequestCount() @@ -229,7 +229,7 @@ function interpretResponse(response, bidRequest) { return bidResponses; } -function getUserSyncs(syncOptions, responses, gdprConsent, usPrivacy) { +function getUserSyncs(syncOptions, _, gdprConsent, usPrivacy, gppConsent) { const syncs = []; const seed = _generateRandomUUID(); const clientId = getClientId(); @@ -237,6 +237,9 @@ function getUserSyncs(syncOptions, responses, gdprConsent, usPrivacy) { var gdpr = (gdprConsent && gdprConsent.gdprApplies) ? 1 : 0; var gdprConsentString = (gdprConsent && gdprConsent.consentString) ? gdprConsent.consentString : ''; + var gppString = (gppConsent && gppConsent.consentString) ? gppConsent.consentString : ''; + var gppApplicableSections = (gppConsent && gppConsent.applicableSections && Array.isArray(gppConsent.applicableSections)) ? gppConsent.applicableSections.join(',') : ''; + // don't sync if opted out via usPrivacy if (typeof usPrivacy == 'string' && usPrivacy.length == 4 && usPrivacy[0] == 1 && usPrivacy[2] == 'Y') { return syncs; @@ -251,6 +254,8 @@ function getUserSyncs(syncOptions, responses, gdprConsent, usPrivacy) { .replace('{GDPR}', gdpr) .replace('{GDPR_CONSENT}', gdprConsentString) .replace('{US_PRIVACY}', usPrivacy || '') + .replace('{GPP_STRING}', gppString) + .replace('{GPP_SID}', gppApplicableSections) }); } } @@ -329,7 +334,7 @@ function getLocalStorageSafely(key) { } } -function getUserIds(tdidAdapter, usp, gdpr, eids) { +function getUserIds(tdidAdapter, usp, gdpr, eids, gpp) { const crb = spec._getCrb(); const userIds = { crbIDs: crb.syncIds || {} @@ -375,6 +380,19 @@ function getUserIds(tdidAdapter, usp, gdpr, eids) { userIds.sharedIDEids = eids; } + if (gpp) { + const parsedGPP = {} + if (gpp && gpp.consentString) { + parsedGPP.gppString = gpp.consentString + } + if (gpp && gpp.applicableSections) { + parsedGPP.applicableSections = gpp.applicableSections + } + if (!isEmpty(parsedGPP)) { + userIds.gpp = parsedGPP + } + } + return userIds; } diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index 260ac6c2132..d692cc67e26 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -524,9 +524,7 @@ describe('kargo adapter tests', function () { } const reqCount = requestCount++; - if (reqCount > 0) { - base.requestCount = reqCount - } + base.requestCount = reqCount if (expectedCRB != null) { if (expectedCRB.rawCRB != null) { @@ -894,8 +892,8 @@ describe('kargo adapter tests', function () { }); }); - function getUserSyncsWhenAllowed(gdprConsent, usPrivacy) { - return spec.getUserSyncs({iframeEnabled: true}, null, gdprConsent, usPrivacy); + function getUserSyncsWhenAllowed(gdprConsent, usPrivacy, gppConsent) { + return spec.getUserSyncs({iframeEnabled: true}, null, gdprConsent, usPrivacy, gppConsent); } function getUserSyncsWhenForbidden() { @@ -910,17 +908,17 @@ describe('kargo adapter tests', function () { shouldSimulateOutdatedBrowser = true; } - function getSyncUrl(index, gdprApplies, gdprConsentString, usPrivacy) { + function getSyncUrl(index, gdprApplies, gdprConsentString, usPrivacy, gpp, gppSid) { return { type: 'iframe', - url: `https://crb.kargo.com/api/v1/initsyncrnd/${clientId}?seed=3205e885-8d37-4139-b47e-f82cff268000&idx=${index}&gdpr=${gdprApplies}&gdpr_consent=${gdprConsentString}&us_privacy=${usPrivacy}` + url: `https://crb.kargo.com/api/v1/initsyncrnd/${clientId}?seed=3205e885-8d37-4139-b47e-f82cff268000&idx=${index}&gdpr=${gdprApplies}&gdpr_consent=${gdprConsentString}&us_privacy=${usPrivacy}&gpp=${gpp}&gpp_sid=${gppSid}` }; } - function getSyncUrls(gdprApplies, gdprConsentString, usPrivacy) { + function getSyncUrls(gdprApplies, gdprConsentString, usPrivacy, gpp, gppSid) { var syncs = []; for (var i = 0; i < 5; i++) { - syncs[i] = getSyncUrl(i, gdprApplies || 0, gdprConsentString || '', usPrivacy || ''); + syncs[i] = getSyncUrl(i, gdprApplies || 0, gdprConsentString || '', usPrivacy || '', gpp || '', gppSid || ''); } return syncs; } @@ -957,6 +955,11 @@ describe('kargo adapter tests', function () { safelyRun(() => expect(getUserSyncsWhenAllowed({ gdprApplies: true, consentString: 'consentstring' })).to.deep.equal(getSyncUrls(1, 'consentstring', ''))); }); + it('pass through gpp consent', function () { + turnOnClientId(); + safelyRun(() => expect(getUserSyncsWhenAllowed(null, null, { consentString: 'gppString', applicableSections: [-1] })).to.deep.equal(getSyncUrls('', '', '', 'gppString', '-1'))); + }); + it('no user syncs when there is outdated browser', function() { turnOnClientId(); simulateOutdatedBrowser();