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

Kargo Bid Adapter: add GPP support #9812

Merged
merged 1 commit into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 22 additions & 4 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -229,14 +229,17 @@ 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();

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;
Expand All @@ -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)
});
}
}
Expand Down Expand Up @@ -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 || {}
Expand Down Expand Up @@ -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;
}

Expand Down
21 changes: 12 additions & 9 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down