-
Notifications
You must be signed in to change notification settings - Fork 0
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
33Across UIM: Add cookie storage support for first-party ID #78
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -9,7 +9,7 @@ import { logMessage, logError } from '../src/utils.js'; | |||
import { ajaxBuilder } from '../src/ajax.js'; | ||||
import { submodule } from '../src/hook.js'; | ||||
import { uspDataHandler, coppaDataHandler, gppDataHandler } from '../src/adapterManager.js'; | ||||
import { getStorageManager } from '../src/storageManager.js'; | ||||
import { getStorageManager, STORAGE_TYPE_COOKIES, STORAGE_TYPE_LOCALSTORAGE } from '../src/storageManager.js'; | ||||
import { MODULE_TYPE_UID } from '../src/activities/modules.js'; | ||||
|
||||
const MODULE_NAME = '33acrossId'; | ||||
|
@@ -44,7 +44,7 @@ function calculateResponseObj(response) { | |||
}; | ||||
} | ||||
|
||||
function calculateQueryStringParams(pid, gdprConsentData) { | ||||
function calculateQueryStringParams(pid, gdprConsentData, storageConfig) { | ||||
const uspString = uspDataHandler.getConsentData(); | ||||
const gdprApplies = Boolean(gdprConsentData?.gdprApplies); | ||||
const coppaValue = coppaDataHandler.getCoppa(); | ||||
|
@@ -73,14 +73,49 @@ function calculateQueryStringParams(pid, gdprConsentData) { | |||
params.gdpr_consent = gdprConsentData.consentString; | ||||
} | ||||
|
||||
const fp = storage.getDataFromLocalStorage(STORAGE_FPID_KEY); | ||||
const fp = getStoredValue(STORAGE_FPID_KEY, storageConfig); | ||||
if (fp) { | ||||
params.fp = fp; | ||||
} | ||||
|
||||
return params; | ||||
} | ||||
|
||||
function deleteFromStorage(key) { | ||||
if (storage.cookiesAreEnabled()) { | ||||
const expiredDate = new Date(0).toUTCString(); | ||||
|
||||
storage.setCookie(key, '', expiredDate, 'Lax'); | ||||
} | ||||
|
||||
storage.removeDataFromLocalStorage(key); | ||||
} | ||||
|
||||
function storeValue(key, value, storageConfig = {}) { | ||||
if (storageConfig.type === STORAGE_TYPE_COOKIES && storage.cookiesAreEnabled()) { | ||||
const expirationInMs = 60 * 60 * 24 * 1000 * storageConfig.expires; | ||||
const expirationTime = new Date(Date.now() + expirationInMs); | ||||
|
||||
storage.setCookie(key, value, expirationTime.toUTCString(), 'Lax'); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that we are not specifying an domain per Prebid.js/src/storageManager.js Line 56 in db9d236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's correct, the subdomain is included. I've verified this behavior and that's how most of the IdSystems set the cookies, without a hostname, since that part is handled by the storage manager util. |
||||
} else if (storageConfig.type === STORAGE_TYPE_LOCALSTORAGE) { | ||||
storage.setDataInLocalStorage(key, value); | ||||
} | ||||
} | ||||
|
||||
function getStoredValue(key, storageConfig = {}) { | ||||
if (storageConfig.type === STORAGE_TYPE_COOKIES && storage.cookiesAreEnabled()) { | ||||
return storage.getCookie(key); | ||||
} else if (storageConfig.type === STORAGE_TYPE_LOCALSTORAGE) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about checking whether LocalStorage is enabled via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in the case of local storage, each function checks internally if local storage storage is enabled e.g., here is how setDataInLocalStorage is defined:
|
||||
return storage.getDataFromLocalStorage(key); | ||||
} | ||||
} | ||||
|
||||
function handleFpId(fpId, storageConfig = {}) { | ||||
fpId | ||||
? storeValue(STORAGE_FPID_KEY, fpId, storageConfig) | ||||
: deleteFromStorage(STORAGE_FPID_KEY); | ||||
} | ||||
|
||||
/** @type {Submodule} */ | ||||
export const thirthyThreeAcrossIdSubmodule = { | ||||
/** | ||||
|
@@ -111,7 +146,7 @@ export const thirthyThreeAcrossIdSubmodule = { | |||
* @param {SubmoduleConfig} [config] | ||||
* @returns {IdResponse|undefined} | ||||
*/ | ||||
getId({ params = { } }, gdprConsentData) { | ||||
getId({ params = { }, storage }, gdprConsentData) { | ||||
if (typeof params.pid !== 'string') { | ||||
logError(`${MODULE_NAME}: Submodule requires a partner ID to be defined`); | ||||
|
||||
|
@@ -132,11 +167,7 @@ export const thirthyThreeAcrossIdSubmodule = { | |||
logError(`${MODULE_NAME}: ID reading error:`, err); | ||||
} | ||||
|
||||
if (responseObj.fp) { | ||||
storage.setDataInLocalStorage(STORAGE_FPID_KEY, responseObj.fp); | ||||
} else { | ||||
storage.removeDataFromLocalStorage(STORAGE_FPID_KEY); | ||||
} | ||||
handleFpId(responseObj.fp, storage); | ||||
|
||||
cb(responseObj.envelope); | ||||
}, | ||||
|
@@ -145,7 +176,7 @@ export const thirthyThreeAcrossIdSubmodule = { | |||
|
||||
cb(); | ||||
} | ||||
}, calculateQueryStringParams(pid, gdprConsentData), { method: 'GET', withCredentials: true }); | ||||
}, calculateQueryStringParams(pid, gdprConsentData, storage), { method: 'GET', withCredentials: true }); | ||||
} | ||||
}; | ||||
}, | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
storage
is default of{}
ortype
is not set? Also what is the expected structure ofstorageConfig
the pub should pass? Have we documented this in the md?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we won't be storing any values if the storage is
{}
or the type is not set.. that's the behavior that can be found in the baseID modulemodules/userId/index.js
as well.The recommended structure is part of the documentation --> https://docs.prebid.org/dev-docs/modules/userid-submodules/33across.html