@posthog/browser 0.4.2 → 0.6.0
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/ARCHITECTURE.md +36 -48
- package/README.md +97 -69
- package/dist/composition/npm/core.d.ts +3 -4
- package/dist/composition/npm/core.js +2 -1
- package/dist/composition/npm/core.mjs +2 -1
- package/dist/composition/npm/index.d.ts +4 -5
- package/dist/composition/npm/index.js +2 -1
- package/dist/composition/npm/index.mjs +2 -1
- package/dist/composition/npm/root-composition.d.ts +4 -4
- package/dist/composition/npm/root-composition.js +0 -16
- package/dist/composition/npm/root-composition.mjs +0 -16
- package/dist/core/context/browser-client.d.ts +4 -35
- package/dist/core/extensions/registry.d.ts +15 -36
- package/dist/core/extensions/registry.js +67 -198
- package/dist/core/extensions/registry.mjs +67 -198
- package/dist/core/posthog.d.ts +3 -2
- package/dist/core/posthog.js +190 -173
- package/dist/core/posthog.mjs +191 -174
- package/dist/core/state/state.d.ts +33 -3
- package/dist/core/state/state.js +122 -27
- package/dist/core/state/state.mjs +107 -27
- package/dist/core/types.d.ts +134 -14
- package/dist/persistence/cookie.d.ts +19 -0
- package/dist/persistence/cookie.js +273 -0
- package/dist/persistence/cookie.mjs +235 -0
- package/dist/platform/logger.d.ts +5 -1
- package/dist/platform/logger.js +3 -3
- package/dist/platform/logger.mjs +3 -3
- package/dist/primitives/id.d.ts +5 -0
- package/dist/primitives/id.js +10 -2
- package/dist/primitives/id.mjs +6 -1
- package/dist/primitives/version.js +1 -1
- package/dist/primitives/version.mjs +1 -1
- package/dist/products/analytics/analytics-core.d.ts +89 -0
- package/dist/products/analytics/analytics-core.js +563 -0
- package/dist/products/analytics/analytics-core.mjs +516 -0
- package/dist/products/analytics/analytics-internal.d.ts +16 -37
- package/dist/products/analytics/analytics-internal.js +2 -10
- package/dist/products/analytics/analytics-internal.mjs +1 -3
- package/dist/products/analytics/analytics-options.d.ts +0 -9
- package/dist/products/analytics/analytics-options.js +1 -38
- package/dist/products/analytics/analytics-options.mjs +1 -17
- package/dist/products/analytics/delivery/analytics-delivery.js +1 -1
- package/dist/products/analytics/delivery/analytics-delivery.mjs +1 -1
- package/dist/products/analytics/delivery/lane.d.ts +8 -1
- package/dist/products/analytics/delivery/lane.js +16 -4
- package/dist/products/analytics/delivery/lane.mjs +16 -4
- package/dist/products/analytics/groups.d.ts +8 -0
- package/dist/products/analytics/groups.js +84 -0
- package/dist/products/analytics/groups.mjs +40 -0
- package/dist/products/analytics/person.d.ts +11 -0
- package/dist/products/analytics/person.js +91 -0
- package/dist/products/analytics/person.mjs +41 -0
- package/dist/products/analytics/properties/analytics-properties.d.ts +1 -0
- package/dist/products/analytics/properties/analytics-properties.js +3 -0
- package/dist/products/analytics/properties/analytics-properties.mjs +1 -1
- package/dist/products/autocapture/autocapture.js +2 -6
- package/dist/products/autocapture/autocapture.mjs +2 -6
- package/dist/products/flags/flags-internal.d.ts +4 -2
- package/dist/products/flags/flags-options.d.ts +16 -2
- package/dist/products/flags/flags-token.d.ts +31 -4
- package/dist/products/flags/flags.d.ts +1 -1
- package/dist/products/flags/flags.js +112 -11
- package/dist/products/flags/flags.mjs +112 -11
- package/dist/products/logs/logs.js +2 -5
- package/dist/products/logs/logs.mjs +2 -5
- package/dist/products/surveys/surveys-extension.js +78 -46
- package/dist/products/surveys/surveys-extension.mjs +80 -48
- package/dist/products/surveys/surveys-internal.d.ts +6 -0
- package/package.json +7 -7
- package/dist/products/analytics/analytics-api.d.ts +0 -32
- package/dist/products/analytics/analytics-api.js +0 -18
- package/dist/products/analytics/analytics-api.mjs +0 -1
- package/dist/products/analytics/analytics-buffer.d.ts +0 -4
- package/dist/products/analytics/analytics-buffer.js +0 -41
- package/dist/products/analytics/analytics-buffer.mjs +0 -3
- package/dist/products/analytics/analytics-extension.d.ts +0 -87
- package/dist/products/analytics/analytics-extension.js +0 -649
- package/dist/products/analytics/analytics-extension.mjs +0 -611
- package/dist/products/analytics/analytics.d.ts +0 -6
- package/dist/products/analytics/analytics.js +0 -42
- package/dist/products/analytics/analytics.mjs +0 -4
- package/dist/products/analytics/automatic-analytics.d.ts +0 -3
- package/dist/products/analytics/automatic-analytics.js +0 -44
- package/dist/products/analytics/automatic-analytics.mjs +0 -6
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { ENABLED_FEATURE_FLAGS, FLAG_CALL_REPORTED, PERSISTENCE_ACTIVE_FEATURE_FLAGS, PERSISTENCE_FEATURE_FLAG_DETAILS, PERSISTENCE_FEATURE_FLAG_ERRORS, PERSISTENCE_FEATURE_FLAG_EVALUATED_AT, PERSISTENCE_FEATURE_FLAG_PAYLOADS, PERSISTENCE_FEATURE_FLAG_REQUEST_ID, STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from "@posthog/browser-common/constants";
|
|
2
|
+
import { createId } from "../primitives/id.mjs";
|
|
3
|
+
import { CLIENT_KV_NAMESPACE, incrementRevision, isRecord, isTimestamp } from "../core/state/state.mjs";
|
|
4
|
+
import { isValidDistinctId } from "../products/analytics/analytics-core.mjs";
|
|
5
|
+
import { REGISTERED_PROPERTIES } from "../products/analytics/properties/analytics-properties.mjs";
|
|
6
|
+
const IDENTITY_BOUND_KEYS = [
|
|
7
|
+
STORED_PERSON_PROPERTIES_KEY,
|
|
8
|
+
PERSISTENCE_ACTIVE_FEATURE_FLAGS,
|
|
9
|
+
ENABLED_FEATURE_FLAGS,
|
|
10
|
+
PERSISTENCE_FEATURE_FLAG_DETAILS,
|
|
11
|
+
PERSISTENCE_FEATURE_FLAG_PAYLOADS,
|
|
12
|
+
PERSISTENCE_FEATURE_FLAG_REQUEST_ID,
|
|
13
|
+
PERSISTENCE_FEATURE_FLAG_EVALUATED_AT,
|
|
14
|
+
PERSISTENCE_FEATURE_FLAG_ERRORS,
|
|
15
|
+
FLAG_CALL_REPORTED
|
|
16
|
+
];
|
|
17
|
+
const SHARED_HOSTING_DOMAINS = [
|
|
18
|
+
'herokuapp.com',
|
|
19
|
+
'vercel.app',
|
|
20
|
+
'netlify.app'
|
|
21
|
+
];
|
|
22
|
+
const REVISION = /^(0|[1-9]\d*)$/;
|
|
23
|
+
const getDocument = ()=>{
|
|
24
|
+
try {
|
|
25
|
+
return globalThis.document;
|
|
26
|
+
} catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const readCookie = (name)=>{
|
|
31
|
+
try {
|
|
32
|
+
const prefix = `${name}=`;
|
|
33
|
+
for (const part of getDocument()?.cookie.split(';') ?? []){
|
|
34
|
+
const cookie = part.trim();
|
|
35
|
+
if (cookie.startsWith(prefix)) {
|
|
36
|
+
const value = JSON.parse(decodeURIComponent(cookie.slice(prefix.length)));
|
|
37
|
+
return isRecord(value) ? value : void 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} catch {}
|
|
41
|
+
};
|
|
42
|
+
const findSiteDomain = (document, hostname)=>{
|
|
43
|
+
if ('localhost' === hostname || /^[\d.]+$|:/.test(hostname)) return '';
|
|
44
|
+
const parts = hostname.split('.');
|
|
45
|
+
const probe = `dmn_chk_${createId()}`;
|
|
46
|
+
for(let length = 1; length <= Math.min(parts.length, 8); length++){
|
|
47
|
+
const candidate = parts.slice(-length).join('.');
|
|
48
|
+
const cookie = `${probe}=1; domain=.${candidate}; path=/`;
|
|
49
|
+
document.cookie = `${cookie}; max-age=3`;
|
|
50
|
+
if (document.cookie.includes(probe)) {
|
|
51
|
+
document.cookie = `${cookie}; max-age=0`;
|
|
52
|
+
return candidate;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return /[a-z0-9][a-z0-9-]+\.[a-z]{2,}$/i.exec(hostname)?.[0] ?? '';
|
|
56
|
+
};
|
|
57
|
+
const mergeCookie = (local, cookie)=>{
|
|
58
|
+
const distinctId = cookie?.distinct_id;
|
|
59
|
+
if (!cookie || !isValidDistinctId(distinctId)) return local;
|
|
60
|
+
let record;
|
|
61
|
+
try {
|
|
62
|
+
const parsed = local ? JSON.parse(local) : void 0;
|
|
63
|
+
record = isRecord(parsed) && 1 === parsed.version ? parsed : void 0;
|
|
64
|
+
} catch {
|
|
65
|
+
record = void 0;
|
|
66
|
+
}
|
|
67
|
+
const identified = 'identified' === cookie.$user_state || void 0 === cookie.$user_state && record?.distinctId === distinctId && true === record.isIdentified;
|
|
68
|
+
const sameUser = record?.distinctId === distinctId && true === record.isIdentified === identified;
|
|
69
|
+
const deviceId = 'string' == typeof cookie.$device_id && cookie.$device_id ? cookie.$device_id : 'string' == typeof record?.deviceId ? record.deviceId : distinctId;
|
|
70
|
+
const extensionData = isRecord(record?.extensionData) ? record.extensionData : {};
|
|
71
|
+
const data = isRecord(extensionData[CLIENT_KV_NAMESPACE]) ? extensionData[CLIENT_KV_NAMESPACE] : {};
|
|
72
|
+
extensionData[CLIENT_KV_NAMESPACE] = data;
|
|
73
|
+
const merged = {
|
|
74
|
+
groups: {},
|
|
75
|
+
...record,
|
|
76
|
+
version: 1,
|
|
77
|
+
deviceId,
|
|
78
|
+
anonymousId: identified ? 'string' == typeof record?.anonymousId && (sameUser || true !== record.isIdentified) ? record.anonymousId : deviceId : distinctId,
|
|
79
|
+
distinctId,
|
|
80
|
+
isIdentified: identified,
|
|
81
|
+
extensionData
|
|
82
|
+
};
|
|
83
|
+
if (!sameUser) {
|
|
84
|
+
for (const key of IDENTITY_BOUND_KEYS)delete data[key];
|
|
85
|
+
if (!identified) {
|
|
86
|
+
merged.groups = {};
|
|
87
|
+
delete data[STORED_GROUP_PROPERTIES_KEY];
|
|
88
|
+
delete data[REGISTERED_PROPERTIES];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (true === cookie.$epp) data.personProcessingEnabled = true;
|
|
92
|
+
else delete data.personProcessingEnabled;
|
|
93
|
+
delete merged.session;
|
|
94
|
+
delete merged.sessionReset;
|
|
95
|
+
const [lastActivityTimestamp, sessionId, start, revision] = Array.isArray(cookie.$sesid) ? cookie.$sesid : [];
|
|
96
|
+
const sessionStartTimestamp = start ?? lastActivityTimestamp;
|
|
97
|
+
const validRevision = 'string' == typeof revision && REVISION.test(revision) ? revision : void 0;
|
|
98
|
+
const knownSession = isRecord(record?.session) ? record.session : void 0;
|
|
99
|
+
const knownRevision = void 0 !== knownSession && knownSession.sessionId === sessionId && knownSession.sessionStartTimestamp === sessionStartTimestamp && 'string' == typeof knownSession.revision && REVISION.test(knownSession.revision) ? knownSession.revision : void 0;
|
|
100
|
+
if ('string' == typeof sessionId && sessionId && isTimestamp(lastActivityTimestamp) && isTimestamp(sessionStartTimestamp) && (validRevision || Number.isSafeInteger(sessionStartTimestamp))) merged.session = {
|
|
101
|
+
sessionId,
|
|
102
|
+
sessionStartTimestamp,
|
|
103
|
+
lastActivityTimestamp,
|
|
104
|
+
revision: validRevision ?? knownRevision ?? String(sessionStartTimestamp)
|
|
105
|
+
};
|
|
106
|
+
else if (validRevision) merged.sessionReset = validRevision;
|
|
107
|
+
else if (null === sessionId && 'string' == typeof knownSession?.revision && REVISION.test(knownSession.revision)) merged.sessionReset = incrementRevision(knownSession.revision);
|
|
108
|
+
return JSON.stringify(merged);
|
|
109
|
+
};
|
|
110
|
+
const sameIdentity = (cookie, identity)=>cookie.distinct_id === identity[0] && (void 0 === cookie.$user_state || 'identified' === cookie.$user_state === identity[1]);
|
|
111
|
+
const toCookie = (record, existing, stale, replaced)=>{
|
|
112
|
+
const identified = true === record.isIdentified;
|
|
113
|
+
const reset = !!existing && !sameIdentity(existing, [
|
|
114
|
+
record.distinctId,
|
|
115
|
+
identified
|
|
116
|
+
]) && (!identified || replaced);
|
|
117
|
+
const value = existing && (stale || !reset) ? existing : {};
|
|
118
|
+
if (!stale) {
|
|
119
|
+
const processing = true === value.$epp && sameIdentity(value, [
|
|
120
|
+
record.distinctId,
|
|
121
|
+
identified
|
|
122
|
+
]);
|
|
123
|
+
value.distinct_id = record.distinctId;
|
|
124
|
+
value.$device_id = record.deviceId;
|
|
125
|
+
value.$user_state = identified ? 'identified' : 'anonymous';
|
|
126
|
+
const extensionData = record.extensionData;
|
|
127
|
+
const data = isRecord(extensionData) ? extensionData[CLIENT_KV_NAMESPACE] : void 0;
|
|
128
|
+
if (processing || isRecord(data) && true === data.personProcessingEnabled) value.$epp = true;
|
|
129
|
+
else delete value.$epp;
|
|
130
|
+
}
|
|
131
|
+
const session = record.session;
|
|
132
|
+
value.$sesid = isRecord(session) ? [
|
|
133
|
+
session.lastActivityTimestamp,
|
|
134
|
+
session.sessionId,
|
|
135
|
+
session.sessionStartTimestamp,
|
|
136
|
+
session.revision
|
|
137
|
+
] : [
|
|
138
|
+
null,
|
|
139
|
+
null,
|
|
140
|
+
null,
|
|
141
|
+
record.sessionReset ?? null
|
|
142
|
+
];
|
|
143
|
+
return value;
|
|
144
|
+
};
|
|
145
|
+
const writeCookie = (document, name, value, settings, site)=>{
|
|
146
|
+
const attributes = `; SameSite=Lax; path=/${site ? `; domain=.${site}` : ''}${settings.secure ? '; secure' : ''}`;
|
|
147
|
+
document.cookie = value ? `${name}=${encodeURIComponent(JSON.stringify(value))}; expires=${new Date(Date.now() + 86400000 * settings.expirationDays).toUTCString()}${attributes}` : `${name}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${attributes}`;
|
|
148
|
+
};
|
|
149
|
+
const cookiePersistence = (options = {})=>{
|
|
150
|
+
let snapshot = {};
|
|
151
|
+
try {
|
|
152
|
+
snapshot = {
|
|
153
|
+
...options
|
|
154
|
+
};
|
|
155
|
+
} catch {}
|
|
156
|
+
return {
|
|
157
|
+
wrap (storage, stateKey, projectToken) {
|
|
158
|
+
let hostname = '';
|
|
159
|
+
let https = false;
|
|
160
|
+
try {
|
|
161
|
+
const location = globalThis.location;
|
|
162
|
+
hostname = location?.hostname ?? '';
|
|
163
|
+
https = location?.protocol === 'https:';
|
|
164
|
+
} catch {}
|
|
165
|
+
const name = snapshot.name ?? `ph_${projectToken.replace(/\+/g, 'PL').replace(/\//g, 'SL').replace(/=/g, 'EQ')}_posthog`;
|
|
166
|
+
const settings = {
|
|
167
|
+
crossSubdomain: snapshot.crossSubdomain ?? !SHARED_HOSTING_DOMAINS.includes(hostname.split('.').slice(-2).join('.')),
|
|
168
|
+
secure: snapshot.secure ?? https,
|
|
169
|
+
expirationDays: snapshot.expirationDays ?? 365
|
|
170
|
+
};
|
|
171
|
+
let siteDomain;
|
|
172
|
+
const site = (document)=>siteDomain ??= findSiteDomain(document, hostname);
|
|
173
|
+
let known;
|
|
174
|
+
let anonymousId;
|
|
175
|
+
let scoped = false;
|
|
176
|
+
const write = (state)=>{
|
|
177
|
+
try {
|
|
178
|
+
const document = getDocument();
|
|
179
|
+
if (!document) return;
|
|
180
|
+
const existing = readCookie(name);
|
|
181
|
+
if (!scoped) {
|
|
182
|
+
scoped = true;
|
|
183
|
+
if (settings.crossSubdomain ? site(document) : existing && site(document)) writeCookie(document, name, void 0, settings, settings.crossSubdomain ? '' : site(document));
|
|
184
|
+
}
|
|
185
|
+
let value;
|
|
186
|
+
let identity;
|
|
187
|
+
if (void 0 !== state) {
|
|
188
|
+
const record = JSON.parse(state);
|
|
189
|
+
if (!isRecord(record) || 'string' != typeof record.distinctId) return;
|
|
190
|
+
identity = [
|
|
191
|
+
record.distinctId,
|
|
192
|
+
true === record.isIdentified
|
|
193
|
+
];
|
|
194
|
+
const stale = !!existing && !!known && isValidDistinctId(existing.distinct_id) && !sameIdentity(existing, known) && identity[0] === known[0] && identity[1] === known[1];
|
|
195
|
+
if (stale) identity = void 0;
|
|
196
|
+
value = toCookie(record, existing, stale, record.anonymousId !== anonymousId);
|
|
197
|
+
anonymousId = record.anonymousId;
|
|
198
|
+
}
|
|
199
|
+
writeCookie(document, name, value, settings, settings.crossSubdomain ? site(document) : '');
|
|
200
|
+
const written = identity && readCookie(name);
|
|
201
|
+
if (identity && written && sameIdentity(written, identity)) known = identity;
|
|
202
|
+
} catch {}
|
|
203
|
+
};
|
|
204
|
+
return {
|
|
205
|
+
getItem: (key)=>{
|
|
206
|
+
if (key !== stateKey) return storage.getItem(key);
|
|
207
|
+
const merged = mergeCookie(storage.getItem(key), readCookie(name));
|
|
208
|
+
if (!known && merged) try {
|
|
209
|
+
const record = JSON.parse(merged);
|
|
210
|
+
if (isRecord(record)) {
|
|
211
|
+
known = [
|
|
212
|
+
record.distinctId,
|
|
213
|
+
true === record.isIdentified
|
|
214
|
+
];
|
|
215
|
+
anonymousId = record.anonymousId;
|
|
216
|
+
}
|
|
217
|
+
} catch {}
|
|
218
|
+
return merged;
|
|
219
|
+
},
|
|
220
|
+
setItem: (key, value)=>{
|
|
221
|
+
if (key === stateKey) write(value);
|
|
222
|
+
storage.setItem(key, value);
|
|
223
|
+
},
|
|
224
|
+
removeItem: (key)=>{
|
|
225
|
+
if (key === stateKey) write(void 0);
|
|
226
|
+
storage.removeItem(key);
|
|
227
|
+
},
|
|
228
|
+
...storage.subscribe ? {
|
|
229
|
+
subscribe: (key, listener)=>storage.subscribe(key, listener)
|
|
230
|
+
} : {}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
export { cookiePersistence };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { Client } from '@posthog/browser-common';
|
|
2
2
|
type Logger = Client['logger'];
|
|
3
|
-
|
|
3
|
+
/** Shared output switch, so a runtime change reaches child loggers that extensions already created. */
|
|
4
|
+
export interface LogState {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const createLogger: (prefix: string, state: LogState) => Logger;
|
|
4
8
|
export {};
|
package/dist/platform/logger.js
CHANGED
|
@@ -31,9 +31,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
createLogger: ()=>createLogger
|
|
32
32
|
});
|
|
33
33
|
const console_original_namespaceObject = require("@posthog/browser-common/utils/console-original");
|
|
34
|
-
const createLogger = (prefix,
|
|
34
|
+
const createLogger = (prefix, state)=>{
|
|
35
35
|
const write = (level, args)=>{
|
|
36
|
-
if (!enabled) return;
|
|
36
|
+
if (!state.enabled) return;
|
|
37
37
|
try {
|
|
38
38
|
const console = globalThis.console;
|
|
39
39
|
(0, console_original_namespaceObject.originalConsoleMethod)(console?.[level])?.call(console, prefix, ...args);
|
|
@@ -45,7 +45,7 @@ const createLogger = (prefix, enabled)=>{
|
|
|
45
45
|
warn: (...args)=>write('warn', args),
|
|
46
46
|
error: (...args)=>write('error', args),
|
|
47
47
|
critical: (...args)=>write('error', args),
|
|
48
|
-
createLogger: (childPrefix)=>createLogger(`${prefix} ${childPrefix}`,
|
|
48
|
+
createLogger: (childPrefix)=>createLogger(`${prefix} ${childPrefix}`, state)
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
51
|
exports.createLogger = __webpack_exports__.createLogger;
|
package/dist/platform/logger.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { originalConsoleMethod } from "@posthog/browser-common/utils/console-original";
|
|
2
|
-
const createLogger = (prefix,
|
|
2
|
+
const createLogger = (prefix, state)=>{
|
|
3
3
|
const write = (level, args)=>{
|
|
4
|
-
if (!enabled) return;
|
|
4
|
+
if (!state.enabled) return;
|
|
5
5
|
try {
|
|
6
6
|
const console = globalThis.console;
|
|
7
7
|
originalConsoleMethod(console?.[level])?.call(console, prefix, ...args);
|
|
@@ -13,7 +13,7 @@ const createLogger = (prefix, enabled)=>{
|
|
|
13
13
|
warn: (...args)=>write('warn', args),
|
|
14
14
|
error: (...args)=>write('error', args),
|
|
15
15
|
critical: (...args)=>write('error', args),
|
|
16
|
-
createLogger: (childPrefix)=>createLogger(`${prefix} ${childPrefix}`,
|
|
16
|
+
createLogger: (childPrefix)=>createLogger(`${prefix} ${childPrefix}`, state)
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
export { createLogger };
|
package/dist/primitives/id.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export declare const createId: () => string;
|
|
2
|
+
/**
|
|
3
|
+
* A UUIDv7 that encodes `timestamp`, for session and window IDs, which PostHog sessions and posthog-js require to be
|
|
4
|
+
* v7. A local primitive, because the shared generator imports `@posthog/core` and reads its own clock.
|
|
5
|
+
*/
|
|
6
|
+
export declare const createTimeId: (timestamp: number) => string;
|
package/dist/primitives/id.js
CHANGED
|
@@ -49,12 +49,20 @@ const createId = ()=>{
|
|
|
49
49
|
return ('x' === character ? random : 3 & random | 8).toString(16);
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
|
+
const createTimeId = (timestamp)=>{
|
|
53
|
+
const time = Number.isFinite(timestamp) ? Math.min(Math.max(Math.floor(timestamp), 0), 0xffffffffffff) : 0;
|
|
54
|
+
const hex = time.toString(16).padStart(12, '0');
|
|
55
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-7${createId().slice(15)}`;
|
|
56
|
+
};
|
|
52
57
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
53
|
-
createId: createId
|
|
58
|
+
createId: createId,
|
|
59
|
+
createTimeId: createTimeId
|
|
54
60
|
});
|
|
55
61
|
exports.createId = __webpack_exports__.createId;
|
|
62
|
+
exports.createTimeId = __webpack_exports__.createTimeId;
|
|
56
63
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
57
|
-
"createId"
|
|
64
|
+
"createId",
|
|
65
|
+
"createTimeId"
|
|
58
66
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
59
67
|
Object.defineProperty(exports, '__esModule', {
|
|
60
68
|
value: true
|
package/dist/primitives/id.mjs
CHANGED
|
@@ -20,4 +20,9 @@ const createId = ()=>{
|
|
|
20
20
|
return ('x' === character ? random : 3 & random | 8).toString(16);
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
const createTimeId = (timestamp)=>{
|
|
24
|
+
const time = Number.isFinite(timestamp) ? Math.min(Math.max(Math.floor(timestamp), 0), 0xffffffffffff) : 0;
|
|
25
|
+
const hex = time.toString(16).padStart(12, '0');
|
|
26
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-7${createId().slice(15)}`;
|
|
27
|
+
};
|
|
28
|
+
export { createId, createTimeId };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "0.
|
|
1
|
+
const version = "0.6.0";
|
|
2
2
|
export { version };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { CaptureOptions, CapturedEventInfo, Disposable, SessionContext } from '@posthog/browser-common';
|
|
2
|
+
import { Publisher } from '@posthog/browser-common/pubsub';
|
|
3
|
+
import { type AnalyticsCore, type AnalyticsDeliveryFactory, type AnalyticsTeardownSubscription } from './analytics-internal';
|
|
4
|
+
import type { ChangePropertiesInfo, GroupInfo, IdentifyInfo } from '../../core/context/browser-client';
|
|
5
|
+
import type { BootstrapOptions, NewSessionInfo, CaptureSummary, ResetOptions } from '../../core/types';
|
|
6
|
+
import type { AnalyticsOptions, PersonProfileMode } from './analytics-options';
|
|
7
|
+
import { type PersonProperties } from './properties/person-processing';
|
|
8
|
+
export declare const isNonEmptyString: (value: unknown) => value is string;
|
|
9
|
+
export declare const isValidDistinctId: (value: unknown) => value is string;
|
|
10
|
+
interface PersonPropertiesAdmission {
|
|
11
|
+
readonly signature: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The client's capture pipeline: admission, identity operations, buffering and delivery.
|
|
15
|
+
* Members prefixed with `_` are package-internal and used by the optional groups and person modules.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Analytics {
|
|
18
|
+
readonly _core: AnalyticsCore;
|
|
19
|
+
readonly _eventPublisher: Publisher<CapturedEventInfo>;
|
|
20
|
+
readonly _newSessionPublisher: Publisher<NewSessionInfo>;
|
|
21
|
+
readonly _sessionIdPublisher: Publisher<SessionContext>;
|
|
22
|
+
readonly _identifyPublisher: Publisher<IdentifyInfo>;
|
|
23
|
+
readonly _changePropertiesPublisher: Publisher<ChangePropertiesInfo>;
|
|
24
|
+
readonly _groupPublisher: Publisher<GroupInfo>;
|
|
25
|
+
readonly _groupsResetPublisher: Publisher<void>;
|
|
26
|
+
readonly _resetPublisher: Publisher<void>;
|
|
27
|
+
_personProfiles: PersonProfileMode;
|
|
28
|
+
_disposed: boolean;
|
|
29
|
+
_lastPersonProperties: string | undefined;
|
|
30
|
+
/** The last admitted `$pageview` UUID and the session it belongs to. */
|
|
31
|
+
_pageview: [id: string, sessionId: string] | undefined;
|
|
32
|
+
private _driver;
|
|
33
|
+
private _isTearingDown;
|
|
34
|
+
private readonly _registeredProperties;
|
|
35
|
+
private readonly _sessionProperties;
|
|
36
|
+
private readonly _rateLimiter;
|
|
37
|
+
private readonly _dynamicEventProperties;
|
|
38
|
+
private readonly _teardownCallbacks;
|
|
39
|
+
private readonly _buffer;
|
|
40
|
+
private readonly _deliveryHost;
|
|
41
|
+
constructor(_core: AnalyticsCore, options: AnalyticsOptions, createDelivery: AnalyticsDeliveryFactory);
|
|
42
|
+
get isRateLimited(): boolean;
|
|
43
|
+
onBeforeTeardown(callback: () => void): AnalyticsTeardownSubscription;
|
|
44
|
+
flush(): Promise<void>;
|
|
45
|
+
purge(): void;
|
|
46
|
+
dispose(): Promise<void> | undefined;
|
|
47
|
+
private readonly _beforeTeardown;
|
|
48
|
+
captureInitialPageview(): boolean;
|
|
49
|
+
capture(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions): boolean;
|
|
50
|
+
captureImmediate(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions): Promise<CaptureSummary>;
|
|
51
|
+
_capture(event: string, properties?: Record<string, unknown> | null, options?: CaptureOptions, skipRateLimit?: boolean, personProperties?: PersonPropertiesAdmission): boolean;
|
|
52
|
+
private _admitCapture;
|
|
53
|
+
private _acceptRateLimit;
|
|
54
|
+
private _reportRateLimit;
|
|
55
|
+
private _snapshotProperties;
|
|
56
|
+
private _prepareCapture;
|
|
57
|
+
private _warnOversized;
|
|
58
|
+
private _commitCapture;
|
|
59
|
+
/** A pageview belongs to its session, so an expired or rotated session has none. */
|
|
60
|
+
_pageviewIdFor(sessionId: string | undefined): string | undefined;
|
|
61
|
+
_hasPersonProcessing(): boolean;
|
|
62
|
+
_requirePersonProcessing(): boolean;
|
|
63
|
+
/** Whether a local identity operation may run now. Prepares state without requiring it. */
|
|
64
|
+
_canMutate(): boolean;
|
|
65
|
+
/** Applies an identity another subdomain stored as this context applies its own reset or identify. */
|
|
66
|
+
private _adoptStoredIdentity;
|
|
67
|
+
/** Clears state that belonged to the previous identity and notifies reset listeners. */
|
|
68
|
+
private _resetIdentityState;
|
|
69
|
+
/** Whether registered properties are available now. */
|
|
70
|
+
private _canUseProperties;
|
|
71
|
+
_setPersonProperties(properties: PersonProperties, options?: CaptureOptions, identification?: IdentifyInfo): void;
|
|
72
|
+
identify(distinctId: string, set?: Record<string, unknown>, setOnce?: Record<string, unknown>): void;
|
|
73
|
+
/** Resets identity state and returns the bootstrap values for the new identity, if any. */
|
|
74
|
+
reset(options?: boolean | ResetOptions): ResetOptions['bootstrap'];
|
|
75
|
+
/** Applies setup bootstrap without replacing a persisted identity, as in posthog-js. */
|
|
76
|
+
bootstrap(options: BootstrapOptions | undefined): void;
|
|
77
|
+
private _bootstrapSession;
|
|
78
|
+
private _registration;
|
|
79
|
+
register(properties: Record<string, unknown>): void;
|
|
80
|
+
registerOnce(properties: Record<string, unknown>, defaultValue?: unknown): void;
|
|
81
|
+
registerForSession(properties: Record<string, unknown>): void;
|
|
82
|
+
unregisterForSession(property: string): void;
|
|
83
|
+
unregister(property: string): void;
|
|
84
|
+
getProperty(property: string): unknown;
|
|
85
|
+
registerDynamicEventProperties(producer: () => Record<string, unknown>): Disposable;
|
|
86
|
+
}
|
|
87
|
+
/** The client's capture pipeline, for optional modules that extend it with less common operations. */
|
|
88
|
+
export declare const analyticsOf: (posthog: object) => Analytics | undefined;
|
|
89
|
+
export {};
|