Skip to content

Commit 14be6cc

Browse files
authored
Merge pull request #3 from startappdev/remove-manual-storage-management
Remove manual storage management
2 parents 3937eaa + 95ae686 commit 14be6cc

4 files changed

Lines changed: 37 additions & 61 deletions

File tree

modules/startioBidAdapter.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,11 @@ To enable iframe-based user syncing for Start.io, include the `filterSettings` c
102102
pbjs.setConfig({
103103
userSync: {
104104
userIds: [{
105-
name: 'startioId'
105+
name: 'startioId',
106+
storage: {
107+
type: 'cookie&html5',
108+
name: 'startioId'
109+
}
106110
}],
107111
filterSettings: {
108112
iframe: {

modules/startioIdSystem.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,13 @@
77
import { logError, formatQS } from '../src/utils.js';
88
import { submodule } from '../src/hook.js';
99
import { ajax } from '../src/ajax.js';
10-
import { getStorageManager } from '../src/storageManager.js';
11-
import { MODULE_TYPE_UID } from '../src/activities/modules.js';
1210
import { getUserSyncParams } from '../libraries/userSyncUtils/userSyncUtils.js';
1311

1412
const MODULE_NAME = 'startioId';
13+
const GVLID = 1216;
1514
const DEFAULT_ENDPOINT = 'https://cs.startappnetwork.com/get-uid-obj?p=m4b8b3y4';
1615

17-
const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME });
18-
19-
function getCachedId() {
20-
let cachedId;
21-
22-
if (storage.cookiesAreEnabled()) {
23-
cachedId = storage.getCookie(MODULE_NAME);
24-
}
25-
26-
if (!cachedId && storage.hasLocalStorage()) {
27-
const expirationStr = storage.getDataFromLocalStorage(`${MODULE_NAME}_exp`);
28-
if (expirationStr) {
29-
const expirationDate = new Date(expirationStr);
30-
if (expirationDate > new Date()) {
31-
cachedId = storage.getDataFromLocalStorage(MODULE_NAME);
32-
}
33-
}
34-
}
35-
36-
return cachedId || null;
37-
}
38-
39-
function storeId(id, expiresInDays) {
40-
expiresInDays = expiresInDays || 90;
41-
const expirationDate = new Date(Date.now() + expiresInDays * 24 * 60 * 60 * 1000).toUTCString();
42-
43-
if (storage.cookiesAreEnabled()) {
44-
storage.setCookie(MODULE_NAME, id, expirationDate, 'None');
45-
}
46-
47-
if (storage.hasLocalStorage()) {
48-
storage.setDataInLocalStorage(`${MODULE_NAME}_exp`, expirationDate);
49-
storage.setDataInLocalStorage(MODULE_NAME, id);
50-
}
51-
}
52-
53-
function fetchIdFromServer(callback, expiresInDays, consentData) {
16+
function fetchIdFromServer(callback, consentData) {
5417
const consentParams = getUserSyncParams(
5518
consentData?.gdpr,
5619
consentData?.usp,
@@ -66,7 +29,6 @@ function fetchIdFromServer(callback, expiresInDays, consentData) {
6629
const responseObj = JSON.parse(response);
6730
if (responseObj && responseObj.uid) {
6831
responseId = responseObj.uid;
69-
storeId(responseId, expiresInDays);
7032
} else {
7133
logError(`${MODULE_NAME}: Server response missing 'uid' field`);
7234
}
@@ -85,6 +47,7 @@ function fetchIdFromServer(callback, expiresInDays, consentData) {
8547

8648
export const startioIdSubmodule = {
8749
name: MODULE_NAME,
50+
gvlid: GVLID,
8851
decode(value) {
8952
return value && typeof value === 'string'
9053
? { 'startioId': value }
@@ -94,14 +57,10 @@ export const startioIdSubmodule = {
9457
if (storedId) {
9558
return { id: storedId };
9659
}
97-
98-
const cachedId = getCachedId();
99-
if (cachedId) {
100-
return { id: cachedId };
60+
if (config.storage && config.storage.expires == null) {
61+
config.storage.expires = 90;
10162
}
102-
const storageConfig = config && config.storage;
103-
const expiresInDays = storageConfig && storageConfig.expires;
104-
return { callback: (cb) => fetchIdFromServer(cb, expiresInDays, consentData) };
63+
return { callback: (cb) => fetchIdFromServer(cb, consentData) };
10564
},
10665

10766
eids: {

modules/startioIdSystem.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ To enable iframe-based user syncing for Start.io, include the `filterSettings` c
1212
pbjs.setConfig({
1313
userSync: {
1414
userIds: [{
15-
name: 'startioId'
15+
name: 'startioId',
16+
storage: {
17+
type: 'cookie&html5', // 'cookie', 'html5', or 'cookie&html5'
18+
name: 'startioId',
19+
expires: 90 // optional, 90 days by default
20+
}
1621
}],
1722
filterSettings: {
1823
iframe: {
@@ -33,3 +38,7 @@ The below parameters apply only to the Start.io User ID integration.
3338
| Param under userSync.userIds[] | Scope | Type | Description | Example |
3439
| --- | --- | --- | --- | --- |
3540
| name | Required | String | The name of this module. | `"startioId"` |
41+
| storage | Required | Object | Storage configuration for the user ID. | |
42+
| storage.type | Required | String | Type of storage: `"cookie"`, `"html5"`, or `"cookie&html5"`. | `"cookie&html5"` |
43+
| storage.name | Required | String | The name used to store the user ID. | `"startioId"` |
44+
| storage.expires | Optional | Number | Number of days before the stored ID expires. Defaults to `90`. | `365` |

test/spec/modules/startioIdSystem_spec.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ import * as utils from '../../../src/utils.js';
22
import { server } from 'test/mocks/xhr.js';
33
import { startioIdSubmodule } from 'modules/startioIdSystem.js';
44
import { createEidsArray } from '../../../modules/userId/eids.js';
5-
import { getStorageManager } from '../../../src/storageManager.js';
65

76
describe('StartIO ID System', function () {
87
let sandbox;
9-
let storage;
108

119
const validConfig = {
1210
params: {},
@@ -18,16 +16,6 @@ describe('StartIO ID System', function () {
1816
beforeEach(function () {
1917
sandbox = sinon.createSandbox();
2018
sandbox.stub(utils, 'logError');
21-
storage = getStorageManager({ moduleType: 'userId', moduleName: 'startioId' });
22-
23-
// Clear any cached storage
24-
if (storage.cookiesAreEnabled()) {
25-
storage.setCookie('startioId', '', new Date(0).toUTCString());
26-
}
27-
if (storage.hasLocalStorage()) {
28-
storage.removeDataFromLocalStorage('startioId');
29-
storage.removeDataFromLocalStorage('startioId_exp');
30-
}
3119
});
3220

3321
afterEach(function () {
@@ -39,6 +27,10 @@ describe('StartIO ID System', function () {
3927
expect(startioIdSubmodule.name).to.equal('startioId');
4028
});
4129

30+
it('should have gvlid', function () {
31+
expect(startioIdSubmodule.gvlid).to.equal(1216);
32+
});
33+
4234
it('should have eids configuration', function () {
4335
expect(startioIdSubmodule.eids).to.deep.equal({
4436
'startioId': {
@@ -207,5 +199,17 @@ describe('StartIO ID System', function () {
207199
expect(utils.logError.calledOnce).to.be.true;
208200
expect(utils.logError.args[0][0]).to.include('encountered an error');
209201
});
202+
203+
it('should set default storage.expires to 90 when not provided', function () {
204+
const config = { params: {}, storage: { type: 'html5', name: 'startioId' } };
205+
startioIdSubmodule.getId(config);
206+
expect(config.storage.expires).to.equal(90);
207+
});
208+
209+
it('should not override storage.expires when already set', function () {
210+
const config = { params: {}, storage: { type: 'html5', name: 'startioId', expires: 365 } };
211+
startioIdSubmodule.getId(config);
212+
expect(config.storage.expires).to.equal(365);
213+
});
210214
});
211215
});

0 commit comments

Comments
 (0)