Skip to content

Commit

Permalink
33across ID System: Store hashed email when feature is enabled via co…
Browse files Browse the repository at this point in the history
…nfig (prebid#12630)

* Allow to read hashed email from 33across global

* refactoring of supplemental IDs

* store hashed email as another FP supplemental ID.

* split existing unit test about successful 33across ID system response.

* should clear hashed email if 33x response doesn't contain ID

* rename some of the internal 33x ID system variables

* code review feedback. HEM sources order & var rename
  • Loading branch information
carlosfelix authored Jan 13, 2025
1 parent 743f100 commit ea87c0e
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 26 deletions.
87 changes: 64 additions & 23 deletions modules/33acrossIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function calculateResponseObj(response) {
};
}

function calculateQueryStringParams({ pid, hem }, gdprConsentData, enabledStorageTypes) {
function calculateQueryStringParams({ pid, pubProvidedHem }, gdprConsentData, enabledStorageTypes) {
const uspString = uspDataHandler.getConsentData();
const coppaValue = coppaDataHandler.getCoppa();
const gppConsent = gppDataHandler.getConsentData();
Expand Down Expand Up @@ -98,9 +98,9 @@ function calculateQueryStringParams({ pid, hem }, gdprConsentData, enabledStorag
params.tp = encodeURIComponent(tp);
}

const hemParam = hem || getStoredValue(STORAGE_HEM_KEY, enabledStorageTypes);
if (hemParam) {
params.sha256 = encodeURIComponent(hemParam);
const hem = pubProvidedHem || getStoredValue(STORAGE_HEM_KEY, enabledStorageTypes);
if (hem) {
params.sha256 = encodeURIComponent(hem);
}

return params;
Expand Down Expand Up @@ -145,10 +145,51 @@ function getStoredValue(key, enabledStorageTypes) {
return storedValue;
}

function handleSupplementalId(key, id, storageConfig) {
id
? storeValue(key, id, storageConfig)
: deleteFromStorage(key);
function filterEnabledSupplementalIds({ tp, fp, hem }, { storeFpid, storeTpid, envelopeAvailable }) {
const ids = [];

if (storeFpid) {
ids.push(
/**
* [
* <storage key>,
* < ID value to store or remove >,
* < clear flag: indicates if existing storage item should be removed or not based on certain condition>
* ]
*/
[STORAGE_FPID_KEY, fp, !fp],
[STORAGE_HEM_KEY, hem, !envelopeAvailable] // Clear hashed email if envelope is not available
);
}

if (storeTpid) {
ids.push([STORAGE_TPID_KEY, tp, !tp]);
}

return ids;
}

function updateSupplementalIdStorage(supplementalId, storageConfig) {
const [ key, id, clear ] = supplementalId;

if (clear) {
deleteFromStorage(key);

return;
}

if (id) {
storeValue(key, id, storageConfig);
}
}

function handleSupplementalIds(ids, { enabledStorageTypes, expires, ...options }) {
filterEnabledSupplementalIds(ids, options).forEach((supplementalId) => {
updateSupplementalIdStorage(supplementalId, {
enabledStorageTypes,
expires
})
});
}

/** @type {Submodule} */
Expand Down Expand Up @@ -197,8 +238,10 @@ export const thirtyThreeAcrossIdSubmodule = {
const {
storeFpid = DEFAULT_1PID_SUPPORT,
storeTpid = DEFAULT_TPID_SUPPORT, apiUrl = API_URL,
...options
pid,
hem
} = params;
const pubProvidedHem = hem || window._33across?.hem?.sha256;

return {
callback(cb) {
Expand All @@ -218,19 +261,17 @@ export const thirtyThreeAcrossIdSubmodule = {
});
}

if (storeFpid) {
handleSupplementalId(STORAGE_FPID_KEY, responseObj.fp, {
enabledStorageTypes,
expires: storageConfig.expires
});
}

if (storeTpid) {
handleSupplementalId(STORAGE_TPID_KEY, responseObj.tp, {
enabledStorageTypes,
expires: storageConfig.expires
});
}
handleSupplementalIds({
fp: responseObj.fp,
tp: responseObj.tp,
hem: pubProvidedHem
}, {
storeFpid,
storeTpid,
envelopeAvailable: !!responseObj.envelope,
enabledStorageTypes,
expires: storageConfig.expires
});

cb(responseObj.envelope);
},
Expand All @@ -239,7 +280,7 @@ export const thirtyThreeAcrossIdSubmodule = {

cb();
}
}, calculateQueryStringParams(options, gdprConsentData, enabledStorageTypes), {
}, calculateQueryStringParams({ pid, pubProvidedHem }, gdprConsentData, enabledStorageTypes), {
method: 'GET',
withCredentials: true
});
Expand Down
3 changes: 2 additions & 1 deletion modules/33acrossIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ The following settings are available in the `params` property in `userSync.userI

### HEM Collection

33Across ID System supports user's hashed email, if available in storage.
33Across ID System supports user's hashed emails (HEMs). HEMs could be collected from 3 different sources in following
priority order: `hem` configuration parameter, global `_33across.hem.sha256` field or from storage (cookie or local storage).
Loading

0 comments on commit ea87c0e

Please sign in to comment.