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

33Across UIM: Add cookie storage support for first-party ID #78

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

carlosfelix
Copy link
Collaborator

No description provided.

function getStoredValue(key, storageConfig = {}) {
if (storageConfig.type === STORAGE_TYPE_COOKIES && storage.cookiesAreEnabled()) {
return storage.getCookie(key);
} else if (storageConfig.type === STORAGE_TYPE_LOCALSTORAGE) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about checking whether LocalStorage is enabled via localStorageIsEnabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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:

 const setDataInLocalStorage = function (key, value, done) {
    let cb = function (result) {
      if (result && result.valid && hasLocalStorage()) { // <-- hasLocalStorage is called
        window.localStorage.setItem(key, value);
      }
    }
    return schedule(cb, STORAGE_TYPE_LOCALSTORAGE, done);
  }

if (fp) {
params.fp = fp;
}

return params;
}

function handleFpId(fpId, storageConfig = {}) {
if (!fpId) {
return storage.removeDataFromLocalStorage(STORAGE_FPID_KEY);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about removing from cookie?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, that part is missing.. working on it.

const expirationInMs = 60 * 60 * 24 * 1000 * storageConfig.expires;
const expirationTime = new Date(Date.now() + expirationInMs);

storage.setCookie(key, value, expirationTime.toUTCString(), 'Lax');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we are not specifying an domain per

* If not specified, defaults to the host portion of the current document location.
it will default to hostname which I am assuming will also include subdomain if the location url includes that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

}

function storeValue(key, value, storageConfig = {}) {
if (storageConfig.type === STORAGE_TYPE_COOKIES && storage.cookiesAreEnabled()) {
Copy link
Collaborator

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 {} or type is not set? Also what is the expected structure of storageConfig the pub should pass? Have we documented this in the md?

Copy link
Collaborator Author

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 module modules/userId/index.js as well.

The recommended structure is part of the documentation --> https://docs.prebid.org/dev-docs/modules/userid-submodules/33across.html

pbjs.setConfig({
  userSync: {
    userIds: [{
      name: "33acrossId",
      params: {
        pid: "0010b00002GYU4eBAH" // Example ID
      },
      storage: {
        name: "33acrossId",
        type: "html5",
        expires: 90,
        refreshInSeconds: 8 * 3600
      }
    }]
  }
});

@curlyblueeagle curlyblueeagle merged commit 21ec0c6 into uim_fpid Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants