@posthog/browser 0.0.0 → 0.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/ARCHITECTURE.md +559 -0
- package/LICENSE +417 -0
- package/README.md +286 -28
- package/dist/analytics-buffer.d.ts +4 -0
- package/dist/analytics-buffer.js +200 -0
- package/dist/analytics-buffer.mjs +162 -0
- package/dist/analytics-delivery.d.ts +3 -0
- package/dist/analytics-delivery.js +231 -0
- package/dist/analytics-delivery.mjs +193 -0
- package/dist/analytics-internal.d.ts +64 -0
- package/dist/analytics-internal.js +52 -0
- package/dist/analytics-internal.mjs +5 -0
- package/dist/analytics-options.d.ts +14 -0
- package/dist/analytics-options.js +18 -0
- package/dist/analytics-options.mjs +1 -0
- package/dist/analytics.d.ts +5 -0
- package/dist/analytics.js +42 -0
- package/dist/analytics.mjs +4 -0
- package/dist/autocapture-options.d.ts +32 -0
- package/dist/autocapture-options.js +49 -0
- package/dist/autocapture-options.mjs +11 -0
- package/dist/autocapture.d.ts +5 -0
- package/dist/autocapture.js +108 -0
- package/dist/autocapture.mjs +70 -0
- package/dist/automatic-analytics.d.ts +3 -0
- package/dist/automatic-analytics.js +44 -0
- package/dist/automatic-analytics.mjs +6 -0
- package/dist/automatic-surveys.d.ts +2 -0
- package/dist/automatic-surveys.js +41 -0
- package/dist/automatic-surveys.mjs +3 -0
- package/dist/bot-filter.d.ts +2 -0
- package/dist/bot-filter.js +87 -0
- package/dist/bot-filter.mjs +49 -0
- package/dist/browser-client.d.ts +30 -0
- package/dist/browser-client.js +18 -0
- package/dist/browser-client.mjs +1 -0
- package/dist/capture-summary.d.ts +3 -0
- package/dist/capture-summary.js +63 -0
- package/dist/capture-summary.mjs +22 -0
- package/dist/capture-v1.d.ts +105 -0
- package/dist/capture-v1.js +781 -0
- package/dist/capture-v1.mjs +722 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.js +49 -0
- package/dist/core.mjs +5 -0
- package/dist/event-buffer.d.ts +41 -0
- package/dist/event-buffer.js +158 -0
- package/dist/event-buffer.mjs +120 -0
- package/dist/extensions/registry.d.ts +16 -0
- package/dist/extensions/registry.js +128 -0
- package/dist/extensions/registry.mjs +90 -0
- package/dist/flags-internal.d.ts +8 -0
- package/dist/flags-internal.js +18 -0
- package/dist/flags-internal.mjs +1 -0
- package/dist/flags-options.d.ts +22 -0
- package/dist/flags-options.js +18 -0
- package/dist/flags-options.mjs +1 -0
- package/dist/flags-token.d.ts +15 -0
- package/dist/flags-token.js +40 -0
- package/dist/flags-token.mjs +2 -0
- package/dist/flags.d.ts +6 -0
- package/dist/flags.js +164 -0
- package/dist/flags.mjs +123 -0
- package/dist/id.d.ts +1 -0
- package/dist/id.js +61 -0
- package/dist/id.mjs +23 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +119 -0
- package/dist/index.mjs +75 -0
- package/dist/lane.d.ts +57 -0
- package/dist/lane.js +363 -0
- package/dist/lane.mjs +325 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.js +57 -0
- package/dist/logger.mjs +19 -0
- package/dist/logs-internal.d.ts +7 -0
- package/dist/logs-internal.js +18 -0
- package/dist/logs-internal.mjs +1 -0
- package/dist/logs-options.d.ts +11 -0
- package/dist/logs-options.js +57 -0
- package/dist/logs-options.mjs +19 -0
- package/dist/logs.d.ts +6 -0
- package/dist/logs.js +140 -0
- package/dist/logs.mjs +102 -0
- package/dist/named-error.d.ts +7 -0
- package/dist/named-error.js +49 -0
- package/dist/named-error.mjs +11 -0
- package/dist/posthog.d.ts +3 -0
- package/dist/posthog.js +829 -0
- package/dist/posthog.mjs +791 -0
- package/dist/rate-limiter.d.ts +24 -0
- package/dist/rate-limiter.js +95 -0
- package/dist/rate-limiter.mjs +57 -0
- package/dist/remote-config.d.ts +3 -0
- package/dist/remote-config.js +47 -0
- package/dist/remote-config.mjs +9 -0
- package/dist/request.d.ts +14 -0
- package/dist/request.js +130 -0
- package/dist/request.mjs +89 -0
- package/dist/state.d.ts +82 -0
- package/dist/state.js +625 -0
- package/dist/state.mjs +581 -0
- package/dist/surveys-extension.d.ts +9 -0
- package/dist/surveys-extension.js +272 -0
- package/dist/surveys-extension.mjs +234 -0
- package/dist/surveys-internal.d.ts +12 -0
- package/dist/surveys-internal.js +18 -0
- package/dist/surveys-internal.mjs +1 -0
- package/dist/surveys-options.d.ts +18 -0
- package/dist/surveys-options.js +42 -0
- package/dist/surveys-options.mjs +4 -0
- package/dist/surveys.d.ts +6 -0
- package/dist/surveys.js +45 -0
- package/dist/surveys.mjs +4 -0
- package/dist/types.d.ts +114 -0
- package/dist/types.js +18 -0
- package/dist/types.mjs +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +40 -0
- package/dist/version.mjs +2 -0
- package/package.json +89 -8
package/dist/posthog.mjs
ADDED
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
import { loadRemoteConfig } from "./remote-config.mjs";
|
|
2
|
+
import { Publisher } from "@posthog/browser-common/pubsub";
|
|
3
|
+
import { createAnalyticsExtension } from "./analytics-buffer.mjs";
|
|
4
|
+
import { MAX_ANALYTICS_BYTES, isAnalyticsExtension } from "./analytics-internal.mjs";
|
|
5
|
+
import { isLikelyBot } from "./bot-filter.mjs";
|
|
6
|
+
import { EMPTY_CAPTURE_SUMMARY, captureFailure } from "./capture-summary.mjs";
|
|
7
|
+
import { ExtensionRegistry } from "./extensions/registry.mjs";
|
|
8
|
+
import { createId } from "./id.mjs";
|
|
9
|
+
import { createLogger } from "./logger.mjs";
|
|
10
|
+
import { ClientRateLimiter } from "./rate-limiter.mjs";
|
|
11
|
+
import { sendRequest } from "./request.mjs";
|
|
12
|
+
import { BrowserState, getDefaultSessionStorage, getDefaultStorage } from "./state.mjs";
|
|
13
|
+
import { version } from "./version.mjs";
|
|
14
|
+
const CONSENT_CHANGE_EVENT = '__posthog_browser_consent_change__';
|
|
15
|
+
const DEFAULT_SHUTDOWN_TIMEOUT_MS = 30000;
|
|
16
|
+
const CLIENT_RATE_LIMIT_WARNING = '$$client_ingestion_warning';
|
|
17
|
+
const isNonEmptyString = (value)=>'string' == typeof value && value.trim().length > 0;
|
|
18
|
+
const isRecord = (value)=>'object' == typeof value && null !== value && !Array.isArray(value);
|
|
19
|
+
const normalizeHost = (host)=>{
|
|
20
|
+
let end = host.length;
|
|
21
|
+
while(end > 0 && 47 === host.charCodeAt(end - 1))end--;
|
|
22
|
+
return end === host.length ? host : host.slice(0, end);
|
|
23
|
+
};
|
|
24
|
+
const getAssetsHost = (apiHost)=>{
|
|
25
|
+
try {
|
|
26
|
+
const url = new URL(apiHost);
|
|
27
|
+
if ('https:' === url.protocol) {
|
|
28
|
+
const region = /^(app|us|us-assets|eu|eu-assets)(\.i)?\.posthog\.com$/.exec(url.hostname)?.[1];
|
|
29
|
+
if (region) return `https://${region.startsWith('eu') ? 'eu' : 'us'}-assets.i.posthog.com`;
|
|
30
|
+
}
|
|
31
|
+
} catch {}
|
|
32
|
+
return apiHost;
|
|
33
|
+
};
|
|
34
|
+
const isValidDistinctId = (value)=>isNonEmptyString(value) && ![
|
|
35
|
+
'$posthog_cookieless',
|
|
36
|
+
'distinct_id',
|
|
37
|
+
'distinctid',
|
|
38
|
+
'undefined',
|
|
39
|
+
'null'
|
|
40
|
+
].includes(value.toLowerCase());
|
|
41
|
+
const deepFreeze = (value)=>{
|
|
42
|
+
if (value && 'object' == typeof value) {
|
|
43
|
+
Object.values(value).forEach(deepFreeze);
|
|
44
|
+
Object.freeze(value);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
const getDefaultFetch = ()=>{
|
|
49
|
+
try {
|
|
50
|
+
return globalThis.fetch?.bind(globalThis);
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const getDefaultNavigator = ()=>{
|
|
56
|
+
try {
|
|
57
|
+
return globalThis.navigator;
|
|
58
|
+
} catch {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const eventTimestamp = (timestamp)=>{
|
|
63
|
+
try {
|
|
64
|
+
return (timestamp ?? new Date()).toISOString();
|
|
65
|
+
} catch {
|
|
66
|
+
return new Date().toISOString();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const utf8Bytes = (value)=>{
|
|
70
|
+
let bytes = 0;
|
|
71
|
+
for(let index = 0; index < value.length; index++){
|
|
72
|
+
const code = value.charCodeAt(index);
|
|
73
|
+
if (code < 0x80) bytes++;
|
|
74
|
+
else if (code < 0x800) bytes += 2;
|
|
75
|
+
else if (code >= 0xd800 && code <= 0xdbff && value.charCodeAt(index + 1) >= 0xdc00) {
|
|
76
|
+
bytes += 4;
|
|
77
|
+
index++;
|
|
78
|
+
} else bytes += 3;
|
|
79
|
+
}
|
|
80
|
+
return bytes;
|
|
81
|
+
};
|
|
82
|
+
class PostHogBrowserClient {
|
|
83
|
+
static create(options, capture) {
|
|
84
|
+
return new PostHogBrowserClient(options, capture);
|
|
85
|
+
}
|
|
86
|
+
constructor(options, capture){
|
|
87
|
+
this.library = Object.freeze({
|
|
88
|
+
name: 'web',
|
|
89
|
+
version: version
|
|
90
|
+
});
|
|
91
|
+
this._dynamicEventProperties = [];
|
|
92
|
+
this._rateLimiter = new ClientRateLimiter();
|
|
93
|
+
this._immediateAuthority = {};
|
|
94
|
+
this._closing = false;
|
|
95
|
+
this._disposed = false;
|
|
96
|
+
this._initialPageviewPending = true;
|
|
97
|
+
let projectToken = '';
|
|
98
|
+
try {
|
|
99
|
+
projectToken = options.projectToken ?? '';
|
|
100
|
+
} catch {}
|
|
101
|
+
this.projectToken = projectToken;
|
|
102
|
+
this._capturePageview = options.capturePageview ?? true;
|
|
103
|
+
this.logger = createLogger('[PostHog]', options.debug ?? false);
|
|
104
|
+
if (!projectToken) this.logger.error('A PostHog project token is required');
|
|
105
|
+
const initialPersonProperties = options.initialPersonProperties;
|
|
106
|
+
try {
|
|
107
|
+
this.initialPersonProperties = initialPersonProperties ? deepFreeze(JSON.parse(JSON.stringify(initialPersonProperties))) : Object.freeze({});
|
|
108
|
+
} catch {
|
|
109
|
+
this.initialPersonProperties = Object.freeze({});
|
|
110
|
+
}
|
|
111
|
+
this._remoteConfigPublisher = new Publisher((error)=>this.logger.error('A remote configuration listener failed', error));
|
|
112
|
+
this._eventPublisher = new Publisher((error)=>this.logger.error('An event listener failed', error));
|
|
113
|
+
this._identifyPublisher = new Publisher((error)=>this.logger.error('An identify listener failed', error));
|
|
114
|
+
this._groupPublisher = new Publisher((error)=>this.logger.error('A group listener failed', error));
|
|
115
|
+
this._resetPublisher = new Publisher((error)=>this.logger.error('A reset listener failed', error));
|
|
116
|
+
this._newSessionPublisher = new Publisher((error)=>this.logger.error('A session listener failed', error));
|
|
117
|
+
this._consentChangePublisher = new Publisher((error)=>this.logger.error('A consent change listener failed', error));
|
|
118
|
+
const browserNavigator = false === options.navigator ? void 0 : options.navigator ?? getDefaultNavigator();
|
|
119
|
+
const browserFetch = false === options.fetch ? void 0 : options.fetch ?? getDefaultFetch();
|
|
120
|
+
this._blocked = !projectToken || !(options.disableBotDetection ?? false) && isLikelyBot(browserNavigator, options.blockedUserAgents ?? []);
|
|
121
|
+
const requestedStorage = false === options.storage ? void 0 : options.storage ?? getDefaultStorage();
|
|
122
|
+
const storage = this._blocked ? void 0 : requestedStorage;
|
|
123
|
+
this._state = new BrowserState(projectToken, storage, options.persistenceKey, options.consentPersistenceName, options.optOutByDefault ?? false, !this._blocked && void 0 === options.storage && void 0 !== requestedStorage ? getDefaultSessionStorage : void 0, (consent, previous)=>{
|
|
124
|
+
if ('denied' === consent) {
|
|
125
|
+
this._immediateAuthority = {};
|
|
126
|
+
this._captureSink?.purge();
|
|
127
|
+
}
|
|
128
|
+
this._consentChangePublisher.publish({
|
|
129
|
+
current: consent,
|
|
130
|
+
previous
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
this._consentObservation = this._observeConsent(storage, !this._blocked && void 0 === options.storage && void 0 !== requestedStorage);
|
|
134
|
+
const apiHost = normalizeHost(options.apiHost ?? 'https://us.i.posthog.com');
|
|
135
|
+
this._requestRuntime = [
|
|
136
|
+
{
|
|
137
|
+
api: apiHost,
|
|
138
|
+
flags: normalizeHost(options.flagsHost ?? apiHost),
|
|
139
|
+
assets: getAssetsHost(apiHost)
|
|
140
|
+
},
|
|
141
|
+
projectToken,
|
|
142
|
+
browserFetch,
|
|
143
|
+
browserNavigator
|
|
144
|
+
];
|
|
145
|
+
this._remoteConfig = options.remoteConfig;
|
|
146
|
+
this._remoteConfigTimeoutMs = void 0 !== options.remoteConfigTimeoutMs && Number.isFinite(options.remoteConfigTimeoutMs) ? Math.max(0, options.remoteConfigTimeoutMs) : 10000;
|
|
147
|
+
this.kv = this._state.keyValueStore('core', ()=>!this._closing && !this._disposed && this._state.prepare());
|
|
148
|
+
this._latestRemoteConfigResult = this._remoteConfig ? {
|
|
149
|
+
ok: true,
|
|
150
|
+
config: this._remoteConfig
|
|
151
|
+
} : void 0;
|
|
152
|
+
this.onRemoteConfig = (handler)=>{
|
|
153
|
+
if (this._closing || this._disposed) return {
|
|
154
|
+
dispose () {}
|
|
155
|
+
};
|
|
156
|
+
const subscription = this._remoteConfigPublisher.listener(handler);
|
|
157
|
+
if (this._latestRemoteConfigResult) try {
|
|
158
|
+
handler(this._latestRemoteConfigResult);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
this.logger.error('A remote configuration listener failed', error);
|
|
161
|
+
}
|
|
162
|
+
else if (!this._closing && !this._disposed) this.getRemoteConfig();
|
|
163
|
+
return subscription;
|
|
164
|
+
};
|
|
165
|
+
this.onEvent = this._eventPublisher.listener;
|
|
166
|
+
this.onIdentify = this._identifyPublisher.listener;
|
|
167
|
+
this.onGroup = this._groupPublisher.listener;
|
|
168
|
+
this.onReset = this._resetPublisher.listener;
|
|
169
|
+
this.onConsentChange = this._consentChangePublisher.listener;
|
|
170
|
+
this.onNewSession = this._newSessionPublisher.listener;
|
|
171
|
+
this.onSession = (listener)=>this.onNewSession((session)=>listener(session.sessionId));
|
|
172
|
+
this._registry = new ExtensionRegistry((extensionName)=>this._createExtensionClient(extensionName), this.logger);
|
|
173
|
+
this._captureSink = capture;
|
|
174
|
+
}
|
|
175
|
+
get distinctId() {
|
|
176
|
+
this._state.prepare();
|
|
177
|
+
return this._state.distinctId;
|
|
178
|
+
}
|
|
179
|
+
get anonymousId() {
|
|
180
|
+
this._state.prepare();
|
|
181
|
+
return this._state.anonymousId;
|
|
182
|
+
}
|
|
183
|
+
get deviceId() {
|
|
184
|
+
this._state.prepare();
|
|
185
|
+
return this._state.deviceId;
|
|
186
|
+
}
|
|
187
|
+
get groups() {
|
|
188
|
+
this._state.prepare();
|
|
189
|
+
return this._state.groups;
|
|
190
|
+
}
|
|
191
|
+
get session() {
|
|
192
|
+
this._state.prepare();
|
|
193
|
+
return this._state.session;
|
|
194
|
+
}
|
|
195
|
+
get isOptedOut() {
|
|
196
|
+
return this.hasOptedOut();
|
|
197
|
+
}
|
|
198
|
+
get canCapture() {
|
|
199
|
+
return !this._closing && !this._disposed && !this._blocked && !this.hasOptedOut() && this._state.prepare();
|
|
200
|
+
}
|
|
201
|
+
get isRateLimited() {
|
|
202
|
+
return this._rateLimiter.wouldLimit;
|
|
203
|
+
}
|
|
204
|
+
capture(event, properties = null, options = {}) {
|
|
205
|
+
try {
|
|
206
|
+
if ('unload' === options.delivery && !this._captureSink?.isTearingDown) {
|
|
207
|
+
const authority = this._immediateAuthority;
|
|
208
|
+
const message = this._admitCapture(event, properties, options, false, true);
|
|
209
|
+
if (message) this._captureSink?.deliverUnload(message, ()=>this._immediateAuthority === authority);
|
|
210
|
+
return !!message || !this._rateLimiter.limited;
|
|
211
|
+
}
|
|
212
|
+
} catch (error) {
|
|
213
|
+
this.logger.error('Unload capture failed', error);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
return this._capture(event, properties, options) || !this._rateLimiter.limited;
|
|
217
|
+
}
|
|
218
|
+
async captureImmediate(event, properties = null, options = {}) {
|
|
219
|
+
try {
|
|
220
|
+
const authority = this._immediateAuthority;
|
|
221
|
+
const message = this._admitCapture(event, properties, options, false, true);
|
|
222
|
+
if (!message) return EMPTY_CAPTURE_SUMMARY;
|
|
223
|
+
const capture = this._captureSink;
|
|
224
|
+
if (!capture) return captureFailure(new Error('Immediate analytics delivery is unavailable'));
|
|
225
|
+
return await capture.deliverImmediate(message, ()=>this._immediateAuthority === authority);
|
|
226
|
+
} catch (error) {
|
|
227
|
+
return captureFailure(error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
_capture(event, properties = null, options = {}, skipRateLimit = false) {
|
|
231
|
+
return void 0 !== this._admitCapture(event, properties, options, skipRateLimit, false);
|
|
232
|
+
}
|
|
233
|
+
_admitCapture(event, properties, options, skipRateLimit, immediate) {
|
|
234
|
+
if (!isNonEmptyString(event) || this._closing || this._disposed || this._blocked || this.hasOptedOut() || !this._state.prepare()) return;
|
|
235
|
+
if (!skipRateLimit) {
|
|
236
|
+
const rateLimit = this._rateLimiter.consume();
|
|
237
|
+
if (!rateLimit.allowed) {
|
|
238
|
+
if (void 0 !== rateLimit.reportDropped) {
|
|
239
|
+
const warning = `${rateLimit.reportDropped} event(s) dropped since the last warning. Client limit is 10 events per second with a burst of 100.`;
|
|
240
|
+
this.logger.warn(`PostHog client rate limited: ${warning}`);
|
|
241
|
+
if (this._capture(CLIENT_RATE_LIMIT_WARNING, {
|
|
242
|
+
$$client_ingestion_warning_message: `posthog-js client rate limited: ${warning}`
|
|
243
|
+
}, {}, true)) this._rateLimiter.reported();
|
|
244
|
+
}
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const dynamicProperties = {};
|
|
249
|
+
for (const producer of this._dynamicEventProperties.slice())try {
|
|
250
|
+
Object.assign(dynamicProperties, producer());
|
|
251
|
+
} catch (error) {
|
|
252
|
+
this.logger.error('An event property producer failed', error);
|
|
253
|
+
}
|
|
254
|
+
let messageProperties;
|
|
255
|
+
let observedProperties;
|
|
256
|
+
let uuid;
|
|
257
|
+
let timestamp;
|
|
258
|
+
try {
|
|
259
|
+
const callerProperties = {
|
|
260
|
+
...dynamicProperties,
|
|
261
|
+
...properties ?? {}
|
|
262
|
+
};
|
|
263
|
+
const set = options.set;
|
|
264
|
+
const setOnce = options.setOnce;
|
|
265
|
+
uuid = options.uuid;
|
|
266
|
+
timestamp = options.timestamp;
|
|
267
|
+
if (set) callerProperties['$set'] = set;
|
|
268
|
+
if (setOnce) callerProperties['$set_once'] = setOnce;
|
|
269
|
+
const serializedProperties = JSON.stringify(callerProperties);
|
|
270
|
+
const parsedMessageProperties = JSON.parse(serializedProperties, function(_key, value) {
|
|
271
|
+
return null !== value || Array.isArray(this) ? value : void 0;
|
|
272
|
+
});
|
|
273
|
+
const parsedObservedProperties = JSON.parse(serializedProperties);
|
|
274
|
+
if (!isRecord(parsedMessageProperties) || !isRecord(parsedObservedProperties)) throw new Error('Event properties must serialize to an object');
|
|
275
|
+
messageProperties = parsedMessageProperties;
|
|
276
|
+
observedProperties = parsedObservedProperties;
|
|
277
|
+
} catch (error) {
|
|
278
|
+
this.logger.error('Event properties are not JSON-serializable', error);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const preparedSession = this._state.prepareSessionForEvent();
|
|
282
|
+
const session = preparedSession.context;
|
|
283
|
+
const distinctId = this._state.distinctId;
|
|
284
|
+
const deviceId = this._state.deviceId;
|
|
285
|
+
const groups = this._state.groups;
|
|
286
|
+
Object.assign(messageProperties, {
|
|
287
|
+
token: this.projectToken,
|
|
288
|
+
distinct_id: distinctId,
|
|
289
|
+
$device_id: deviceId,
|
|
290
|
+
$groups: groups,
|
|
291
|
+
$session_id: session.sessionId,
|
|
292
|
+
$window_id: session.windowId,
|
|
293
|
+
$lib: 'web',
|
|
294
|
+
$lib_version: version
|
|
295
|
+
});
|
|
296
|
+
Object.assign(observedProperties, {
|
|
297
|
+
token: this.projectToken,
|
|
298
|
+
distinct_id: distinctId,
|
|
299
|
+
$device_id: deviceId,
|
|
300
|
+
$groups: {
|
|
301
|
+
...groups
|
|
302
|
+
},
|
|
303
|
+
$session_id: session.sessionId,
|
|
304
|
+
$window_id: session.windowId,
|
|
305
|
+
$lib: 'web',
|
|
306
|
+
$lib_version: version
|
|
307
|
+
});
|
|
308
|
+
const message = {
|
|
309
|
+
uuid: uuid ?? createId(),
|
|
310
|
+
event,
|
|
311
|
+
distinct_id: distinctId,
|
|
312
|
+
properties: messageProperties,
|
|
313
|
+
timestamp: eventTimestamp(timestamp)
|
|
314
|
+
};
|
|
315
|
+
let bytes;
|
|
316
|
+
try {
|
|
317
|
+
bytes = utf8Bytes(JSON.stringify(message));
|
|
318
|
+
} catch (error) {
|
|
319
|
+
this.logger.error('The finalized event could not be measured', error);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
const capture = this._captureSink;
|
|
323
|
+
if (immediate ? bytes > MAX_ANALYTICS_BYTES : !capture?.enqueue(message, bytes)) {
|
|
324
|
+
if (bytes > MAX_ANALYTICS_BYTES) this.logger.warn(`Event "${event}" (${bytes} bytes) exceeds the local analytics limit and was dropped`);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (!this._state.sessionAdmitted(preparedSession)) {
|
|
328
|
+
if (!immediate) capture?.discardQueued(message);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (preparedSession.reason) this._newSessionPublisher.publish({
|
|
332
|
+
...session,
|
|
333
|
+
reason: preparedSession.reason
|
|
334
|
+
});
|
|
335
|
+
this._eventPublisher.publish(deepFreeze({
|
|
336
|
+
event,
|
|
337
|
+
properties: observedProperties
|
|
338
|
+
}));
|
|
339
|
+
if (!immediate) capture?.admitted();
|
|
340
|
+
return message;
|
|
341
|
+
}
|
|
342
|
+
async identify(distinctId, set, setOnce) {
|
|
343
|
+
if (!isValidDistinctId(distinctId) || this._closing || this._disposed) return;
|
|
344
|
+
this._state.prepare();
|
|
345
|
+
const previousDistinctId = this._state.distinctId;
|
|
346
|
+
const wasIdentified = this._state.isIdentified;
|
|
347
|
+
const captureOptions = {};
|
|
348
|
+
if (set) captureOptions.set = set;
|
|
349
|
+
if (setOnce) captureOptions.setOnce = setOnce;
|
|
350
|
+
const hasPersonProperties = !!set || !!setOnce;
|
|
351
|
+
if (distinctId === previousDistinctId) {
|
|
352
|
+
if (wasIdentified) {
|
|
353
|
+
if (hasPersonProperties) {
|
|
354
|
+
this._identifyPublisher.publish({
|
|
355
|
+
distinctId,
|
|
356
|
+
previousDistinctId,
|
|
357
|
+
wasIdentified,
|
|
358
|
+
set,
|
|
359
|
+
setOnce
|
|
360
|
+
});
|
|
361
|
+
this.capture('$set', null, captureOptions);
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
this._state.identify(distinctId);
|
|
365
|
+
this._identifyPublisher.publish({
|
|
366
|
+
distinctId,
|
|
367
|
+
previousDistinctId,
|
|
368
|
+
wasIdentified,
|
|
369
|
+
set,
|
|
370
|
+
setOnce
|
|
371
|
+
});
|
|
372
|
+
this.capture('$set', null, {
|
|
373
|
+
set: set ?? {},
|
|
374
|
+
setOnce: setOnce ?? {}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
this._state.identify(distinctId);
|
|
380
|
+
this._identifyPublisher.publish({
|
|
381
|
+
distinctId,
|
|
382
|
+
previousDistinctId,
|
|
383
|
+
wasIdentified,
|
|
384
|
+
set,
|
|
385
|
+
setOnce
|
|
386
|
+
});
|
|
387
|
+
if (wasIdentified) {
|
|
388
|
+
if (hasPersonProperties) this.capture('$set', null, captureOptions);
|
|
389
|
+
} else this.capture('$identify', {
|
|
390
|
+
$anon_distinct_id: previousDistinctId
|
|
391
|
+
}, captureOptions);
|
|
392
|
+
}
|
|
393
|
+
async group(type, key, properties) {
|
|
394
|
+
if (!isNonEmptyString(type) || !isNonEmptyString(key) || this._closing || this._disposed) return;
|
|
395
|
+
this._state.prepare();
|
|
396
|
+
const changed = this._state.group(type, key);
|
|
397
|
+
if (!changed && !properties) return;
|
|
398
|
+
this._groupPublisher.publish({
|
|
399
|
+
type,
|
|
400
|
+
key,
|
|
401
|
+
changed,
|
|
402
|
+
properties
|
|
403
|
+
});
|
|
404
|
+
this.capture('$groupidentify', {
|
|
405
|
+
$group_type: type,
|
|
406
|
+
$group_key: key,
|
|
407
|
+
...properties ? {
|
|
408
|
+
$group_set: properties
|
|
409
|
+
} : {}
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
reset() {
|
|
413
|
+
if (this._closing || this._disposed) return;
|
|
414
|
+
this._state.prepare();
|
|
415
|
+
this._state.reset();
|
|
416
|
+
this._resetPublisher.publish(void 0);
|
|
417
|
+
}
|
|
418
|
+
async flush() {
|
|
419
|
+
await this._registry.flush();
|
|
420
|
+
}
|
|
421
|
+
optIn() {
|
|
422
|
+
if (this._disposed) return;
|
|
423
|
+
if (this._state.optIn()) this._dispatchConsentChange();
|
|
424
|
+
this._startInitialPageview();
|
|
425
|
+
}
|
|
426
|
+
optOut() {
|
|
427
|
+
if (!this._disposed && this._state.optOut()) this._dispatchConsentChange();
|
|
428
|
+
}
|
|
429
|
+
hasOptedOut() {
|
|
430
|
+
return 'denied' === this._state.consent;
|
|
431
|
+
}
|
|
432
|
+
registerDynamicEventProperties(producer) {
|
|
433
|
+
if (this._disposed) return {
|
|
434
|
+
dispose () {}
|
|
435
|
+
};
|
|
436
|
+
this._dynamicEventProperties.push(producer);
|
|
437
|
+
let active = true;
|
|
438
|
+
return {
|
|
439
|
+
dispose: ()=>{
|
|
440
|
+
if (!active) return;
|
|
441
|
+
active = false;
|
|
442
|
+
const index = this._dynamicEventProperties.indexOf(producer);
|
|
443
|
+
if (-1 !== index) this._dynamicEventProperties.splice(index, 1);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
sendRequest(path, init) {
|
|
448
|
+
return sendRequest(this._requestRuntime, path, init, ()=>!this._blocked && !this.hasOptedOut());
|
|
449
|
+
}
|
|
450
|
+
async getRemoteConfig() {
|
|
451
|
+
if (this._closing || this._disposed) return;
|
|
452
|
+
if (void 0 !== this._remoteConfig) return this._remoteConfig;
|
|
453
|
+
if (!this._remoteConfigPromise) {
|
|
454
|
+
let timeout;
|
|
455
|
+
let invalidated = false;
|
|
456
|
+
let controller;
|
|
457
|
+
let cancelWait;
|
|
458
|
+
const timeoutResult = new Promise((resolve)=>{
|
|
459
|
+
cancelWait = ()=>{
|
|
460
|
+
if (void 0 !== timeout) {
|
|
461
|
+
try {
|
|
462
|
+
globalThis.clearTimeout(timeout);
|
|
463
|
+
} catch {}
|
|
464
|
+
timeout = void 0;
|
|
465
|
+
}
|
|
466
|
+
resolve(void 0);
|
|
467
|
+
};
|
|
468
|
+
this._cancelRemoteConfigWait = cancelWait;
|
|
469
|
+
try {
|
|
470
|
+
timeout = globalThis.setTimeout(cancelWait, this._remoteConfigTimeoutMs);
|
|
471
|
+
} catch {
|
|
472
|
+
cancelWait();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
this._remoteConfigPromise = Promise.race([
|
|
476
|
+
Promise.resolve().then(()=>{
|
|
477
|
+
if (this._closing || this._disposed) {
|
|
478
|
+
invalidated = true;
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
controller = 'function' == typeof globalThis.AbortController ? new globalThis.AbortController() : void 0;
|
|
482
|
+
return loadRemoteConfig(this._requestRuntime, controller?.signal, ()=>!this._closing && !this._disposed && !this._blocked);
|
|
483
|
+
}),
|
|
484
|
+
timeoutResult
|
|
485
|
+
]).then((remoteConfig)=>{
|
|
486
|
+
if (this._closing || this._disposed) {
|
|
487
|
+
invalidated = true;
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
this._latestRemoteConfigResult = remoteConfig ? {
|
|
491
|
+
ok: true,
|
|
492
|
+
config: remoteConfig
|
|
493
|
+
} : {
|
|
494
|
+
ok: false
|
|
495
|
+
};
|
|
496
|
+
if (remoteConfig) this._remoteConfig = remoteConfig;
|
|
497
|
+
this._remoteConfigPublisher.publish(this._latestRemoteConfigResult);
|
|
498
|
+
return remoteConfig;
|
|
499
|
+
}).catch((error)=>{
|
|
500
|
+
if (this._closing || this._disposed) {
|
|
501
|
+
invalidated = true;
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
this.logger.error('Remote configuration failed', error);
|
|
505
|
+
this._latestRemoteConfigResult = {
|
|
506
|
+
ok: false
|
|
507
|
+
};
|
|
508
|
+
this._remoteConfigPublisher.publish(this._latestRemoteConfigResult);
|
|
509
|
+
}).finally(()=>{
|
|
510
|
+
try {
|
|
511
|
+
controller?.abort();
|
|
512
|
+
} catch {}
|
|
513
|
+
if (void 0 !== timeout) try {
|
|
514
|
+
globalThis.clearTimeout(timeout);
|
|
515
|
+
} catch {}
|
|
516
|
+
if (this._cancelRemoteConfigWait === cancelWait) this._cancelRemoteConfigWait = void 0;
|
|
517
|
+
if (invalidated) this._remoteConfigPromise = void 0;
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
return this._remoteConfigPromise;
|
|
521
|
+
}
|
|
522
|
+
getExtension(name) {
|
|
523
|
+
return this._registry.get(name);
|
|
524
|
+
}
|
|
525
|
+
shutdown(shutdownTimeoutMs = DEFAULT_SHUTDOWN_TIMEOUT_MS) {
|
|
526
|
+
if (!this._shutdownPromise) {
|
|
527
|
+
this._closing = true;
|
|
528
|
+
const extensionFlush = this._registry.flush('shutdown');
|
|
529
|
+
this._removePageviewListener();
|
|
530
|
+
try {
|
|
531
|
+
this._consentObservation.dispose();
|
|
532
|
+
} catch {}
|
|
533
|
+
try {
|
|
534
|
+
this._cancelRemoteConfigWait?.();
|
|
535
|
+
} catch {}
|
|
536
|
+
this._shutdownPromise = this._shutdown(shutdownTimeoutMs, extensionFlush);
|
|
537
|
+
}
|
|
538
|
+
return this._shutdownPromise;
|
|
539
|
+
}
|
|
540
|
+
dispose() {
|
|
541
|
+
return this.shutdown();
|
|
542
|
+
}
|
|
543
|
+
async _shutdown(shutdownTimeoutMs, extensionFlush) {
|
|
544
|
+
const timeoutMs = Math.max(0, Math.floor(Number.isFinite(shutdownTimeoutMs) ? shutdownTimeoutMs : DEFAULT_SHUTDOWN_TIMEOUT_MS));
|
|
545
|
+
let timer;
|
|
546
|
+
let timedOut = false;
|
|
547
|
+
const timeout = new Promise((resolve)=>{
|
|
548
|
+
try {
|
|
549
|
+
timer = globalThis.setTimeout(()=>{
|
|
550
|
+
timedOut = true;
|
|
551
|
+
resolve();
|
|
552
|
+
}, timeoutMs);
|
|
553
|
+
} catch {
|
|
554
|
+
timedOut = true;
|
|
555
|
+
resolve();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
try {
|
|
559
|
+
await Promise.race([
|
|
560
|
+
extensionFlush,
|
|
561
|
+
timeout
|
|
562
|
+
]);
|
|
563
|
+
this._disposed = true;
|
|
564
|
+
try {
|
|
565
|
+
this._state.dispose();
|
|
566
|
+
} catch (error) {
|
|
567
|
+
this.logger.error('Failed to dispose browser state', error);
|
|
568
|
+
}
|
|
569
|
+
this._captureSink = void 0;
|
|
570
|
+
const cleanup = this._registry.dispose().catch((error)=>this.logger.error('Failed to dispose extensions', error));
|
|
571
|
+
this._remoteConfigPublisher.dispose();
|
|
572
|
+
this._eventPublisher.dispose();
|
|
573
|
+
this._identifyPublisher.dispose();
|
|
574
|
+
this._groupPublisher.dispose();
|
|
575
|
+
this._resetPublisher.dispose();
|
|
576
|
+
this._consentChangePublisher.dispose();
|
|
577
|
+
this._newSessionPublisher.dispose();
|
|
578
|
+
this._dynamicEventProperties.splice(0);
|
|
579
|
+
await Promise.race([
|
|
580
|
+
cleanup,
|
|
581
|
+
timeout
|
|
582
|
+
]);
|
|
583
|
+
if (timedOut) this.logger.warn(`PostHog shutdown stopped waiting for cleanup after ${timeoutMs}ms`);
|
|
584
|
+
} catch (error) {
|
|
585
|
+
this.logger.error('PostHog shutdown failed', error);
|
|
586
|
+
} finally{
|
|
587
|
+
if (void 0 !== timer) try {
|
|
588
|
+
globalThis.clearTimeout(timer);
|
|
589
|
+
} catch {}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
_startInitialPageview() {
|
|
593
|
+
if (!this._capturePageview || !this._initialPageviewPending || this._closing || this._disposed) return;
|
|
594
|
+
let document;
|
|
595
|
+
let visibility;
|
|
596
|
+
try {
|
|
597
|
+
document = globalThis.document;
|
|
598
|
+
visibility = document?.visibilityState;
|
|
599
|
+
} catch {
|
|
600
|
+
this._removePageviewListener();
|
|
601
|
+
this._initialPageviewPending = false;
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
if (!document || void 0 === visibility) {
|
|
605
|
+
this._removePageviewListener();
|
|
606
|
+
this._initialPageviewPending = false;
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if ('visible' !== visibility) {
|
|
610
|
+
if (this._pageviewListener?.[0] !== document) this._removePageviewListener();
|
|
611
|
+
if (!this._pageviewListener) {
|
|
612
|
+
const listener = ()=>this._startInitialPageview();
|
|
613
|
+
this._pageviewListener = [
|
|
614
|
+
document,
|
|
615
|
+
listener
|
|
616
|
+
];
|
|
617
|
+
try {
|
|
618
|
+
document.addEventListener('visibilitychange', listener);
|
|
619
|
+
} catch {
|
|
620
|
+
this._removePageviewListener();
|
|
621
|
+
this._initialPageviewPending = false;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
this._removePageviewListener();
|
|
627
|
+
this._initialPageviewPending = false;
|
|
628
|
+
if (!this._capture('$pageview')) this._initialPageviewPending = !this._disposed && !this._blocked;
|
|
629
|
+
}
|
|
630
|
+
_removePageviewListener() {
|
|
631
|
+
const listener = this._pageviewListener;
|
|
632
|
+
this._pageviewListener = void 0;
|
|
633
|
+
if (listener) try {
|
|
634
|
+
listener[0].removeEventListener('visibilitychange', listener[1]);
|
|
635
|
+
} catch {}
|
|
636
|
+
}
|
|
637
|
+
_observeConsent(storage, observeNativeStorage) {
|
|
638
|
+
if (!storage) return {
|
|
639
|
+
dispose () {}
|
|
640
|
+
};
|
|
641
|
+
const refresh = ()=>{
|
|
642
|
+
if (!this._disposed) this._state.refreshConsent();
|
|
643
|
+
};
|
|
644
|
+
const storageListener = (event)=>{
|
|
645
|
+
try {
|
|
646
|
+
const storageEvent = event;
|
|
647
|
+
if (storageEvent.storageArea === storage && (null === storageEvent.key || storageEvent.key === this._state.consentKey)) {
|
|
648
|
+
if (!this._disposed) this._state.observeConsent(storageEvent.newValue);
|
|
649
|
+
}
|
|
650
|
+
} catch {}
|
|
651
|
+
};
|
|
652
|
+
const localListener = (event)=>{
|
|
653
|
+
try {
|
|
654
|
+
if (event.detail === this._state.consentKey) refresh();
|
|
655
|
+
} catch {}
|
|
656
|
+
};
|
|
657
|
+
let adapter;
|
|
658
|
+
let storageListening = false;
|
|
659
|
+
let localListening = false;
|
|
660
|
+
if (observeNativeStorage) try {
|
|
661
|
+
globalThis.addEventListener('storage', storageListener);
|
|
662
|
+
storageListening = true;
|
|
663
|
+
} catch {}
|
|
664
|
+
try {
|
|
665
|
+
globalThis.addEventListener(CONSENT_CHANGE_EVENT, localListener);
|
|
666
|
+
localListening = true;
|
|
667
|
+
} catch {}
|
|
668
|
+
try {
|
|
669
|
+
adapter = storage?.subscribe?.(this._state.consentKey, refresh);
|
|
670
|
+
} catch {}
|
|
671
|
+
return {
|
|
672
|
+
dispose: ()=>{
|
|
673
|
+
if (storageListening) {
|
|
674
|
+
try {
|
|
675
|
+
globalThis.removeEventListener('storage', storageListener);
|
|
676
|
+
} catch {}
|
|
677
|
+
storageListening = false;
|
|
678
|
+
}
|
|
679
|
+
if (localListening) {
|
|
680
|
+
try {
|
|
681
|
+
globalThis.removeEventListener(CONSENT_CHANGE_EVENT, localListener);
|
|
682
|
+
} catch {}
|
|
683
|
+
localListening = false;
|
|
684
|
+
}
|
|
685
|
+
try {
|
|
686
|
+
adapter?.dispose();
|
|
687
|
+
} catch {}
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
_dispatchConsentChange() {
|
|
692
|
+
try {
|
|
693
|
+
globalThis.dispatchEvent(new CustomEvent(CONSENT_CHANGE_EVENT, {
|
|
694
|
+
detail: this._state.consentKey
|
|
695
|
+
}));
|
|
696
|
+
} catch {}
|
|
697
|
+
}
|
|
698
|
+
_createExtensionClient(extensionName) {
|
|
699
|
+
const host = this;
|
|
700
|
+
const logger = this.logger.createLogger(extensionName);
|
|
701
|
+
const kv = this._state.keyValueStore(extensionName, ()=>!this._closing && !this._disposed && this._state.prepare());
|
|
702
|
+
return {
|
|
703
|
+
get distinctId () {
|
|
704
|
+
return host.distinctId;
|
|
705
|
+
},
|
|
706
|
+
get anonymousId () {
|
|
707
|
+
return host.anonymousId;
|
|
708
|
+
},
|
|
709
|
+
get deviceId () {
|
|
710
|
+
return host.deviceId;
|
|
711
|
+
},
|
|
712
|
+
get library () {
|
|
713
|
+
return host.library;
|
|
714
|
+
},
|
|
715
|
+
get initialPersonProperties () {
|
|
716
|
+
return host.initialPersonProperties;
|
|
717
|
+
},
|
|
718
|
+
get groups () {
|
|
719
|
+
return host.groups;
|
|
720
|
+
},
|
|
721
|
+
get session () {
|
|
722
|
+
return host.session;
|
|
723
|
+
},
|
|
724
|
+
get isOptedOut () {
|
|
725
|
+
return host.isOptedOut;
|
|
726
|
+
},
|
|
727
|
+
get canCapture () {
|
|
728
|
+
return host.canCapture;
|
|
729
|
+
},
|
|
730
|
+
get isRateLimited () {
|
|
731
|
+
return host.isRateLimited;
|
|
732
|
+
},
|
|
733
|
+
capture: (event, properties, options)=>host.capture(event, properties, options),
|
|
734
|
+
registerDynamicEventProperties: (producer)=>host.registerDynamicEventProperties(producer),
|
|
735
|
+
getExtension: (name)=>host.getExtension(name),
|
|
736
|
+
get projectToken () {
|
|
737
|
+
return host.projectToken;
|
|
738
|
+
},
|
|
739
|
+
sendRequest: (path, init)=>host.sendRequest(path, init),
|
|
740
|
+
onConsentChange: host.onConsentChange,
|
|
741
|
+
onRemoteConfig: host.onRemoteConfig,
|
|
742
|
+
onEvent: host.onEvent,
|
|
743
|
+
onIdentify: host.onIdentify,
|
|
744
|
+
onGroup: host.onGroup,
|
|
745
|
+
onReset: host.onReset,
|
|
746
|
+
onSession: host.onSession,
|
|
747
|
+
kv,
|
|
748
|
+
logger
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
_canDeliver() {
|
|
752
|
+
return !this._disposed && !this._blocked && !this.hasOptedOut();
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
const createPostHogCore = async (options, configured = options?.extensions ?? [])=>{
|
|
756
|
+
const analytics = configured.find(isAnalyticsExtension) ?? createAnalyticsExtension();
|
|
757
|
+
const extensions = configured.filter((extension)=>extension !== analytics);
|
|
758
|
+
const client = PostHogBrowserClient.create(options ?? {
|
|
759
|
+
projectToken: ''
|
|
760
|
+
}, analytics);
|
|
761
|
+
client.getRemoteConfig();
|
|
762
|
+
let analyticsReady = false;
|
|
763
|
+
try {
|
|
764
|
+
await client._registry.install(analytics);
|
|
765
|
+
analytics.initialize({
|
|
766
|
+
runtime: client._requestRuntime,
|
|
767
|
+
canRetry: ()=>client._canDeliver(),
|
|
768
|
+
reportFailure: (error)=>client.logger.error('Event delivery failed', error),
|
|
769
|
+
reportWarning: (message)=>client.logger.warn(message),
|
|
770
|
+
onAvailable: ()=>client._startInitialPageview()
|
|
771
|
+
});
|
|
772
|
+
analyticsReady = true;
|
|
773
|
+
} catch (error) {
|
|
774
|
+
client._captureSink = void 0;
|
|
775
|
+
try {
|
|
776
|
+
await client._registry.rollback(analytics);
|
|
777
|
+
} catch (cleanupError) {
|
|
778
|
+
client.logger.error(`Failed to dispose disabled extension "${analytics.name}"`, cleanupError);
|
|
779
|
+
}
|
|
780
|
+
client.logger.error(`Failed to install configured extension "${analytics.name}"`, error);
|
|
781
|
+
}
|
|
782
|
+
for (const extension of extensions)try {
|
|
783
|
+
await client._registry.install(extension);
|
|
784
|
+
} catch (error) {
|
|
785
|
+
client.logger.error(`Failed to install configured extension "${extension.name}"`, error);
|
|
786
|
+
}
|
|
787
|
+
if (analyticsReady) await analytics.start();
|
|
788
|
+
client._startInitialPageview();
|
|
789
|
+
return client;
|
|
790
|
+
};
|
|
791
|
+
export { createPostHogCore };
|