Skip to content
6 changes: 5 additions & 1 deletion modules/startioBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
53 changes: 6 additions & 47 deletions modules/startioIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`);
}
Expand All @@ -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 }
Expand All @@ -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: {
Expand Down
11 changes: 10 additions & 1 deletion modules/startioIdSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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` |
28 changes: 16 additions & 12 deletions test/spec/modules/startioIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand All @@ -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 () {
Expand All @@ -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': {
Expand Down Expand Up @@ -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);
});
});
});
Loading