diff --git a/modules/startioBidAdapter.md b/modules/startioBidAdapter.md index d74e0e64d3..b727acd319 100644 --- a/modules/startioBidAdapter.md +++ b/modules/startioBidAdapter.md @@ -102,7 +102,11 @@ To enable iframe-based user syncing for Start.io, include the `filterSettings` c pbjs.setConfig({ userSync: { userIds: [{ - name: 'startioId' + name: 'startioId', + storage: { + type: 'cookie&html5', + name: 'startioId' + } }], filterSettings: { iframe: { diff --git a/modules/startioIdSystem.js b/modules/startioIdSystem.js index aad91368af..637d69a65a 100644 --- a/modules/startioIdSystem.js +++ b/modules/startioIdSystem.js @@ -7,50 +7,13 @@ import { logError, formatQS } from '../src/utils.js'; import { submodule } from '../src/hook.js'; import { ajax } from '../src/ajax.js'; -import { getStorageManager } from '../src/storageManager.js'; -import { MODULE_TYPE_UID } from '../src/activities/modules.js'; import { getUserSyncParams } from '../libraries/userSyncUtils/userSyncUtils.js'; const MODULE_NAME = 'startioId'; +const GVLID = 1216; const DEFAULT_ENDPOINT = 'https://cs.startappnetwork.com/get-uid-obj?p=m4b8b3y4'; -const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME }); - -function getCachedId() { - let cachedId; - - if (storage.cookiesAreEnabled()) { - cachedId = storage.getCookie(MODULE_NAME); - } - - if (!cachedId && storage.hasLocalStorage()) { - const expirationStr = storage.getDataFromLocalStorage(`${MODULE_NAME}_exp`); - if (expirationStr) { - const expirationDate = new Date(expirationStr); - if (expirationDate > new Date()) { - cachedId = storage.getDataFromLocalStorage(MODULE_NAME); - } - } - } - - return cachedId || null; -} - -function storeId(id, expiresInDays) { - expiresInDays = expiresInDays || 90; - const expirationDate = new Date(Date.now() + expiresInDays * 24 * 60 * 60 * 1000).toUTCString(); - - if (storage.cookiesAreEnabled()) { - storage.setCookie(MODULE_NAME, id, expirationDate, 'None'); - } - - if (storage.hasLocalStorage()) { - storage.setDataInLocalStorage(`${MODULE_NAME}_exp`, expirationDate); - storage.setDataInLocalStorage(MODULE_NAME, id); - } -} - -function fetchIdFromServer(callback, expiresInDays, consentData) { +function fetchIdFromServer(callback, consentData) { const consentParams = getUserSyncParams( consentData?.gdpr, consentData?.usp, @@ -66,7 +29,6 @@ function fetchIdFromServer(callback, expiresInDays, consentData) { const responseObj = JSON.parse(response); if (responseObj && responseObj.uid) { responseId = responseObj.uid; - storeId(responseId, expiresInDays); } else { logError(`${MODULE_NAME}: Server response missing 'uid' field`); } @@ -85,6 +47,7 @@ function fetchIdFromServer(callback, expiresInDays, consentData) { export const startioIdSubmodule = { name: MODULE_NAME, + gvlid: GVLID, decode(value) { return value && typeof value === 'string' ? { 'startioId': value } @@ -94,14 +57,10 @@ export const startioIdSubmodule = { if (storedId) { return { id: storedId }; } - - const cachedId = getCachedId(); - if (cachedId) { - return { id: cachedId }; + if (config.storage && config.storage.expires == null) { + config.storage.expires = 90; } - const storageConfig = config && config.storage; - const expiresInDays = storageConfig && storageConfig.expires; - return { callback: (cb) => fetchIdFromServer(cb, expiresInDays, consentData) }; + return { callback: (cb) => fetchIdFromServer(cb, consentData) }; }, eids: { diff --git a/modules/startioIdSystem.md b/modules/startioIdSystem.md index 89c30f34b7..5c3de1bf96 100644 --- a/modules/startioIdSystem.md +++ b/modules/startioIdSystem.md @@ -12,7 +12,12 @@ To enable iframe-based user syncing for Start.io, include the `filterSettings` c pbjs.setConfig({ userSync: { userIds: [{ - name: 'startioId' + name: 'startioId', + storage: { + type: 'cookie&html5', // 'cookie', 'html5', or 'cookie&html5' + name: 'startioId', + expires: 90 // optional, 90 days by default + } }], filterSettings: { iframe: { @@ -33,3 +38,7 @@ The below parameters apply only to the Start.io User ID integration. | Param under userSync.userIds[] | Scope | Type | Description | Example | | --- | --- | --- | --- | --- | | name | Required | String | The name of this module. | `"startioId"` | +| storage | Required | Object | Storage configuration for the user ID. | | +| storage.type | Required | String | Type of storage: `"cookie"`, `"html5"`, or `"cookie&html5"`. | `"cookie&html5"` | +| storage.name | Required | String | The name used to store the user ID. | `"startioId"` | +| storage.expires | Optional | Number | Number of days before the stored ID expires. Defaults to `90`. | `365` | diff --git a/test/spec/modules/startioIdSystem_spec.js b/test/spec/modules/startioIdSystem_spec.js index 25d3d52a51..dbdc2096bb 100644 --- a/test/spec/modules/startioIdSystem_spec.js +++ b/test/spec/modules/startioIdSystem_spec.js @@ -2,11 +2,9 @@ import * as utils from '../../../src/utils.js'; import { server } from 'test/mocks/xhr.js'; import { startioIdSubmodule } from 'modules/startioIdSystem.js'; import { createEidsArray } from '../../../modules/userId/eids.js'; -import { getStorageManager } from '../../../src/storageManager.js'; describe('StartIO ID System', function () { let sandbox; - let storage; const validConfig = { params: {}, @@ -18,16 +16,6 @@ describe('StartIO ID System', function () { beforeEach(function () { sandbox = sinon.createSandbox(); sandbox.stub(utils, 'logError'); - storage = getStorageManager({ moduleType: 'userId', moduleName: 'startioId' }); - - // Clear any cached storage - if (storage.cookiesAreEnabled()) { - storage.setCookie('startioId', '', new Date(0).toUTCString()); - } - if (storage.hasLocalStorage()) { - storage.removeDataFromLocalStorage('startioId'); - storage.removeDataFromLocalStorage('startioId_exp'); - } }); afterEach(function () { @@ -39,6 +27,10 @@ describe('StartIO ID System', function () { expect(startioIdSubmodule.name).to.equal('startioId'); }); + it('should have gvlid', function () { + expect(startioIdSubmodule.gvlid).to.equal(1216); + }); + it('should have eids configuration', function () { expect(startioIdSubmodule.eids).to.deep.equal({ 'startioId': { @@ -207,5 +199,17 @@ describe('StartIO ID System', function () { expect(utils.logError.calledOnce).to.be.true; expect(utils.logError.args[0][0]).to.include('encountered an error'); }); + + it('should set default storage.expires to 90 when not provided', function () { + const config = { params: {}, storage: { type: 'html5', name: 'startioId' } }; + startioIdSubmodule.getId(config); + expect(config.storage.expires).to.equal(90); + }); + + it('should not override storage.expires when already set', function () { + const config = { params: {}, storage: { type: 'html5', name: 'startioId', expires: 365 } }; + startioIdSubmodule.getId(config); + expect(config.storage.expires).to.equal(365); + }); }); });