@grainql/analytics-web 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/id-manager.d.ts +13 -0
- package/dist/cjs/id-manager.d.ts.map +1 -1
- package/dist/cjs/id-manager.js +83 -4
- package/dist/cjs/id-manager.js.map +1 -1
- package/dist/esm/id-manager.d.ts +13 -0
- package/dist/esm/id-manager.d.ts.map +1 -1
- package/dist/esm/id-manager.js +83 -4
- package/dist/esm/id-manager.js.map +1 -1
- package/dist/id-manager.d.ts +13 -0
- package/dist/id-manager.d.ts.map +1 -1
- package/dist/id-manager.js +83 -4
- package/dist/index.global.dev.js +70 -4
- package/dist/index.global.dev.js.map +2 -2
- package/dist/index.global.js +3 -3
- package/dist/index.global.js.map +3 -3
- package/package.json +1 -1
package/dist/cjs/id-manager.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class IdManager {
|
|
|
21
21
|
private config;
|
|
22
22
|
private cachedDailyId;
|
|
23
23
|
private dailyIdDate;
|
|
24
|
+
private dailyRandomSeed;
|
|
24
25
|
private permanentId;
|
|
25
26
|
constructor(config: IdConfig);
|
|
26
27
|
/**
|
|
@@ -54,6 +55,18 @@ export declare class IdManager {
|
|
|
54
55
|
* Clear permanent ID from localStorage
|
|
55
56
|
*/
|
|
56
57
|
private clearPermanentId;
|
|
58
|
+
/**
|
|
59
|
+
* Load daily random seed from sessionStorage
|
|
60
|
+
*/
|
|
61
|
+
private loadDailySeed;
|
|
62
|
+
/**
|
|
63
|
+
* Save daily random seed to sessionStorage
|
|
64
|
+
*/
|
|
65
|
+
private saveDailySeed;
|
|
66
|
+
/**
|
|
67
|
+
* Clear daily seed from sessionStorage
|
|
68
|
+
*/
|
|
69
|
+
private clearDailySeed;
|
|
57
70
|
/**
|
|
58
71
|
* Get info about current ID for debugging
|
|
59
72
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-manager.d.ts","sourceRoot":"","sources":["../../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2DD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"id-manager.d.ts","sourceRoot":"","sources":["../../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2DD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,QAAQ;IAc5B;;;;OAIG;IACH,uBAAuB,IAAI,MAAM;IAmCjC;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAyB7B;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAQ1B;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAsB3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;IACH,OAAO,CAAC,aAAa;IA2BrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,SAAS,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,OAAO,CAAA;KAAE;CAQpE"}
|
package/dist/cjs/id-manager.js
CHANGED
|
@@ -69,12 +69,17 @@ class IdManager {
|
|
|
69
69
|
constructor(config) {
|
|
70
70
|
this.cachedDailyId = null;
|
|
71
71
|
this.dailyIdDate = null;
|
|
72
|
+
this.dailyRandomSeed = null; // Random component for daily ID
|
|
72
73
|
this.permanentId = null;
|
|
73
74
|
this.config = config;
|
|
74
75
|
// Load permanent ID from localStorage if in permanent mode
|
|
75
76
|
if (config.mode === 'permanent' && config.useLocalStorage) {
|
|
76
77
|
this.loadPermanentId();
|
|
77
78
|
}
|
|
79
|
+
// Load daily random seed from sessionStorage if in cookieless mode
|
|
80
|
+
if (config.mode === 'cookieless') {
|
|
81
|
+
this.loadDailySeed();
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
/**
|
|
80
85
|
* Generate a daily rotating ID
|
|
@@ -84,13 +89,25 @@ class IdManager {
|
|
|
84
89
|
generateDailyRotatingId() {
|
|
85
90
|
const currentDate = getLocalDateString();
|
|
86
91
|
// Return cached ID if still the same day
|
|
87
|
-
if (this.cachedDailyId && this.dailyIdDate === currentDate) {
|
|
92
|
+
if (this.cachedDailyId && this.dailyIdDate === currentDate && this.dailyRandomSeed) {
|
|
88
93
|
return this.cachedDailyId;
|
|
89
94
|
}
|
|
90
|
-
//
|
|
95
|
+
// Load seed from sessionStorage if available
|
|
96
|
+
const storedSeed = this.loadDailySeed();
|
|
97
|
+
// If date changed, clear the random seed
|
|
98
|
+
if (this.dailyIdDate !== currentDate) {
|
|
99
|
+
this.dailyRandomSeed = null;
|
|
100
|
+
this.clearDailySeed();
|
|
101
|
+
}
|
|
102
|
+
// Generate new random seed for today if needed
|
|
103
|
+
if (!this.dailyRandomSeed) {
|
|
104
|
+
this.dailyRandomSeed = storedSeed || generateUUID();
|
|
105
|
+
this.saveDailySeed(this.dailyRandomSeed, currentDate);
|
|
106
|
+
}
|
|
107
|
+
// Generate new daily ID using fingerprint + random seed
|
|
91
108
|
const fingerprint = getBrowserFingerprint();
|
|
92
|
-
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}`;
|
|
93
|
-
const dailyId = `daily_${simpleHash(seed)}
|
|
109
|
+
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}|${this.dailyRandomSeed}`;
|
|
110
|
+
const dailyId = `daily_${simpleHash(seed)}`;
|
|
94
111
|
// Cache for same-day requests
|
|
95
112
|
this.cachedDailyId = dailyId;
|
|
96
113
|
this.dailyIdDate = currentDate;
|
|
@@ -140,6 +157,8 @@ class IdManager {
|
|
|
140
157
|
if (mode === 'permanent') {
|
|
141
158
|
this.cachedDailyId = null;
|
|
142
159
|
this.dailyIdDate = null;
|
|
160
|
+
this.dailyRandomSeed = null;
|
|
161
|
+
this.clearDailySeed();
|
|
143
162
|
}
|
|
144
163
|
// Clear permanent ID when switching to cookieless
|
|
145
164
|
if (mode === 'cookieless') {
|
|
@@ -147,6 +166,8 @@ class IdManager {
|
|
|
147
166
|
if (this.config.useLocalStorage) {
|
|
148
167
|
this.clearPermanentId();
|
|
149
168
|
}
|
|
169
|
+
// Load daily seed for cookieless mode
|
|
170
|
+
this.loadDailySeed();
|
|
150
171
|
}
|
|
151
172
|
}
|
|
152
173
|
/**
|
|
@@ -196,6 +217,64 @@ class IdManager {
|
|
|
196
217
|
// Silent failure
|
|
197
218
|
}
|
|
198
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Load daily random seed from sessionStorage
|
|
222
|
+
*/
|
|
223
|
+
loadDailySeed() {
|
|
224
|
+
if (typeof window === 'undefined')
|
|
225
|
+
return null;
|
|
226
|
+
try {
|
|
227
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
228
|
+
const stored = sessionStorage.getItem(storageKey);
|
|
229
|
+
if (stored) {
|
|
230
|
+
const data = JSON.parse(stored);
|
|
231
|
+
const currentDate = getLocalDateString();
|
|
232
|
+
// Only use seed if it's from today
|
|
233
|
+
if (data.date === currentDate && data.seed) {
|
|
234
|
+
this.dailyRandomSeed = data.seed;
|
|
235
|
+
this.dailyIdDate = data.date;
|
|
236
|
+
return data.seed;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// Clear stale seed
|
|
240
|
+
this.clearDailySeed();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
// Silent failure - sessionStorage might be disabled
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Save daily random seed to sessionStorage
|
|
251
|
+
*/
|
|
252
|
+
saveDailySeed(seed, date) {
|
|
253
|
+
if (typeof window === 'undefined')
|
|
254
|
+
return;
|
|
255
|
+
try {
|
|
256
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
257
|
+
const data = { seed, date };
|
|
258
|
+
sessionStorage.setItem(storageKey, JSON.stringify(data));
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
// Silent failure - sessionStorage might be disabled
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Clear daily seed from sessionStorage
|
|
266
|
+
*/
|
|
267
|
+
clearDailySeed() {
|
|
268
|
+
if (typeof window === 'undefined')
|
|
269
|
+
return;
|
|
270
|
+
try {
|
|
271
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
272
|
+
sessionStorage.removeItem(storageKey);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
// Silent failure
|
|
276
|
+
}
|
|
277
|
+
}
|
|
199
278
|
/**
|
|
200
279
|
* Get info about current ID for debugging
|
|
201
280
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-manager.js","sourceRoot":"","sources":["../../src/id-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAUH;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC/B,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACnC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,4BAA4B;IAClD,CAAC;IACD,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACrC,CAAC;AAED;;GAEG;AACH,SAAS,YAAY;IACnB,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;IAED,8BAA8B;IAC9B,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AAC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QACnC,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,EAAE,EAAE,EAAE;YACN,eAAe,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;SACzC,CAAC;IACJ,CAAC;CACF;AApPD,8BAoPC"}
|
package/dist/esm/id-manager.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class IdManager {
|
|
|
21
21
|
private config;
|
|
22
22
|
private cachedDailyId;
|
|
23
23
|
private dailyIdDate;
|
|
24
|
+
private dailyRandomSeed;
|
|
24
25
|
private permanentId;
|
|
25
26
|
constructor(config: IdConfig);
|
|
26
27
|
/**
|
|
@@ -54,6 +55,18 @@ export declare class IdManager {
|
|
|
54
55
|
* Clear permanent ID from localStorage
|
|
55
56
|
*/
|
|
56
57
|
private clearPermanentId;
|
|
58
|
+
/**
|
|
59
|
+
* Load daily random seed from sessionStorage
|
|
60
|
+
*/
|
|
61
|
+
private loadDailySeed;
|
|
62
|
+
/**
|
|
63
|
+
* Save daily random seed to sessionStorage
|
|
64
|
+
*/
|
|
65
|
+
private saveDailySeed;
|
|
66
|
+
/**
|
|
67
|
+
* Clear daily seed from sessionStorage
|
|
68
|
+
*/
|
|
69
|
+
private clearDailySeed;
|
|
57
70
|
/**
|
|
58
71
|
* Get info about current ID for debugging
|
|
59
72
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-manager.d.ts","sourceRoot":"","sources":["../../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2DD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"id-manager.d.ts","sourceRoot":"","sources":["../../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2DD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,QAAQ;IAc5B;;;;OAIG;IACH,uBAAuB,IAAI,MAAM;IAmCjC;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAyB7B;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAQ1B;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAsB3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;IACH,OAAO,CAAC,aAAa;IA2BrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,SAAS,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,OAAO,CAAA;KAAE;CAQpE"}
|
package/dist/esm/id-manager.js
CHANGED
|
@@ -66,12 +66,17 @@ export class IdManager {
|
|
|
66
66
|
constructor(config) {
|
|
67
67
|
this.cachedDailyId = null;
|
|
68
68
|
this.dailyIdDate = null;
|
|
69
|
+
this.dailyRandomSeed = null; // Random component for daily ID
|
|
69
70
|
this.permanentId = null;
|
|
70
71
|
this.config = config;
|
|
71
72
|
// Load permanent ID from localStorage if in permanent mode
|
|
72
73
|
if (config.mode === 'permanent' && config.useLocalStorage) {
|
|
73
74
|
this.loadPermanentId();
|
|
74
75
|
}
|
|
76
|
+
// Load daily random seed from sessionStorage if in cookieless mode
|
|
77
|
+
if (config.mode === 'cookieless') {
|
|
78
|
+
this.loadDailySeed();
|
|
79
|
+
}
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
77
82
|
* Generate a daily rotating ID
|
|
@@ -81,13 +86,25 @@ export class IdManager {
|
|
|
81
86
|
generateDailyRotatingId() {
|
|
82
87
|
const currentDate = getLocalDateString();
|
|
83
88
|
// Return cached ID if still the same day
|
|
84
|
-
if (this.cachedDailyId && this.dailyIdDate === currentDate) {
|
|
89
|
+
if (this.cachedDailyId && this.dailyIdDate === currentDate && this.dailyRandomSeed) {
|
|
85
90
|
return this.cachedDailyId;
|
|
86
91
|
}
|
|
87
|
-
//
|
|
92
|
+
// Load seed from sessionStorage if available
|
|
93
|
+
const storedSeed = this.loadDailySeed();
|
|
94
|
+
// If date changed, clear the random seed
|
|
95
|
+
if (this.dailyIdDate !== currentDate) {
|
|
96
|
+
this.dailyRandomSeed = null;
|
|
97
|
+
this.clearDailySeed();
|
|
98
|
+
}
|
|
99
|
+
// Generate new random seed for today if needed
|
|
100
|
+
if (!this.dailyRandomSeed) {
|
|
101
|
+
this.dailyRandomSeed = storedSeed || generateUUID();
|
|
102
|
+
this.saveDailySeed(this.dailyRandomSeed, currentDate);
|
|
103
|
+
}
|
|
104
|
+
// Generate new daily ID using fingerprint + random seed
|
|
88
105
|
const fingerprint = getBrowserFingerprint();
|
|
89
|
-
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}`;
|
|
90
|
-
const dailyId = `daily_${simpleHash(seed)}
|
|
106
|
+
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}|${this.dailyRandomSeed}`;
|
|
107
|
+
const dailyId = `daily_${simpleHash(seed)}`;
|
|
91
108
|
// Cache for same-day requests
|
|
92
109
|
this.cachedDailyId = dailyId;
|
|
93
110
|
this.dailyIdDate = currentDate;
|
|
@@ -137,6 +154,8 @@ export class IdManager {
|
|
|
137
154
|
if (mode === 'permanent') {
|
|
138
155
|
this.cachedDailyId = null;
|
|
139
156
|
this.dailyIdDate = null;
|
|
157
|
+
this.dailyRandomSeed = null;
|
|
158
|
+
this.clearDailySeed();
|
|
140
159
|
}
|
|
141
160
|
// Clear permanent ID when switching to cookieless
|
|
142
161
|
if (mode === 'cookieless') {
|
|
@@ -144,6 +163,8 @@ export class IdManager {
|
|
|
144
163
|
if (this.config.useLocalStorage) {
|
|
145
164
|
this.clearPermanentId();
|
|
146
165
|
}
|
|
166
|
+
// Load daily seed for cookieless mode
|
|
167
|
+
this.loadDailySeed();
|
|
147
168
|
}
|
|
148
169
|
}
|
|
149
170
|
/**
|
|
@@ -193,6 +214,64 @@ export class IdManager {
|
|
|
193
214
|
// Silent failure
|
|
194
215
|
}
|
|
195
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Load daily random seed from sessionStorage
|
|
219
|
+
*/
|
|
220
|
+
loadDailySeed() {
|
|
221
|
+
if (typeof window === 'undefined')
|
|
222
|
+
return null;
|
|
223
|
+
try {
|
|
224
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
225
|
+
const stored = sessionStorage.getItem(storageKey);
|
|
226
|
+
if (stored) {
|
|
227
|
+
const data = JSON.parse(stored);
|
|
228
|
+
const currentDate = getLocalDateString();
|
|
229
|
+
// Only use seed if it's from today
|
|
230
|
+
if (data.date === currentDate && data.seed) {
|
|
231
|
+
this.dailyRandomSeed = data.seed;
|
|
232
|
+
this.dailyIdDate = data.date;
|
|
233
|
+
return data.seed;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
// Clear stale seed
|
|
237
|
+
this.clearDailySeed();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
// Silent failure - sessionStorage might be disabled
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Save daily random seed to sessionStorage
|
|
248
|
+
*/
|
|
249
|
+
saveDailySeed(seed, date) {
|
|
250
|
+
if (typeof window === 'undefined')
|
|
251
|
+
return;
|
|
252
|
+
try {
|
|
253
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
254
|
+
const data = { seed, date };
|
|
255
|
+
sessionStorage.setItem(storageKey, JSON.stringify(data));
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
// Silent failure - sessionStorage might be disabled
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Clear daily seed from sessionStorage
|
|
263
|
+
*/
|
|
264
|
+
clearDailySeed() {
|
|
265
|
+
if (typeof window === 'undefined')
|
|
266
|
+
return;
|
|
267
|
+
try {
|
|
268
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
269
|
+
sessionStorage.removeItem(storageKey);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
// Silent failure
|
|
273
|
+
}
|
|
274
|
+
}
|
|
196
275
|
/**
|
|
197
276
|
* Get info about current ID for debugging
|
|
198
277
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-manager.js","sourceRoot":"","sources":["../../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH;;GAEG;AACH,SAAS,UAAU,CAAC,GAAW;IAC7B,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,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H,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,oDAAoD;QACtD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,IAAY,EAAE,IAAY;QAC9C,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAE1C,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,oBAAoB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC9D,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YAC5B,cAAc,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAC3D,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,oDAAoD;QACtD,CAAC;IACH,CAAC;IAED;;OAEG;IACK,cAAc;QACpB,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAE1C,IAAI,CAAC;YACH,MAAM,UAAU,GAAG,oBAAoB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC9D,cAAc,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,iBAAiB;QACnB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,SAAS;QACP,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACnC,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,EAAE,EAAE,EAAE;YACN,eAAe,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;SACzC,CAAC;IACJ,CAAC;CACF"}
|
package/dist/id-manager.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare class IdManager {
|
|
|
21
21
|
private config;
|
|
22
22
|
private cachedDailyId;
|
|
23
23
|
private dailyIdDate;
|
|
24
|
+
private dailyRandomSeed;
|
|
24
25
|
private permanentId;
|
|
25
26
|
constructor(config: IdConfig);
|
|
26
27
|
/**
|
|
@@ -54,6 +55,18 @@ export declare class IdManager {
|
|
|
54
55
|
* Clear permanent ID from localStorage
|
|
55
56
|
*/
|
|
56
57
|
private clearPermanentId;
|
|
58
|
+
/**
|
|
59
|
+
* Load daily random seed from sessionStorage
|
|
60
|
+
*/
|
|
61
|
+
private loadDailySeed;
|
|
62
|
+
/**
|
|
63
|
+
* Save daily random seed to sessionStorage
|
|
64
|
+
*/
|
|
65
|
+
private saveDailySeed;
|
|
66
|
+
/**
|
|
67
|
+
* Clear daily seed from sessionStorage
|
|
68
|
+
*/
|
|
69
|
+
private clearDailySeed;
|
|
57
70
|
/**
|
|
58
71
|
* Get info about current ID for debugging
|
|
59
72
|
*/
|
package/dist/id-manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"id-manager.d.ts","sourceRoot":"","sources":["../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2DD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,QAAQ;
|
|
1
|
+
{"version":3,"file":"id-manager.d.ts","sourceRoot":"","sources":["../src/id-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,WAAW,CAAC;AAEhD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AA2DD;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,WAAW,CAAuB;gBAE9B,MAAM,EAAE,QAAQ;IAc5B;;;;OAIG;IACH,uBAAuB,IAAI,MAAM;IAmCjC;;;OAGG;IACH,mBAAmB,IAAI,MAAM;IAyB7B;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAQ1B;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAsB3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAiBvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAWxB;;OAEG;IACH,OAAO,CAAC,aAAa;IA2BrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAYrB;;OAEG;IACH,OAAO,CAAC,cAAc;IAWtB;;OAEG;IACH,SAAS,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,OAAO,CAAA;KAAE;CAQpE"}
|
package/dist/id-manager.js
CHANGED
|
@@ -69,12 +69,17 @@ class IdManager {
|
|
|
69
69
|
constructor(config) {
|
|
70
70
|
this.cachedDailyId = null;
|
|
71
71
|
this.dailyIdDate = null;
|
|
72
|
+
this.dailyRandomSeed = null; // Random component for daily ID
|
|
72
73
|
this.permanentId = null;
|
|
73
74
|
this.config = config;
|
|
74
75
|
// Load permanent ID from localStorage if in permanent mode
|
|
75
76
|
if (config.mode === 'permanent' && config.useLocalStorage) {
|
|
76
77
|
this.loadPermanentId();
|
|
77
78
|
}
|
|
79
|
+
// Load daily random seed from sessionStorage if in cookieless mode
|
|
80
|
+
if (config.mode === 'cookieless') {
|
|
81
|
+
this.loadDailySeed();
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
/**
|
|
80
85
|
* Generate a daily rotating ID
|
|
@@ -84,13 +89,25 @@ class IdManager {
|
|
|
84
89
|
generateDailyRotatingId() {
|
|
85
90
|
const currentDate = getLocalDateString();
|
|
86
91
|
// Return cached ID if still the same day
|
|
87
|
-
if (this.cachedDailyId && this.dailyIdDate === currentDate) {
|
|
92
|
+
if (this.cachedDailyId && this.dailyIdDate === currentDate && this.dailyRandomSeed) {
|
|
88
93
|
return this.cachedDailyId;
|
|
89
94
|
}
|
|
90
|
-
//
|
|
95
|
+
// Load seed from sessionStorage if available
|
|
96
|
+
const storedSeed = this.loadDailySeed();
|
|
97
|
+
// If date changed, clear the random seed
|
|
98
|
+
if (this.dailyIdDate !== currentDate) {
|
|
99
|
+
this.dailyRandomSeed = null;
|
|
100
|
+
this.clearDailySeed();
|
|
101
|
+
}
|
|
102
|
+
// Generate new random seed for today if needed
|
|
103
|
+
if (!this.dailyRandomSeed) {
|
|
104
|
+
this.dailyRandomSeed = storedSeed || generateUUID();
|
|
105
|
+
this.saveDailySeed(this.dailyRandomSeed, currentDate);
|
|
106
|
+
}
|
|
107
|
+
// Generate new daily ID using fingerprint + random seed
|
|
91
108
|
const fingerprint = getBrowserFingerprint();
|
|
92
|
-
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}`;
|
|
93
|
-
const dailyId = `daily_${simpleHash(seed)}
|
|
109
|
+
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}|${this.dailyRandomSeed}`;
|
|
110
|
+
const dailyId = `daily_${simpleHash(seed)}`;
|
|
94
111
|
// Cache for same-day requests
|
|
95
112
|
this.cachedDailyId = dailyId;
|
|
96
113
|
this.dailyIdDate = currentDate;
|
|
@@ -140,6 +157,8 @@ class IdManager {
|
|
|
140
157
|
if (mode === 'permanent') {
|
|
141
158
|
this.cachedDailyId = null;
|
|
142
159
|
this.dailyIdDate = null;
|
|
160
|
+
this.dailyRandomSeed = null;
|
|
161
|
+
this.clearDailySeed();
|
|
143
162
|
}
|
|
144
163
|
// Clear permanent ID when switching to cookieless
|
|
145
164
|
if (mode === 'cookieless') {
|
|
@@ -147,6 +166,8 @@ class IdManager {
|
|
|
147
166
|
if (this.config.useLocalStorage) {
|
|
148
167
|
this.clearPermanentId();
|
|
149
168
|
}
|
|
169
|
+
// Load daily seed for cookieless mode
|
|
170
|
+
this.loadDailySeed();
|
|
150
171
|
}
|
|
151
172
|
}
|
|
152
173
|
/**
|
|
@@ -196,6 +217,64 @@ class IdManager {
|
|
|
196
217
|
// Silent failure
|
|
197
218
|
}
|
|
198
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Load daily random seed from sessionStorage
|
|
222
|
+
*/
|
|
223
|
+
loadDailySeed() {
|
|
224
|
+
if (typeof window === 'undefined')
|
|
225
|
+
return null;
|
|
226
|
+
try {
|
|
227
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
228
|
+
const stored = sessionStorage.getItem(storageKey);
|
|
229
|
+
if (stored) {
|
|
230
|
+
const data = JSON.parse(stored);
|
|
231
|
+
const currentDate = getLocalDateString();
|
|
232
|
+
// Only use seed if it's from today
|
|
233
|
+
if (data.date === currentDate && data.seed) {
|
|
234
|
+
this.dailyRandomSeed = data.seed;
|
|
235
|
+
this.dailyIdDate = data.date;
|
|
236
|
+
return data.seed;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
// Clear stale seed
|
|
240
|
+
this.clearDailySeed();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
// Silent failure - sessionStorage might be disabled
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Save daily random seed to sessionStorage
|
|
251
|
+
*/
|
|
252
|
+
saveDailySeed(seed, date) {
|
|
253
|
+
if (typeof window === 'undefined')
|
|
254
|
+
return;
|
|
255
|
+
try {
|
|
256
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
257
|
+
const data = { seed, date };
|
|
258
|
+
sessionStorage.setItem(storageKey, JSON.stringify(data));
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
// Silent failure - sessionStorage might be disabled
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Clear daily seed from sessionStorage
|
|
266
|
+
*/
|
|
267
|
+
clearDailySeed() {
|
|
268
|
+
if (typeof window === 'undefined')
|
|
269
|
+
return;
|
|
270
|
+
try {
|
|
271
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
272
|
+
sessionStorage.removeItem(storageKey);
|
|
273
|
+
}
|
|
274
|
+
catch (error) {
|
|
275
|
+
// Silent failure
|
|
276
|
+
}
|
|
277
|
+
}
|
|
199
278
|
/**
|
|
200
279
|
* Get info about current ID for debugging
|
|
201
280
|
*/
|
package/dist/index.global.dev.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Grain Analytics Web SDK v3.1.
|
|
1
|
+
/* Grain Analytics Web SDK v3.1.1 | MIT License | Development Build */
|
|
2
2
|
"use strict";
|
|
3
3
|
var Grain = (() => {
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -6554,11 +6554,16 @@ var Grain = (() => {
|
|
|
6554
6554
|
constructor(config) {
|
|
6555
6555
|
this.cachedDailyId = null;
|
|
6556
6556
|
this.dailyIdDate = null;
|
|
6557
|
+
this.dailyRandomSeed = null;
|
|
6558
|
+
// Random component for daily ID
|
|
6557
6559
|
this.permanentId = null;
|
|
6558
6560
|
this.config = config;
|
|
6559
6561
|
if (config.mode === "permanent" && config.useLocalStorage) {
|
|
6560
6562
|
this.loadPermanentId();
|
|
6561
6563
|
}
|
|
6564
|
+
if (config.mode === "cookieless") {
|
|
6565
|
+
this.loadDailySeed();
|
|
6566
|
+
}
|
|
6562
6567
|
}
|
|
6563
6568
|
/**
|
|
6564
6569
|
* Generate a daily rotating ID
|
|
@@ -6567,12 +6572,21 @@ var Grain = (() => {
|
|
|
6567
6572
|
*/
|
|
6568
6573
|
generateDailyRotatingId() {
|
|
6569
6574
|
const currentDate = getLocalDateString();
|
|
6570
|
-
if (this.cachedDailyId && this.dailyIdDate === currentDate) {
|
|
6575
|
+
if (this.cachedDailyId && this.dailyIdDate === currentDate && this.dailyRandomSeed) {
|
|
6571
6576
|
return this.cachedDailyId;
|
|
6572
6577
|
}
|
|
6578
|
+
const storedSeed = this.loadDailySeed();
|
|
6579
|
+
if (this.dailyIdDate !== currentDate) {
|
|
6580
|
+
this.dailyRandomSeed = null;
|
|
6581
|
+
this.clearDailySeed();
|
|
6582
|
+
}
|
|
6583
|
+
if (!this.dailyRandomSeed) {
|
|
6584
|
+
this.dailyRandomSeed = storedSeed || generateUUID();
|
|
6585
|
+
this.saveDailySeed(this.dailyRandomSeed, currentDate);
|
|
6586
|
+
}
|
|
6573
6587
|
const fingerprint = getBrowserFingerprint();
|
|
6574
|
-
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}`;
|
|
6575
|
-
const dailyId = `daily_${simpleHash(seed)}
|
|
6588
|
+
const seed = `${this.config.tenantId}|${currentDate}|${fingerprint}|${this.dailyRandomSeed}`;
|
|
6589
|
+
const dailyId = `daily_${simpleHash(seed)}`;
|
|
6576
6590
|
this.cachedDailyId = dailyId;
|
|
6577
6591
|
this.dailyIdDate = currentDate;
|
|
6578
6592
|
return dailyId;
|
|
@@ -6616,12 +6630,15 @@ var Grain = (() => {
|
|
|
6616
6630
|
if (mode === "permanent") {
|
|
6617
6631
|
this.cachedDailyId = null;
|
|
6618
6632
|
this.dailyIdDate = null;
|
|
6633
|
+
this.dailyRandomSeed = null;
|
|
6634
|
+
this.clearDailySeed();
|
|
6619
6635
|
}
|
|
6620
6636
|
if (mode === "cookieless") {
|
|
6621
6637
|
this.permanentId = null;
|
|
6622
6638
|
if (this.config.useLocalStorage) {
|
|
6623
6639
|
this.clearPermanentId();
|
|
6624
6640
|
}
|
|
6641
|
+
this.loadDailySeed();
|
|
6625
6642
|
}
|
|
6626
6643
|
}
|
|
6627
6644
|
/**
|
|
@@ -6665,6 +6682,55 @@ var Grain = (() => {
|
|
|
6665
6682
|
} catch (error) {
|
|
6666
6683
|
}
|
|
6667
6684
|
}
|
|
6685
|
+
/**
|
|
6686
|
+
* Load daily random seed from sessionStorage
|
|
6687
|
+
*/
|
|
6688
|
+
loadDailySeed() {
|
|
6689
|
+
if (typeof window === "undefined")
|
|
6690
|
+
return null;
|
|
6691
|
+
try {
|
|
6692
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
6693
|
+
const stored = sessionStorage.getItem(storageKey);
|
|
6694
|
+
if (stored) {
|
|
6695
|
+
const data = JSON.parse(stored);
|
|
6696
|
+
const currentDate = getLocalDateString();
|
|
6697
|
+
if (data.date === currentDate && data.seed) {
|
|
6698
|
+
this.dailyRandomSeed = data.seed;
|
|
6699
|
+
this.dailyIdDate = data.date;
|
|
6700
|
+
return data.seed;
|
|
6701
|
+
} else {
|
|
6702
|
+
this.clearDailySeed();
|
|
6703
|
+
}
|
|
6704
|
+
}
|
|
6705
|
+
} catch (error) {
|
|
6706
|
+
}
|
|
6707
|
+
return null;
|
|
6708
|
+
}
|
|
6709
|
+
/**
|
|
6710
|
+
* Save daily random seed to sessionStorage
|
|
6711
|
+
*/
|
|
6712
|
+
saveDailySeed(seed, date) {
|
|
6713
|
+
if (typeof window === "undefined")
|
|
6714
|
+
return;
|
|
6715
|
+
try {
|
|
6716
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
6717
|
+
const data = { seed, date };
|
|
6718
|
+
sessionStorage.setItem(storageKey, JSON.stringify(data));
|
|
6719
|
+
} catch (error) {
|
|
6720
|
+
}
|
|
6721
|
+
}
|
|
6722
|
+
/**
|
|
6723
|
+
* Clear daily seed from sessionStorage
|
|
6724
|
+
*/
|
|
6725
|
+
clearDailySeed() {
|
|
6726
|
+
if (typeof window === "undefined")
|
|
6727
|
+
return;
|
|
6728
|
+
try {
|
|
6729
|
+
const storageKey = `grain_daily_seed_${this.config.tenantId}`;
|
|
6730
|
+
sessionStorage.removeItem(storageKey);
|
|
6731
|
+
} catch (error) {
|
|
6732
|
+
}
|
|
6733
|
+
}
|
|
6668
6734
|
/**
|
|
6669
6735
|
* Get info about current ID for debugging
|
|
6670
6736
|
*/
|