@posthog/core 1.1.0 → 1.2.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/dist/error-tracking/chunk-ids.js +1 -1
- package/dist/error-tracking/chunk-ids.mjs +1 -1
- package/dist/error-tracking/coercers/error-event-coercer.js +4 -5
- package/dist/error-tracking/coercers/error-event-coercer.mjs +4 -5
- package/dist/error-tracking/coercers/event-coercer.js +1 -2
- package/dist/error-tracking/coercers/event-coercer.mjs +1 -2
- package/dist/error-tracking/coercers/object-coercer.js +1 -2
- package/dist/error-tracking/coercers/object-coercer.mjs +1 -2
- package/dist/error-tracking/coercers/primitive-coercer.js +1 -2
- package/dist/error-tracking/coercers/primitive-coercer.mjs +1 -2
- package/dist/error-tracking/coercers/promise-rejection-event.js +4 -5
- package/dist/error-tracking/coercers/promise-rejection-event.mjs +4 -5
- package/dist/error-tracking/coercers/string-coercer.js +3 -4
- package/dist/error-tracking/coercers/string-coercer.mjs +3 -4
- package/dist/error-tracking/coercers/utils.js +2 -4
- package/dist/error-tracking/coercers/utils.mjs +2 -4
- package/dist/error-tracking/error-properties-builder.js +11 -15
- package/dist/error-tracking/error-properties-builder.mjs +11 -15
- package/dist/error-tracking/parsers/index.js +2 -4
- package/dist/error-tracking/parsers/index.mjs +2 -4
- package/dist/error-tracking/parsers/node.js +3 -5
- package/dist/error-tracking/parsers/node.mjs +3 -5
- package/dist/error-tracking/utils.js +4 -4
- package/dist/error-tracking/utils.mjs +4 -4
- package/dist/eventemitter.js +4 -4
- package/dist/eventemitter.mjs +4 -4
- package/dist/featureFlagUtils.js +20 -45
- package/dist/featureFlagUtils.mjs +20 -45
- package/dist/gzip.js +1 -2
- package/dist/gzip.mjs +1 -2
- package/dist/index.d.ts +4 -366
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +54 -1225
- package/dist/index.mjs +5 -1190
- package/dist/posthog-core-stateless.d.ts +204 -0
- package/dist/posthog-core-stateless.d.ts.map +1 -0
- package/dist/posthog-core-stateless.js +675 -0
- package/dist/posthog-core-stateless.mjs +632 -0
- package/dist/posthog-core.d.ts +171 -0
- package/dist/posthog-core.d.ts.map +1 -0
- package/dist/posthog-core.js +554 -0
- package/dist/posthog-core.mjs +520 -0
- package/dist/testing/PostHogCoreTestClient.d.ts +2 -1
- package/dist/testing/PostHogCoreTestClient.d.ts.map +1 -1
- package/dist/testing/PostHogCoreTestClient.js +9 -11
- package/dist/testing/PostHogCoreTestClient.mjs +8 -10
- package/dist/testing/test-utils.js +1 -1
- package/dist/testing/test-utils.mjs +1 -1
- package/dist/utils/bucketed-rate-limiter.js +8 -12
- package/dist/utils/bucketed-rate-limiter.mjs +8 -12
- package/dist/utils/index.js +3 -3
- package/dist/utils/index.mjs +3 -3
- package/dist/utils/type-utils.js +1 -1
- package/dist/utils/type-utils.mjs +1 -1
- package/dist/vendor/uuidv7.js +12 -16
- package/dist/vendor/uuidv7.mjs +12 -16
- package/package.json +3 -2
- package/src/__tests__/featureFlagUtils.spec.ts +427 -0
- package/src/__tests__/gzip.spec.ts +69 -0
- package/src/__tests__/posthog.ai.spec.ts +110 -0
- package/src/__tests__/posthog.capture.spec.ts +91 -0
- package/src/__tests__/posthog.core.spec.ts +135 -0
- package/src/__tests__/posthog.debug.spec.ts +36 -0
- package/src/__tests__/posthog.enqueue.spec.ts +93 -0
- package/src/__tests__/posthog.featureflags.spec.ts +1106 -0
- package/src/__tests__/posthog.featureflags.v1.spec.ts +922 -0
- package/src/__tests__/posthog.flush.spec.ts +237 -0
- package/src/__tests__/posthog.gdpr.spec.ts +50 -0
- package/src/__tests__/posthog.groups.spec.ts +96 -0
- package/src/__tests__/posthog.identify.spec.ts +194 -0
- package/src/__tests__/posthog.init.spec.ts +110 -0
- package/src/__tests__/posthog.listeners.spec.ts +51 -0
- package/src/__tests__/posthog.register.spec.ts +47 -0
- package/src/__tests__/posthog.reset.spec.ts +76 -0
- package/src/__tests__/posthog.sessions.spec.ts +63 -0
- package/src/__tests__/posthog.setProperties.spec.ts +102 -0
- package/src/__tests__/posthog.shutdown.spec.ts +88 -0
- package/src/__tests__/utils.spec.ts +36 -0
- package/src/error-tracking/chunk-ids.ts +58 -0
- package/src/error-tracking/coercers/dom-exception-coercer.ts +38 -0
- package/src/error-tracking/coercers/error-coercer.ts +36 -0
- package/src/error-tracking/coercers/error-event-coercer.ts +24 -0
- package/src/error-tracking/coercers/event-coercer.ts +19 -0
- package/src/error-tracking/coercers/index.ts +8 -0
- package/src/error-tracking/coercers/object-coercer.ts +76 -0
- package/src/error-tracking/coercers/primitive-coercer.ts +19 -0
- package/src/error-tracking/coercers/promise-rejection-event.spec.ts +77 -0
- package/src/error-tracking/coercers/promise-rejection-event.ts +53 -0
- package/src/error-tracking/coercers/string-coercer.spec.ts +26 -0
- package/src/error-tracking/coercers/string-coercer.ts +31 -0
- package/src/error-tracking/coercers/utils.ts +33 -0
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +202 -0
- package/src/error-tracking/error-properties-builder.parse.spec.ts +30 -0
- package/src/error-tracking/error-properties-builder.ts +169 -0
- package/src/error-tracking/index.ts +5 -0
- package/src/error-tracking/parsers/base.ts +29 -0
- package/src/error-tracking/parsers/chrome.ts +53 -0
- package/src/error-tracking/parsers/gecko.ts +38 -0
- package/src/error-tracking/parsers/index.ts +104 -0
- package/src/error-tracking/parsers/node.ts +111 -0
- package/src/error-tracking/parsers/opera.ts +18 -0
- package/src/error-tracking/parsers/react-native.ts +0 -0
- package/src/error-tracking/parsers/safari.ts +33 -0
- package/src/error-tracking/parsers/winjs.ts +12 -0
- package/src/error-tracking/types.ts +107 -0
- package/src/error-tracking/utils.ts +39 -0
- package/src/eventemitter.ts +27 -0
- package/src/featureFlagUtils.ts +192 -0
- package/src/gzip.ts +29 -0
- package/src/index.ts +8 -0
- package/src/posthog-core-stateless.ts +1226 -0
- package/src/posthog-core.ts +958 -0
- package/src/testing/PostHogCoreTestClient.ts +91 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/test-utils.ts +47 -0
- package/src/types.ts +544 -0
- package/src/utils/bucketed-rate-limiter.spec.ts +33 -0
- package/src/utils/bucketed-rate-limiter.ts +85 -0
- package/src/utils/index.ts +98 -0
- package/src/utils/number-utils.spec.ts +89 -0
- package/src/utils/number-utils.ts +30 -0
- package/src/utils/promise-queue.spec.ts +55 -0
- package/src/utils/promise-queue.ts +30 -0
- package/src/utils/string-utils.ts +23 -0
- package/src/utils/type-utils.ts +134 -0
- package/src/vendor/uuidv7.ts +479 -0
package/dist/index.js
CHANGED
|
@@ -3,14 +3,17 @@ var __webpack_modules__ = {
|
|
|
3
3
|
"./error-tracking": function(module) {
|
|
4
4
|
module.exports = require("./error-tracking/index.js");
|
|
5
5
|
},
|
|
6
|
-
"./eventemitter": function(module) {
|
|
7
|
-
module.exports = require("./eventemitter.js");
|
|
8
|
-
},
|
|
9
6
|
"./featureFlagUtils": function(module) {
|
|
10
7
|
module.exports = require("./featureFlagUtils.js");
|
|
11
8
|
},
|
|
12
|
-
"./
|
|
13
|
-
module.exports = require("./
|
|
9
|
+
"./posthog-core-stateless": function(module) {
|
|
10
|
+
module.exports = require("./posthog-core-stateless.js");
|
|
11
|
+
},
|
|
12
|
+
"./posthog-core": function(module) {
|
|
13
|
+
module.exports = require("./posthog-core.js");
|
|
14
|
+
},
|
|
15
|
+
"./testing": function(module) {
|
|
16
|
+
module.exports = require("./testing/index.js");
|
|
14
17
|
},
|
|
15
18
|
"./types": function(module) {
|
|
16
19
|
module.exports = require("./types.js");
|
|
@@ -18,9 +21,6 @@ var __webpack_modules__ = {
|
|
|
18
21
|
"./utils?637c": function(module) {
|
|
19
22
|
module.exports = require("./utils/index.js");
|
|
20
23
|
},
|
|
21
|
-
"./utils/promise-queue": function(module) {
|
|
22
|
-
module.exports = require("./utils/promise-queue.js");
|
|
23
|
-
},
|
|
24
24
|
"./vendor/uuidv7": function(module) {
|
|
25
25
|
module.exports = require("./vendor/uuidv7.js");
|
|
26
26
|
}
|
|
@@ -69,1244 +69,73 @@ var __webpack_exports__ = {};
|
|
|
69
69
|
(()=>{
|
|
70
70
|
__webpack_require__.r(__webpack_exports__);
|
|
71
71
|
__webpack_require__.d(__webpack_exports__, {
|
|
72
|
-
ErrorTracking: ()=>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
logFlushError: ()=>logFlushError,
|
|
77
|
-
maybeAdd: ()=>maybeAdd
|
|
72
|
+
ErrorTracking: ()=>_error_tracking__WEBPACK_IMPORTED_MODULE_2__,
|
|
73
|
+
getFeatureFlagValue: ()=>_featureFlagUtils__WEBPACK_IMPORTED_MODULE_0__.getFeatureFlagValue,
|
|
74
|
+
testing: ()=>_testing__WEBPACK_IMPORTED_MODULE_4__,
|
|
75
|
+
uuidv7: ()=>_vendor_uuidv7__WEBPACK_IMPORTED_MODULE_3__.uuidv7
|
|
78
76
|
});
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
-
var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./utils?637c");
|
|
82
|
-
var _gzip__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./gzip");
|
|
83
|
-
var _eventemitter__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./eventemitter");
|
|
84
|
-
var _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./vendor/uuidv7");
|
|
85
|
-
var _utils_promise_queue__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./utils/promise-queue");
|
|
77
|
+
var _featureFlagUtils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./featureFlagUtils");
|
|
78
|
+
var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./utils?637c");
|
|
86
79
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
87
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
80
|
+
for(var __WEBPACK_IMPORT_KEY__ in _utils__WEBPACK_IMPORTED_MODULE_1__)if ([
|
|
88
81
|
"ErrorTracking",
|
|
82
|
+
"testing",
|
|
89
83
|
"default",
|
|
90
|
-
"maybeAdd",
|
|
91
|
-
"logFlushError",
|
|
92
84
|
"getFeatureFlagValue",
|
|
93
|
-
"
|
|
94
|
-
"PostHogCore"
|
|
85
|
+
"uuidv7"
|
|
95
86
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
96
|
-
return
|
|
87
|
+
return _utils__WEBPACK_IMPORTED_MODULE_1__[key];
|
|
97
88
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
98
89
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
99
|
-
var
|
|
90
|
+
var _error_tracking__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./error-tracking");
|
|
91
|
+
var _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./vendor/uuidv7");
|
|
92
|
+
var _testing__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("./testing");
|
|
93
|
+
var _posthog_core__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./posthog-core");
|
|
100
94
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
101
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
95
|
+
for(var __WEBPACK_IMPORT_KEY__ in _posthog_core__WEBPACK_IMPORTED_MODULE_5__)if ([
|
|
102
96
|
"ErrorTracking",
|
|
97
|
+
"testing",
|
|
103
98
|
"default",
|
|
104
|
-
"maybeAdd",
|
|
105
|
-
"logFlushError",
|
|
106
99
|
"getFeatureFlagValue",
|
|
107
|
-
"
|
|
108
|
-
"PostHogCore"
|
|
100
|
+
"uuidv7"
|
|
109
101
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
110
|
-
return
|
|
102
|
+
return _posthog_core__WEBPACK_IMPORTED_MODULE_5__[key];
|
|
103
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
104
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
105
|
+
var _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./posthog-core-stateless");
|
|
106
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
107
|
+
for(var __WEBPACK_IMPORT_KEY__ in _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_6__)if ([
|
|
108
|
+
"ErrorTracking",
|
|
109
|
+
"testing",
|
|
110
|
+
"default",
|
|
111
|
+
"getFeatureFlagValue",
|
|
112
|
+
"uuidv7"
|
|
113
|
+
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
114
|
+
return _posthog_core_stateless__WEBPACK_IMPORTED_MODULE_6__[key];
|
|
115
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
116
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
117
|
+
var _types__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__("./types");
|
|
118
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
119
|
+
for(var __WEBPACK_IMPORT_KEY__ in _types__WEBPACK_IMPORTED_MODULE_7__)if ([
|
|
120
|
+
"ErrorTracking",
|
|
121
|
+
"testing",
|
|
122
|
+
"default",
|
|
123
|
+
"getFeatureFlagValue",
|
|
124
|
+
"uuidv7"
|
|
125
|
+
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
126
|
+
return _types__WEBPACK_IMPORTED_MODULE_7__[key];
|
|
111
127
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
112
128
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
113
|
-
class PostHogFetchHttpError extends Error {
|
|
114
|
-
get status() {
|
|
115
|
-
return this.response.status;
|
|
116
|
-
}
|
|
117
|
-
get text() {
|
|
118
|
-
return this.response.text();
|
|
119
|
-
}
|
|
120
|
-
get json() {
|
|
121
|
-
return this.response.json();
|
|
122
|
-
}
|
|
123
|
-
constructor(response, reqByteLength){
|
|
124
|
-
super('HTTP error while fetching PostHog: status=' + response.status + ', reqByteLength=' + reqByteLength), this.response = response, this.reqByteLength = reqByteLength, this.name = 'PostHogFetchHttpError';
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
class PostHogFetchNetworkError extends Error {
|
|
128
|
-
constructor(error){
|
|
129
|
-
super('Network error while fetching PostHog', error instanceof Error ? {
|
|
130
|
-
cause: error
|
|
131
|
-
} : {}), this.error = error, this.name = 'PostHogFetchNetworkError';
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
const maybeAdd = (key, value)=>void 0 !== value ? {
|
|
135
|
-
[key]: value
|
|
136
|
-
} : {};
|
|
137
|
-
async function logFlushError(err) {
|
|
138
|
-
if (err instanceof PostHogFetchHttpError) {
|
|
139
|
-
let text = '';
|
|
140
|
-
try {
|
|
141
|
-
text = await err.text;
|
|
142
|
-
} catch (e) {}
|
|
143
|
-
console.error(`Error while flushing PostHog: message=${err.message}, response body=${text}`, err);
|
|
144
|
-
} else console.error('Error while flushing PostHog', err);
|
|
145
|
-
return Promise.resolve();
|
|
146
|
-
}
|
|
147
|
-
function isPostHogFetchError(err) {
|
|
148
|
-
return 'object' == typeof err && (err instanceof PostHogFetchHttpError || err instanceof PostHogFetchNetworkError);
|
|
149
|
-
}
|
|
150
|
-
function isPostHogFetchContentTooLargeError(err) {
|
|
151
|
-
return 'object' == typeof err && err instanceof PostHogFetchHttpError && 413 === err.status;
|
|
152
|
-
}
|
|
153
|
-
class PostHogCoreStateless {
|
|
154
|
-
logMsgIfDebug(fn) {
|
|
155
|
-
if (this.isDebug) fn();
|
|
156
|
-
}
|
|
157
|
-
wrap(fn) {
|
|
158
|
-
if (this.disabled) return void this.logMsgIfDebug(()=>console.warn('[PostHog] The client is disabled'));
|
|
159
|
-
if (this._isInitialized) return fn();
|
|
160
|
-
this._initPromise.then(()=>fn());
|
|
161
|
-
}
|
|
162
|
-
getCommonEventProperties() {
|
|
163
|
-
return {
|
|
164
|
-
$lib: this.getLibraryId(),
|
|
165
|
-
$lib_version: this.getLibraryVersion()
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
get optedOut() {
|
|
169
|
-
var _this_getPersistedProperty;
|
|
170
|
-
return null != (_this_getPersistedProperty = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.OptedOut)) ? _this_getPersistedProperty : !this.defaultOptIn;
|
|
171
|
-
}
|
|
172
|
-
async optIn() {
|
|
173
|
-
this.wrap(()=>{
|
|
174
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.OptedOut, false);
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
async optOut() {
|
|
178
|
-
this.wrap(()=>{
|
|
179
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.OptedOut, true);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
on(event, cb) {
|
|
183
|
-
return this._events.on(event, cb);
|
|
184
|
-
}
|
|
185
|
-
debug() {
|
|
186
|
-
let enabled = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : true;
|
|
187
|
-
var _this_removeDebugCallback, _this;
|
|
188
|
-
null == (_this_removeDebugCallback = (_this = this).removeDebugCallback) || _this_removeDebugCallback.call(_this);
|
|
189
|
-
if (enabled) {
|
|
190
|
-
const removeDebugCallback = this.on('*', (event, payload)=>console.log('PostHog Debug', event, payload));
|
|
191
|
-
this.removeDebugCallback = ()=>{
|
|
192
|
-
removeDebugCallback();
|
|
193
|
-
this.removeDebugCallback = void 0;
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
get isDebug() {
|
|
198
|
-
return !!this.removeDebugCallback;
|
|
199
|
-
}
|
|
200
|
-
get isDisabled() {
|
|
201
|
-
return this.disabled;
|
|
202
|
-
}
|
|
203
|
-
buildPayload(payload) {
|
|
204
|
-
return {
|
|
205
|
-
distinct_id: payload.distinct_id,
|
|
206
|
-
event: payload.event,
|
|
207
|
-
properties: {
|
|
208
|
-
...payload.properties || {},
|
|
209
|
-
...this.getCommonEventProperties()
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
addPendingPromise(promise) {
|
|
214
|
-
return this.promiseQueue.add(promise);
|
|
215
|
-
}
|
|
216
|
-
identifyStateless(distinctId, properties, options) {
|
|
217
|
-
this.wrap(()=>{
|
|
218
|
-
const payload = {
|
|
219
|
-
...this.buildPayload({
|
|
220
|
-
distinct_id: distinctId,
|
|
221
|
-
event: '$identify',
|
|
222
|
-
properties
|
|
223
|
-
})
|
|
224
|
-
};
|
|
225
|
-
this.enqueue('identify', payload, options);
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
async identifyStatelessImmediate(distinctId, properties, options) {
|
|
229
|
-
const payload = {
|
|
230
|
-
...this.buildPayload({
|
|
231
|
-
distinct_id: distinctId,
|
|
232
|
-
event: '$identify',
|
|
233
|
-
properties
|
|
234
|
-
})
|
|
235
|
-
};
|
|
236
|
-
await this.sendImmediate('identify', payload, options);
|
|
237
|
-
}
|
|
238
|
-
captureStateless(distinctId, event, properties, options) {
|
|
239
|
-
this.wrap(()=>{
|
|
240
|
-
const payload = this.buildPayload({
|
|
241
|
-
distinct_id: distinctId,
|
|
242
|
-
event,
|
|
243
|
-
properties
|
|
244
|
-
});
|
|
245
|
-
this.enqueue('capture', payload, options);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
async captureStatelessImmediate(distinctId, event, properties, options) {
|
|
249
|
-
const payload = this.buildPayload({
|
|
250
|
-
distinct_id: distinctId,
|
|
251
|
-
event,
|
|
252
|
-
properties
|
|
253
|
-
});
|
|
254
|
-
await this.sendImmediate('capture', payload, options);
|
|
255
|
-
}
|
|
256
|
-
aliasStateless(alias, distinctId, properties, options) {
|
|
257
|
-
this.wrap(()=>{
|
|
258
|
-
const payload = this.buildPayload({
|
|
259
|
-
event: '$create_alias',
|
|
260
|
-
distinct_id: distinctId,
|
|
261
|
-
properties: {
|
|
262
|
-
...properties || {},
|
|
263
|
-
distinct_id: distinctId,
|
|
264
|
-
alias
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
this.enqueue('alias', payload, options);
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
async aliasStatelessImmediate(alias, distinctId, properties, options) {
|
|
271
|
-
const payload = this.buildPayload({
|
|
272
|
-
event: '$create_alias',
|
|
273
|
-
distinct_id: distinctId,
|
|
274
|
-
properties: {
|
|
275
|
-
...properties || {},
|
|
276
|
-
distinct_id: distinctId,
|
|
277
|
-
alias
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
await this.sendImmediate('alias', payload, options);
|
|
281
|
-
}
|
|
282
|
-
groupIdentifyStateless(groupType, groupKey, groupProperties, options, distinctId, eventProperties) {
|
|
283
|
-
this.wrap(()=>{
|
|
284
|
-
const payload = this.buildPayload({
|
|
285
|
-
distinct_id: distinctId || `$${groupType}_${groupKey}`,
|
|
286
|
-
event: '$groupidentify',
|
|
287
|
-
properties: {
|
|
288
|
-
$group_type: groupType,
|
|
289
|
-
$group_key: groupKey,
|
|
290
|
-
$group_set: groupProperties || {},
|
|
291
|
-
...eventProperties || {}
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
this.enqueue('capture', payload, options);
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
async getRemoteConfig() {
|
|
298
|
-
await this._initPromise;
|
|
299
|
-
let host = this.host;
|
|
300
|
-
if ('https://us.i.posthog.com' === host) host = 'https://us-assets.i.posthog.com';
|
|
301
|
-
else if ('https://eu.i.posthog.com' === host) host = 'https://eu-assets.i.posthog.com';
|
|
302
|
-
const url = `${host}/array/${this.apiKey}/config`;
|
|
303
|
-
const fetchOptions = {
|
|
304
|
-
method: 'GET',
|
|
305
|
-
headers: {
|
|
306
|
-
...this.getCustomHeaders(),
|
|
307
|
-
'Content-Type': 'application/json'
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
return this.fetchWithRetry(url, fetchOptions, {
|
|
311
|
-
retryCount: 0
|
|
312
|
-
}, this.remoteConfigRequestTimeoutMs).then((response)=>response.json()).catch((error)=>{
|
|
313
|
-
this.logMsgIfDebug(()=>console.error('Remote config could not be loaded', error));
|
|
314
|
-
this._events.emit('error', error);
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
async getFlags(distinctId) {
|
|
318
|
-
let groups = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, personProperties = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, groupProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, extraPayload = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {};
|
|
319
|
-
await this._initPromise;
|
|
320
|
-
const url = `${this.host}/flags/?v=2&config=true`;
|
|
321
|
-
const fetchOptions = {
|
|
322
|
-
method: 'POST',
|
|
323
|
-
headers: {
|
|
324
|
-
...this.getCustomHeaders(),
|
|
325
|
-
'Content-Type': 'application/json'
|
|
326
|
-
},
|
|
327
|
-
body: JSON.stringify({
|
|
328
|
-
token: this.apiKey,
|
|
329
|
-
distinct_id: distinctId,
|
|
330
|
-
groups,
|
|
331
|
-
person_properties: personProperties,
|
|
332
|
-
group_properties: groupProperties,
|
|
333
|
-
...extraPayload
|
|
334
|
-
})
|
|
335
|
-
};
|
|
336
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Flags URL', url));
|
|
337
|
-
return this.fetchWithRetry(url, fetchOptions, {
|
|
338
|
-
retryCount: 0
|
|
339
|
-
}, this.featureFlagsRequestTimeoutMs).then((response)=>response.json()).then((response)=>(0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.normalizeFlagsResponse)(response)).catch((error)=>{
|
|
340
|
-
this._events.emit('error', error);
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
async getFeatureFlagStateless(key, distinctId) {
|
|
344
|
-
let groups = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, personProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, groupProperties = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, disableGeoip = arguments.length > 5 ? arguments[5] : void 0;
|
|
345
|
-
await this._initPromise;
|
|
346
|
-
const flagDetailResponse = await this.getFeatureFlagDetailStateless(key, distinctId, groups, personProperties, groupProperties, disableGeoip);
|
|
347
|
-
if (void 0 === flagDetailResponse) return {
|
|
348
|
-
response: void 0,
|
|
349
|
-
requestId: void 0
|
|
350
|
-
};
|
|
351
|
-
let response = (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getFeatureFlagValue)(flagDetailResponse.response);
|
|
352
|
-
if (void 0 === response) response = false;
|
|
353
|
-
return {
|
|
354
|
-
response,
|
|
355
|
-
requestId: flagDetailResponse.requestId
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
async getFeatureFlagDetailStateless(key, distinctId) {
|
|
359
|
-
let groups = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, personProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, groupProperties = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, disableGeoip = arguments.length > 5 ? arguments[5] : void 0;
|
|
360
|
-
await this._initPromise;
|
|
361
|
-
const flagsResponse = await this.getFeatureFlagDetailsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, [
|
|
362
|
-
key
|
|
363
|
-
]);
|
|
364
|
-
if (void 0 === flagsResponse) return;
|
|
365
|
-
const featureFlags = flagsResponse.flags;
|
|
366
|
-
const flagDetail = featureFlags[key];
|
|
367
|
-
return {
|
|
368
|
-
response: flagDetail,
|
|
369
|
-
requestId: flagsResponse.requestId
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
async getFeatureFlagPayloadStateless(key, distinctId) {
|
|
373
|
-
let groups = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, personProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, groupProperties = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {}, disableGeoip = arguments.length > 5 ? arguments[5] : void 0;
|
|
374
|
-
await this._initPromise;
|
|
375
|
-
const payloads = await this.getFeatureFlagPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, [
|
|
376
|
-
key
|
|
377
|
-
]);
|
|
378
|
-
if (!payloads) return;
|
|
379
|
-
const response = payloads[key];
|
|
380
|
-
if (void 0 === response) return null;
|
|
381
|
-
return response;
|
|
382
|
-
}
|
|
383
|
-
async getFeatureFlagPayloadsStateless(distinctId) {
|
|
384
|
-
let groups = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, personProperties = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, groupProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, disableGeoip = arguments.length > 4 ? arguments[4] : void 0, flagKeysToEvaluate = arguments.length > 5 ? arguments[5] : void 0;
|
|
385
|
-
await this._initPromise;
|
|
386
|
-
const payloads = (await this.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeysToEvaluate)).payloads;
|
|
387
|
-
return payloads;
|
|
388
|
-
}
|
|
389
|
-
async getFeatureFlagsStateless(distinctId) {
|
|
390
|
-
let groups = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, personProperties = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, groupProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, disableGeoip = arguments.length > 4 ? arguments[4] : void 0, flagKeysToEvaluate = arguments.length > 5 ? arguments[5] : void 0;
|
|
391
|
-
await this._initPromise;
|
|
392
|
-
return await this.getFeatureFlagsAndPayloadsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeysToEvaluate);
|
|
393
|
-
}
|
|
394
|
-
async getFeatureFlagsAndPayloadsStateless(distinctId) {
|
|
395
|
-
let groups = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, personProperties = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, groupProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, disableGeoip = arguments.length > 4 ? arguments[4] : void 0, flagKeysToEvaluate = arguments.length > 5 ? arguments[5] : void 0;
|
|
396
|
-
await this._initPromise;
|
|
397
|
-
const featureFlagDetails = await this.getFeatureFlagDetailsStateless(distinctId, groups, personProperties, groupProperties, disableGeoip, flagKeysToEvaluate);
|
|
398
|
-
if (!featureFlagDetails) return {
|
|
399
|
-
flags: void 0,
|
|
400
|
-
payloads: void 0,
|
|
401
|
-
requestId: void 0
|
|
402
|
-
};
|
|
403
|
-
return {
|
|
404
|
-
flags: featureFlagDetails.featureFlags,
|
|
405
|
-
payloads: featureFlagDetails.featureFlagPayloads,
|
|
406
|
-
requestId: featureFlagDetails.requestId
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
async getFeatureFlagDetailsStateless(distinctId) {
|
|
410
|
-
let groups = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, personProperties = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, groupProperties = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {}, disableGeoip = arguments.length > 4 ? arguments[4] : void 0, flagKeysToEvaluate = arguments.length > 5 ? arguments[5] : void 0;
|
|
411
|
-
var _flagsResponse_quotaLimited;
|
|
412
|
-
await this._initPromise;
|
|
413
|
-
const extraPayload = {};
|
|
414
|
-
if (null != disableGeoip ? disableGeoip : this.disableGeoip) extraPayload['geoip_disable'] = true;
|
|
415
|
-
if (flagKeysToEvaluate) extraPayload['flag_keys_to_evaluate'] = flagKeysToEvaluate;
|
|
416
|
-
const flagsResponse = await this.getFlags(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
417
|
-
if (void 0 === flagsResponse) return;
|
|
418
|
-
if (flagsResponse.errorsWhileComputingFlags) console.error('[FEATURE FLAGS] Error while computing feature flags, some flags may be missing or incorrect. Learn more at https://posthog.com/docs/feature-flags/best-practices');
|
|
419
|
-
if (null == (_flagsResponse_quotaLimited = flagsResponse.quotaLimited) ? void 0 : _flagsResponse_quotaLimited.includes("feature_flags")) {
|
|
420
|
-
console.warn('[FEATURE FLAGS] Feature flags quota limit exceeded - feature flags unavailable. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
421
|
-
return {
|
|
422
|
-
flags: {},
|
|
423
|
-
featureFlags: {},
|
|
424
|
-
featureFlagPayloads: {},
|
|
425
|
-
requestId: null == flagsResponse ? void 0 : flagsResponse.requestId
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
return flagsResponse;
|
|
429
|
-
}
|
|
430
|
-
async getSurveysStateless() {
|
|
431
|
-
await this._initPromise;
|
|
432
|
-
if (true === this.disableSurveys) {
|
|
433
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Loading surveys is disabled.'));
|
|
434
|
-
return [];
|
|
435
|
-
}
|
|
436
|
-
const url = `${this.host}/api/surveys/?token=${this.apiKey}`;
|
|
437
|
-
const fetchOptions = {
|
|
438
|
-
method: 'GET',
|
|
439
|
-
headers: {
|
|
440
|
-
...this.getCustomHeaders(),
|
|
441
|
-
'Content-Type': 'application/json'
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
const response = await this.fetchWithRetry(url, fetchOptions).then((response)=>{
|
|
445
|
-
if (200 !== response.status || !response.json) {
|
|
446
|
-
const msg = `Surveys API could not be loaded: ${response.status}`;
|
|
447
|
-
const error = new Error(msg);
|
|
448
|
-
this.logMsgIfDebug(()=>console.error(error));
|
|
449
|
-
this._events.emit('error', new Error(msg));
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
return response.json();
|
|
453
|
-
}).catch((error)=>{
|
|
454
|
-
this.logMsgIfDebug(()=>console.error('Surveys API could not be loaded', error));
|
|
455
|
-
this._events.emit('error', error);
|
|
456
|
-
});
|
|
457
|
-
const newSurveys = null == response ? void 0 : response.surveys;
|
|
458
|
-
if (newSurveys) this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Surveys fetched from API: ', JSON.stringify(newSurveys)));
|
|
459
|
-
return null != newSurveys ? newSurveys : [];
|
|
460
|
-
}
|
|
461
|
-
get props() {
|
|
462
|
-
if (!this._props) this._props = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Props);
|
|
463
|
-
return this._props || {};
|
|
464
|
-
}
|
|
465
|
-
set props(val) {
|
|
466
|
-
this._props = val;
|
|
467
|
-
}
|
|
468
|
-
async register(properties) {
|
|
469
|
-
this.wrap(()=>{
|
|
470
|
-
this.props = {
|
|
471
|
-
...this.props,
|
|
472
|
-
...properties
|
|
473
|
-
};
|
|
474
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Props, this.props);
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
async unregister(property) {
|
|
478
|
-
this.wrap(()=>{
|
|
479
|
-
delete this.props[property];
|
|
480
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Props, this.props);
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
enqueue(type, _message, options) {
|
|
484
|
-
this.wrap(()=>{
|
|
485
|
-
if (this.optedOut) return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
486
|
-
const message = this.prepareMessage(type, _message, options);
|
|
487
|
-
const queue = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue) || [];
|
|
488
|
-
if (queue.length >= this.maxQueueSize) {
|
|
489
|
-
queue.shift();
|
|
490
|
-
this.logMsgIfDebug(()=>console.info('Queue is full, the oldest event is dropped.'));
|
|
491
|
-
}
|
|
492
|
-
queue.push({
|
|
493
|
-
message
|
|
494
|
-
});
|
|
495
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue, queue);
|
|
496
|
-
this._events.emit(type, message);
|
|
497
|
-
if (queue.length >= this.flushAt) this.flushBackground();
|
|
498
|
-
if (this.flushInterval && !this._flushTimer) this._flushTimer = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.safeSetTimeout)(()=>this.flushBackground(), this.flushInterval);
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
async sendImmediate(type, _message, options) {
|
|
502
|
-
if (this.disabled) return void this.logMsgIfDebug(()=>console.warn('[PostHog] The client is disabled'));
|
|
503
|
-
if (!this._isInitialized) await this._initPromise;
|
|
504
|
-
if (this.optedOut) return void this._events.emit(type, "Library is disabled. Not sending event. To re-enable, call posthog.optIn()");
|
|
505
|
-
const data = {
|
|
506
|
-
api_key: this.apiKey,
|
|
507
|
-
batch: [
|
|
508
|
-
this.prepareMessage(type, _message, options)
|
|
509
|
-
],
|
|
510
|
-
sent_at: (0, _utils__WEBPACK_IMPORTED_MODULE_2__.currentISOTime)()
|
|
511
|
-
};
|
|
512
|
-
if (this.historicalMigration) data.historical_migration = true;
|
|
513
|
-
const payload = JSON.stringify(data);
|
|
514
|
-
const url = `${this.host}/batch/`;
|
|
515
|
-
const gzippedPayload = this.disableCompression ? null : await (0, _gzip__WEBPACK_IMPORTED_MODULE_3__.gzipCompress)(payload, this.isDebug);
|
|
516
|
-
const fetchOptions = {
|
|
517
|
-
method: 'POST',
|
|
518
|
-
headers: {
|
|
519
|
-
...this.getCustomHeaders(),
|
|
520
|
-
'Content-Type': 'application/json',
|
|
521
|
-
...null !== gzippedPayload && {
|
|
522
|
-
'Content-Encoding': 'gzip'
|
|
523
|
-
}
|
|
524
|
-
},
|
|
525
|
-
body: gzippedPayload || payload
|
|
526
|
-
};
|
|
527
|
-
try {
|
|
528
|
-
await this.fetchWithRetry(url, fetchOptions);
|
|
529
|
-
} catch (err) {
|
|
530
|
-
this._events.emit('error', err);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
prepareMessage(type, _message, options) {
|
|
534
|
-
const message = {
|
|
535
|
-
..._message,
|
|
536
|
-
type: type,
|
|
537
|
-
library: this.getLibraryId(),
|
|
538
|
-
library_version: this.getLibraryVersion(),
|
|
539
|
-
timestamp: (null == options ? void 0 : options.timestamp) ? null == options ? void 0 : options.timestamp : (0, _utils__WEBPACK_IMPORTED_MODULE_2__.currentISOTime)(),
|
|
540
|
-
uuid: (null == options ? void 0 : options.uuid) ? options.uuid : (0, _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_5__.uuidv7)()
|
|
541
|
-
};
|
|
542
|
-
var _options_disableGeoip;
|
|
543
|
-
const addGeoipDisableProperty = null != (_options_disableGeoip = null == options ? void 0 : options.disableGeoip) ? _options_disableGeoip : this.disableGeoip;
|
|
544
|
-
if (addGeoipDisableProperty) {
|
|
545
|
-
if (!message.properties) message.properties = {};
|
|
546
|
-
message['properties']['$geoip_disable'] = true;
|
|
547
|
-
}
|
|
548
|
-
if (message.distinctId) {
|
|
549
|
-
message.distinct_id = message.distinctId;
|
|
550
|
-
delete message.distinctId;
|
|
551
|
-
}
|
|
552
|
-
return message;
|
|
553
|
-
}
|
|
554
|
-
clearFlushTimer() {
|
|
555
|
-
if (this._flushTimer) {
|
|
556
|
-
clearTimeout(this._flushTimer);
|
|
557
|
-
this._flushTimer = void 0;
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
flushBackground() {
|
|
561
|
-
this.flush().catch(async (err)=>{
|
|
562
|
-
await logFlushError(err);
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
async flush() {
|
|
566
|
-
const nextFlushPromise = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.allSettled)([
|
|
567
|
-
this.flushPromise
|
|
568
|
-
]).then(()=>this._flush());
|
|
569
|
-
this.flushPromise = nextFlushPromise;
|
|
570
|
-
this.addPendingPromise(nextFlushPromise);
|
|
571
|
-
(0, _utils__WEBPACK_IMPORTED_MODULE_2__.allSettled)([
|
|
572
|
-
nextFlushPromise
|
|
573
|
-
]).then(()=>{
|
|
574
|
-
if (this.flushPromise === nextFlushPromise) this.flushPromise = null;
|
|
575
|
-
});
|
|
576
|
-
return nextFlushPromise;
|
|
577
|
-
}
|
|
578
|
-
getCustomHeaders() {
|
|
579
|
-
const customUserAgent = this.getCustomUserAgent();
|
|
580
|
-
const headers = {};
|
|
581
|
-
if (customUserAgent && '' !== customUserAgent) headers['User-Agent'] = customUserAgent;
|
|
582
|
-
return headers;
|
|
583
|
-
}
|
|
584
|
-
async _flush() {
|
|
585
|
-
this.clearFlushTimer();
|
|
586
|
-
await this._initPromise;
|
|
587
|
-
let queue = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue) || [];
|
|
588
|
-
if (!queue.length) return;
|
|
589
|
-
const sentMessages = [];
|
|
590
|
-
const originalQueueLength = queue.length;
|
|
591
|
-
while(queue.length > 0 && sentMessages.length < originalQueueLength){
|
|
592
|
-
const batchItems = queue.slice(0, this.maxBatchSize);
|
|
593
|
-
const batchMessages = batchItems.map((item)=>item.message);
|
|
594
|
-
const persistQueueChange = ()=>{
|
|
595
|
-
const refreshedQueue = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue) || [];
|
|
596
|
-
const newQueue = refreshedQueue.slice(batchItems.length);
|
|
597
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue, newQueue);
|
|
598
|
-
queue = newQueue;
|
|
599
|
-
};
|
|
600
|
-
const data = {
|
|
601
|
-
api_key: this.apiKey,
|
|
602
|
-
batch: batchMessages,
|
|
603
|
-
sent_at: (0, _utils__WEBPACK_IMPORTED_MODULE_2__.currentISOTime)()
|
|
604
|
-
};
|
|
605
|
-
if (this.historicalMigration) data.historical_migration = true;
|
|
606
|
-
const payload = JSON.stringify(data);
|
|
607
|
-
const url = `${this.host}/batch/`;
|
|
608
|
-
const gzippedPayload = this.disableCompression ? null : await (0, _gzip__WEBPACK_IMPORTED_MODULE_3__.gzipCompress)(payload, this.isDebug);
|
|
609
|
-
const fetchOptions = {
|
|
610
|
-
method: 'POST',
|
|
611
|
-
headers: {
|
|
612
|
-
...this.getCustomHeaders(),
|
|
613
|
-
'Content-Type': 'application/json',
|
|
614
|
-
...null !== gzippedPayload && {
|
|
615
|
-
'Content-Encoding': 'gzip'
|
|
616
|
-
}
|
|
617
|
-
},
|
|
618
|
-
body: gzippedPayload || payload
|
|
619
|
-
};
|
|
620
|
-
const retryOptions = {
|
|
621
|
-
retryCheck: (err)=>{
|
|
622
|
-
if (isPostHogFetchContentTooLargeError(err)) return false;
|
|
623
|
-
return isPostHogFetchError(err);
|
|
624
|
-
}
|
|
625
|
-
};
|
|
626
|
-
try {
|
|
627
|
-
await this.fetchWithRetry(url, fetchOptions, retryOptions);
|
|
628
|
-
} catch (err) {
|
|
629
|
-
if (isPostHogFetchContentTooLargeError(err) && batchMessages.length > 1) {
|
|
630
|
-
this.maxBatchSize = Math.max(1, Math.floor(batchMessages.length / 2));
|
|
631
|
-
this.logMsgIfDebug(()=>console.warn(`Received 413 when sending batch of size ${batchMessages.length}, reducing batch size to ${this.maxBatchSize}`));
|
|
632
|
-
continue;
|
|
633
|
-
}
|
|
634
|
-
if (!(err instanceof PostHogFetchNetworkError)) persistQueueChange();
|
|
635
|
-
this._events.emit('error', err);
|
|
636
|
-
throw err;
|
|
637
|
-
}
|
|
638
|
-
persistQueueChange();
|
|
639
|
-
sentMessages.push(...batchMessages);
|
|
640
|
-
}
|
|
641
|
-
this._events.emit('flush', sentMessages);
|
|
642
|
-
}
|
|
643
|
-
async fetchWithRetry(url, options, retryOptions, requestTimeout) {
|
|
644
|
-
var _AbortSignal;
|
|
645
|
-
null != (_AbortSignal = AbortSignal).timeout || (_AbortSignal.timeout = function(ms) {
|
|
646
|
-
const ctrl = new AbortController();
|
|
647
|
-
setTimeout(()=>ctrl.abort(), ms);
|
|
648
|
-
return ctrl.signal;
|
|
649
|
-
});
|
|
650
|
-
const body = options.body ? options.body : '';
|
|
651
|
-
let reqByteLength = -1;
|
|
652
|
-
try {
|
|
653
|
-
reqByteLength = body instanceof Blob ? body.size : Buffer.byteLength(body, _utils__WEBPACK_IMPORTED_MODULE_2__.STRING_FORMAT);
|
|
654
|
-
} catch (e) {
|
|
655
|
-
if (body instanceof Blob) reqByteLength = body.size;
|
|
656
|
-
else {
|
|
657
|
-
const encoded = new TextEncoder().encode(body);
|
|
658
|
-
reqByteLength = encoded.length;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
return await (0, _utils__WEBPACK_IMPORTED_MODULE_2__.retriable)(async ()=>{
|
|
662
|
-
let res = null;
|
|
663
|
-
try {
|
|
664
|
-
res = await this.fetch(url, {
|
|
665
|
-
signal: AbortSignal.timeout(null != requestTimeout ? requestTimeout : this.requestTimeout),
|
|
666
|
-
...options
|
|
667
|
-
});
|
|
668
|
-
} catch (e) {
|
|
669
|
-
throw new PostHogFetchNetworkError(e);
|
|
670
|
-
}
|
|
671
|
-
const isNoCors = 'no-cors' === options.mode;
|
|
672
|
-
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength);
|
|
673
|
-
return res;
|
|
674
|
-
}, {
|
|
675
|
-
...this._retryOptions,
|
|
676
|
-
...retryOptions
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
async _shutdown() {
|
|
680
|
-
let shutdownTimeoutMs = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 30000;
|
|
681
|
-
await this._initPromise;
|
|
682
|
-
let hasTimedOut = false;
|
|
683
|
-
this.clearFlushTimer();
|
|
684
|
-
const doShutdown = async ()=>{
|
|
685
|
-
try {
|
|
686
|
-
await this.promiseQueue.join();
|
|
687
|
-
while(true){
|
|
688
|
-
const queue = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue) || [];
|
|
689
|
-
if (0 === queue.length) break;
|
|
690
|
-
await this.flush();
|
|
691
|
-
if (hasTimedOut) break;
|
|
692
|
-
}
|
|
693
|
-
} catch (e) {
|
|
694
|
-
if (!isPostHogFetchError(e)) throw e;
|
|
695
|
-
await logFlushError(e);
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
return Promise.race([
|
|
699
|
-
new Promise((_, reject)=>{
|
|
700
|
-
(0, _utils__WEBPACK_IMPORTED_MODULE_2__.safeSetTimeout)(()=>{
|
|
701
|
-
this.logMsgIfDebug(()=>console.error('Timed out while shutting down PostHog'));
|
|
702
|
-
hasTimedOut = true;
|
|
703
|
-
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
704
|
-
}, shutdownTimeoutMs);
|
|
705
|
-
}),
|
|
706
|
-
doShutdown()
|
|
707
|
-
]);
|
|
708
|
-
}
|
|
709
|
-
async shutdown() {
|
|
710
|
-
let shutdownTimeoutMs = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 30000;
|
|
711
|
-
if (this.shutdownPromise) this.logMsgIfDebug(()=>console.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup'));
|
|
712
|
-
else this.shutdownPromise = this._shutdown(shutdownTimeoutMs).finally(()=>{
|
|
713
|
-
this.shutdownPromise = null;
|
|
714
|
-
});
|
|
715
|
-
return this.shutdownPromise;
|
|
716
|
-
}
|
|
717
|
-
constructor(apiKey, options){
|
|
718
|
-
this.flushPromise = null;
|
|
719
|
-
this.shutdownPromise = null;
|
|
720
|
-
this.promiseQueue = new _utils_promise_queue__WEBPACK_IMPORTED_MODULE_6__.PromiseQueue();
|
|
721
|
-
this._events = new _eventemitter__WEBPACK_IMPORTED_MODULE_4__.SimpleEventEmitter();
|
|
722
|
-
this._isInitialized = false;
|
|
723
|
-
(0, _utils__WEBPACK_IMPORTED_MODULE_2__.assert)(apiKey, "You must pass your PostHog project's api key.");
|
|
724
|
-
this.apiKey = apiKey;
|
|
725
|
-
this.host = (0, _utils__WEBPACK_IMPORTED_MODULE_2__.removeTrailingSlash)((null == options ? void 0 : options.host) || 'https://us.i.posthog.com');
|
|
726
|
-
this.flushAt = (null == options ? void 0 : options.flushAt) ? Math.max(null == options ? void 0 : options.flushAt, 1) : 20;
|
|
727
|
-
var _options_maxBatchSize;
|
|
728
|
-
this.maxBatchSize = Math.max(this.flushAt, null != (_options_maxBatchSize = null == options ? void 0 : options.maxBatchSize) ? _options_maxBatchSize : 100);
|
|
729
|
-
var _options_maxQueueSize;
|
|
730
|
-
this.maxQueueSize = Math.max(this.flushAt, null != (_options_maxQueueSize = null == options ? void 0 : options.maxQueueSize) ? _options_maxQueueSize : 1000);
|
|
731
|
-
var _options_flushInterval;
|
|
732
|
-
this.flushInterval = null != (_options_flushInterval = null == options ? void 0 : options.flushInterval) ? _options_flushInterval : 10000;
|
|
733
|
-
var _options_preloadFeatureFlags;
|
|
734
|
-
this.preloadFeatureFlags = null != (_options_preloadFeatureFlags = null == options ? void 0 : options.preloadFeatureFlags) ? _options_preloadFeatureFlags : true;
|
|
735
|
-
var _options_defaultOptIn;
|
|
736
|
-
this.defaultOptIn = null != (_options_defaultOptIn = null == options ? void 0 : options.defaultOptIn) ? _options_defaultOptIn : true;
|
|
737
|
-
var _options_disableSurveys;
|
|
738
|
-
this.disableSurveys = null != (_options_disableSurveys = null == options ? void 0 : options.disableSurveys) ? _options_disableSurveys : false;
|
|
739
|
-
var _options_fetchRetryCount, _options_fetchRetryDelay;
|
|
740
|
-
this._retryOptions = {
|
|
741
|
-
retryCount: null != (_options_fetchRetryCount = null == options ? void 0 : options.fetchRetryCount) ? _options_fetchRetryCount : 3,
|
|
742
|
-
retryDelay: null != (_options_fetchRetryDelay = null == options ? void 0 : options.fetchRetryDelay) ? _options_fetchRetryDelay : 3000,
|
|
743
|
-
retryCheck: isPostHogFetchError
|
|
744
|
-
};
|
|
745
|
-
var _options_requestTimeout;
|
|
746
|
-
this.requestTimeout = null != (_options_requestTimeout = null == options ? void 0 : options.requestTimeout) ? _options_requestTimeout : 10000;
|
|
747
|
-
var _options_featureFlagsRequestTimeoutMs;
|
|
748
|
-
this.featureFlagsRequestTimeoutMs = null != (_options_featureFlagsRequestTimeoutMs = null == options ? void 0 : options.featureFlagsRequestTimeoutMs) ? _options_featureFlagsRequestTimeoutMs : 3000;
|
|
749
|
-
var _options_remoteConfigRequestTimeoutMs;
|
|
750
|
-
this.remoteConfigRequestTimeoutMs = null != (_options_remoteConfigRequestTimeoutMs = null == options ? void 0 : options.remoteConfigRequestTimeoutMs) ? _options_remoteConfigRequestTimeoutMs : 3000;
|
|
751
|
-
var _options_disableGeoip;
|
|
752
|
-
this.disableGeoip = null != (_options_disableGeoip = null == options ? void 0 : options.disableGeoip) ? _options_disableGeoip : true;
|
|
753
|
-
var _options_disabled;
|
|
754
|
-
this.disabled = null != (_options_disabled = null == options ? void 0 : options.disabled) ? _options_disabled : false;
|
|
755
|
-
var _options_historicalMigration;
|
|
756
|
-
this.historicalMigration = null != (_options_historicalMigration = null == options ? void 0 : options.historicalMigration) ? _options_historicalMigration : false;
|
|
757
|
-
this._initPromise = Promise.resolve();
|
|
758
|
-
this._isInitialized = true;
|
|
759
|
-
var _options_disableCompression;
|
|
760
|
-
this.disableCompression = !(0, _gzip__WEBPACK_IMPORTED_MODULE_3__.isGzipSupported)() || (null != (_options_disableCompression = null == options ? void 0 : options.disableCompression) ? _options_disableCompression : false);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
class PostHogCore extends PostHogCoreStateless {
|
|
764
|
-
setupBootstrap(options) {
|
|
765
|
-
const bootstrap = null == options ? void 0 : options.bootstrap;
|
|
766
|
-
if (!bootstrap) return;
|
|
767
|
-
if (bootstrap.distinctId) if (bootstrap.isIdentifiedId) {
|
|
768
|
-
const distinctId = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.DistinctId);
|
|
769
|
-
if (!distinctId) this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.DistinctId, bootstrap.distinctId);
|
|
770
|
-
} else {
|
|
771
|
-
const anonymousId = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.AnonymousId);
|
|
772
|
-
if (!anonymousId) this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.AnonymousId, bootstrap.distinctId);
|
|
773
|
-
}
|
|
774
|
-
const bootstrapFeatureFlags = bootstrap.featureFlags;
|
|
775
|
-
var _bootstrap_featureFlagPayloads;
|
|
776
|
-
const bootstrapFeatureFlagPayloads = null != (_bootstrap_featureFlagPayloads = bootstrap.featureFlagPayloads) ? _bootstrap_featureFlagPayloads : {};
|
|
777
|
-
if (bootstrapFeatureFlags && Object.keys(bootstrapFeatureFlags).length) {
|
|
778
|
-
const normalizedBootstrapFeatureFlagDetails = (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.createFlagsResponseFromFlagsAndPayloads)(bootstrapFeatureFlags, bootstrapFeatureFlagPayloads);
|
|
779
|
-
if (Object.keys(normalizedBootstrapFeatureFlagDetails.flags).length > 0) {
|
|
780
|
-
this.setBootstrappedFeatureFlagDetails(normalizedBootstrapFeatureFlagDetails);
|
|
781
|
-
const currentFeatureFlagDetails = this.getKnownFeatureFlagDetails() || {
|
|
782
|
-
flags: {},
|
|
783
|
-
requestId: void 0
|
|
784
|
-
};
|
|
785
|
-
const newFeatureFlagDetails = {
|
|
786
|
-
flags: {
|
|
787
|
-
...normalizedBootstrapFeatureFlagDetails.flags,
|
|
788
|
-
...currentFeatureFlagDetails.flags
|
|
789
|
-
},
|
|
790
|
-
requestId: normalizedBootstrapFeatureFlagDetails.requestId
|
|
791
|
-
};
|
|
792
|
-
this.setKnownFeatureFlagDetails(newFeatureFlagDetails);
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
clearProps() {
|
|
797
|
-
this.props = void 0;
|
|
798
|
-
this.sessionProps = {};
|
|
799
|
-
this.flagCallReported = {};
|
|
800
|
-
}
|
|
801
|
-
on(event, cb) {
|
|
802
|
-
return this._events.on(event, cb);
|
|
803
|
-
}
|
|
804
|
-
reset(propertiesToKeep) {
|
|
805
|
-
this.wrap(()=>{
|
|
806
|
-
const allPropertiesToKeep = [
|
|
807
|
-
_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Queue,
|
|
808
|
-
...propertiesToKeep || []
|
|
809
|
-
];
|
|
810
|
-
this.clearProps();
|
|
811
|
-
for (const key of Object.keys(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty))if (!allPropertiesToKeep.includes(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty[key])) this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty[key], null);
|
|
812
|
-
this.reloadFeatureFlags();
|
|
813
|
-
});
|
|
814
|
-
}
|
|
815
|
-
getCommonEventProperties() {
|
|
816
|
-
const featureFlags = this.getFeatureFlags();
|
|
817
|
-
const featureVariantProperties = {};
|
|
818
|
-
if (featureFlags) for (const [feature, variant] of Object.entries(featureFlags))featureVariantProperties[`$feature/${feature}`] = variant;
|
|
819
|
-
return {
|
|
820
|
-
...maybeAdd('$active_feature_flags', featureFlags ? Object.keys(featureFlags) : void 0),
|
|
821
|
-
...featureVariantProperties,
|
|
822
|
-
...super.getCommonEventProperties()
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
enrichProperties(properties) {
|
|
826
|
-
return {
|
|
827
|
-
...this.props,
|
|
828
|
-
...this.sessionProps,
|
|
829
|
-
...properties || {},
|
|
830
|
-
...this.getCommonEventProperties(),
|
|
831
|
-
$session_id: this.getSessionId()
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
getSessionId() {
|
|
835
|
-
if (!this._isInitialized) return '';
|
|
836
|
-
let sessionId = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionId);
|
|
837
|
-
const sessionLastTimestamp = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionLastTimestamp) || 0;
|
|
838
|
-
const sessionStartTimestamp = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionStartTimestamp) || 0;
|
|
839
|
-
const now = Date.now();
|
|
840
|
-
const sessionLastDif = now - sessionLastTimestamp;
|
|
841
|
-
const sessionStartDif = now - sessionStartTimestamp;
|
|
842
|
-
if (!sessionId || sessionLastDif > 1000 * this._sessionExpirationTimeSeconds || sessionStartDif > 1000 * this._sessionMaxLengthSeconds) {
|
|
843
|
-
sessionId = (0, _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_5__.uuidv7)();
|
|
844
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionId, sessionId);
|
|
845
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionStartTimestamp, now);
|
|
846
|
-
}
|
|
847
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionLastTimestamp, now);
|
|
848
|
-
return sessionId;
|
|
849
|
-
}
|
|
850
|
-
resetSessionId() {
|
|
851
|
-
this.wrap(()=>{
|
|
852
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionId, null);
|
|
853
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionLastTimestamp, null);
|
|
854
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionStartTimestamp, null);
|
|
855
|
-
});
|
|
856
|
-
}
|
|
857
|
-
getAnonymousId() {
|
|
858
|
-
if (!this._isInitialized) return '';
|
|
859
|
-
let anonId = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.AnonymousId);
|
|
860
|
-
if (!anonId) {
|
|
861
|
-
anonId = (0, _vendor_uuidv7__WEBPACK_IMPORTED_MODULE_5__.uuidv7)();
|
|
862
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.AnonymousId, anonId);
|
|
863
|
-
}
|
|
864
|
-
return anonId;
|
|
865
|
-
}
|
|
866
|
-
getDistinctId() {
|
|
867
|
-
if (!this._isInitialized) return '';
|
|
868
|
-
return this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.DistinctId) || this.getAnonymousId();
|
|
869
|
-
}
|
|
870
|
-
registerForSession(properties) {
|
|
871
|
-
this.sessionProps = {
|
|
872
|
-
...this.sessionProps,
|
|
873
|
-
...properties
|
|
874
|
-
};
|
|
875
|
-
}
|
|
876
|
-
unregisterForSession(property) {
|
|
877
|
-
delete this.sessionProps[property];
|
|
878
|
-
}
|
|
879
|
-
identify(distinctId, properties, options) {
|
|
880
|
-
this.wrap(()=>{
|
|
881
|
-
const previousDistinctId = this.getDistinctId();
|
|
882
|
-
distinctId = distinctId || previousDistinctId;
|
|
883
|
-
if (null == properties ? void 0 : properties.$groups) this.groups(properties.$groups);
|
|
884
|
-
const userPropsOnce = null == properties ? void 0 : properties.$set_once;
|
|
885
|
-
null == properties || delete properties.$set_once;
|
|
886
|
-
const userProps = (null == properties ? void 0 : properties.$set) || properties;
|
|
887
|
-
const allProperties = this.enrichProperties({
|
|
888
|
-
$anon_distinct_id: this.getAnonymousId(),
|
|
889
|
-
...maybeAdd('$set', userProps),
|
|
890
|
-
...maybeAdd('$set_once', userPropsOnce)
|
|
891
|
-
});
|
|
892
|
-
if (distinctId !== previousDistinctId) {
|
|
893
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.AnonymousId, previousDistinctId);
|
|
894
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.DistinctId, distinctId);
|
|
895
|
-
this.reloadFeatureFlags();
|
|
896
|
-
}
|
|
897
|
-
super.identifyStateless(distinctId, allProperties, options);
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
capture(event, properties, options) {
|
|
901
|
-
this.wrap(()=>{
|
|
902
|
-
const distinctId = this.getDistinctId();
|
|
903
|
-
if (null == properties ? void 0 : properties.$groups) this.groups(properties.$groups);
|
|
904
|
-
const allProperties = this.enrichProperties(properties);
|
|
905
|
-
super.captureStateless(distinctId, event, allProperties, options);
|
|
906
|
-
});
|
|
907
|
-
}
|
|
908
|
-
alias(alias) {
|
|
909
|
-
this.wrap(()=>{
|
|
910
|
-
const distinctId = this.getDistinctId();
|
|
911
|
-
const allProperties = this.enrichProperties({});
|
|
912
|
-
super.aliasStateless(alias, distinctId, allProperties);
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
autocapture(eventType, elements) {
|
|
916
|
-
let properties = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, options = arguments.length > 3 ? arguments[3] : void 0;
|
|
917
|
-
this.wrap(()=>{
|
|
918
|
-
const distinctId = this.getDistinctId();
|
|
919
|
-
const payload = {
|
|
920
|
-
distinct_id: distinctId,
|
|
921
|
-
event: '$autocapture',
|
|
922
|
-
properties: {
|
|
923
|
-
...this.enrichProperties(properties),
|
|
924
|
-
$event_type: eventType,
|
|
925
|
-
$elements: elements
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
this.enqueue('autocapture', payload, options);
|
|
929
|
-
});
|
|
930
|
-
}
|
|
931
|
-
groups(groups) {
|
|
932
|
-
this.wrap(()=>{
|
|
933
|
-
const existingGroups = this.props.$groups || {};
|
|
934
|
-
this.register({
|
|
935
|
-
$groups: {
|
|
936
|
-
...existingGroups,
|
|
937
|
-
...groups
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
if (Object.keys(groups).find((type)=>existingGroups[type] !== groups[type])) this.reloadFeatureFlags();
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
group(groupType, groupKey, groupProperties, options) {
|
|
944
|
-
this.wrap(()=>{
|
|
945
|
-
this.groups({
|
|
946
|
-
[groupType]: groupKey
|
|
947
|
-
});
|
|
948
|
-
if (groupProperties) this.groupIdentify(groupType, groupKey, groupProperties, options);
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
groupIdentify(groupType, groupKey, groupProperties, options) {
|
|
952
|
-
this.wrap(()=>{
|
|
953
|
-
const distinctId = this.getDistinctId();
|
|
954
|
-
const eventProperties = this.enrichProperties({});
|
|
955
|
-
super.groupIdentifyStateless(groupType, groupKey, groupProperties, options, distinctId, eventProperties);
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
setPersonPropertiesForFlags(properties) {
|
|
959
|
-
this.wrap(()=>{
|
|
960
|
-
const existingProperties = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.PersonProperties) || {};
|
|
961
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.PersonProperties, {
|
|
962
|
-
...existingProperties,
|
|
963
|
-
...properties
|
|
964
|
-
});
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
resetPersonPropertiesForFlags() {
|
|
968
|
-
this.wrap(()=>{
|
|
969
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.PersonProperties, null);
|
|
970
|
-
});
|
|
971
|
-
}
|
|
972
|
-
setGroupPropertiesForFlags(properties) {
|
|
973
|
-
this.wrap(()=>{
|
|
974
|
-
const existingProperties = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.GroupProperties) || {};
|
|
975
|
-
if (0 !== Object.keys(existingProperties).length) Object.keys(existingProperties).forEach((groupType)=>{
|
|
976
|
-
existingProperties[groupType] = {
|
|
977
|
-
...existingProperties[groupType],
|
|
978
|
-
...properties[groupType]
|
|
979
|
-
};
|
|
980
|
-
delete properties[groupType];
|
|
981
|
-
});
|
|
982
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.GroupProperties, {
|
|
983
|
-
...existingProperties,
|
|
984
|
-
...properties
|
|
985
|
-
});
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
resetGroupPropertiesForFlags() {
|
|
989
|
-
this.wrap(()=>{
|
|
990
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.GroupProperties, null);
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
async remoteConfigAsync() {
|
|
994
|
-
await this._initPromise;
|
|
995
|
-
if (this._remoteConfigResponsePromise) return this._remoteConfigResponsePromise;
|
|
996
|
-
return this._remoteConfigAsync();
|
|
997
|
-
}
|
|
998
|
-
async flagsAsync() {
|
|
999
|
-
let sendAnonDistinctId = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : true;
|
|
1000
|
-
await this._initPromise;
|
|
1001
|
-
if (this._flagsResponsePromise) return this._flagsResponsePromise;
|
|
1002
|
-
return this._flagsAsync(sendAnonDistinctId);
|
|
1003
|
-
}
|
|
1004
|
-
cacheSessionReplay(source, response) {
|
|
1005
|
-
const sessionReplay = null == response ? void 0 : response.sessionRecording;
|
|
1006
|
-
if (sessionReplay) {
|
|
1007
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionReplay, sessionReplay);
|
|
1008
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', `Session replay config from ${source}: `, JSON.stringify(sessionReplay)));
|
|
1009
|
-
} else if ('boolean' == typeof sessionReplay && false === sessionReplay) {
|
|
1010
|
-
this.logMsgIfDebug(()=>console.info('PostHog Debug', `Session replay config from ${source} disabled.`));
|
|
1011
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.SessionReplay, null);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
async _remoteConfigAsync() {
|
|
1015
|
-
this._remoteConfigResponsePromise = this._initPromise.then(()=>{
|
|
1016
|
-
let remoteConfig = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.RemoteConfig);
|
|
1017
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Cached remote config: ', JSON.stringify(remoteConfig)));
|
|
1018
|
-
return super.getRemoteConfig().then((response)=>{
|
|
1019
|
-
if (response) {
|
|
1020
|
-
var _response_supportedCompression;
|
|
1021
|
-
const remoteConfigWithoutSurveys = {
|
|
1022
|
-
...response
|
|
1023
|
-
};
|
|
1024
|
-
delete remoteConfigWithoutSurveys.surveys;
|
|
1025
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Fetched remote config: ', JSON.stringify(remoteConfigWithoutSurveys)));
|
|
1026
|
-
if (false === this.disableSurveys) {
|
|
1027
|
-
const surveys = response.surveys;
|
|
1028
|
-
let hasSurveys = true;
|
|
1029
|
-
if (Array.isArray(surveys)) this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Surveys fetched from remote config: ', JSON.stringify(surveys)));
|
|
1030
|
-
else {
|
|
1031
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', 'There are no surveys.'));
|
|
1032
|
-
hasSurveys = false;
|
|
1033
|
-
}
|
|
1034
|
-
if (hasSurveys) this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Surveys, surveys);
|
|
1035
|
-
else this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Surveys, null);
|
|
1036
|
-
} else this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.Surveys, null);
|
|
1037
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.RemoteConfig, remoteConfigWithoutSurveys);
|
|
1038
|
-
this.cacheSessionReplay('remote config', response);
|
|
1039
|
-
if (false === response.hasFeatureFlags) {
|
|
1040
|
-
this.setKnownFeatureFlagDetails({
|
|
1041
|
-
flags: {}
|
|
1042
|
-
});
|
|
1043
|
-
this.logMsgIfDebug(()=>console.warn('Remote config has no feature flags, will not load feature flags.'));
|
|
1044
|
-
} else if (false !== this.preloadFeatureFlags) this.reloadFeatureFlags();
|
|
1045
|
-
if (!(null == (_response_supportedCompression = response.supportedCompression) ? void 0 : _response_supportedCompression.includes(_types__WEBPACK_IMPORTED_MODULE_0__.Compression.GZipJS))) this.disableCompression = true;
|
|
1046
|
-
remoteConfig = response;
|
|
1047
|
-
}
|
|
1048
|
-
return remoteConfig;
|
|
1049
|
-
});
|
|
1050
|
-
}).finally(()=>{
|
|
1051
|
-
this._remoteConfigResponsePromise = void 0;
|
|
1052
|
-
});
|
|
1053
|
-
return this._remoteConfigResponsePromise;
|
|
1054
|
-
}
|
|
1055
|
-
async _flagsAsync() {
|
|
1056
|
-
let sendAnonDistinctId = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : true;
|
|
1057
|
-
this._flagsResponsePromise = this._initPromise.then(async ()=>{
|
|
1058
|
-
var _res_quotaLimited;
|
|
1059
|
-
const distinctId = this.getDistinctId();
|
|
1060
|
-
const groups = this.props.$groups || {};
|
|
1061
|
-
const personProperties = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.PersonProperties) || {};
|
|
1062
|
-
const groupProperties = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.GroupProperties) || {};
|
|
1063
|
-
const extraProperties = {
|
|
1064
|
-
$anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : void 0
|
|
1065
|
-
};
|
|
1066
|
-
const res = await super.getFlags(distinctId, groups, personProperties, groupProperties, extraProperties);
|
|
1067
|
-
if (null == res ? void 0 : null == (_res_quotaLimited = res.quotaLimited) ? void 0 : _res_quotaLimited.includes("feature_flags")) {
|
|
1068
|
-
this.setKnownFeatureFlagDetails(null);
|
|
1069
|
-
console.warn('[FEATURE FLAGS] Feature flags quota limit exceeded - unsetting all flags. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
1070
|
-
return res;
|
|
1071
|
-
}
|
|
1072
|
-
if (null == res ? void 0 : res.featureFlags) {
|
|
1073
|
-
if (this.sendFeatureFlagEvent) this.flagCallReported = {};
|
|
1074
|
-
let newFeatureFlagDetails = res;
|
|
1075
|
-
if (res.errorsWhileComputingFlags) {
|
|
1076
|
-
const currentFlagDetails = this.getKnownFeatureFlagDetails();
|
|
1077
|
-
this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlagDetails)));
|
|
1078
|
-
newFeatureFlagDetails = {
|
|
1079
|
-
...res,
|
|
1080
|
-
flags: {
|
|
1081
|
-
...null == currentFlagDetails ? void 0 : currentFlagDetails.flags,
|
|
1082
|
-
...res.flags
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
this.setKnownFeatureFlagDetails(newFeatureFlagDetails);
|
|
1087
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.FlagsEndpointWasHit, true);
|
|
1088
|
-
this.cacheSessionReplay('flags', res);
|
|
1089
|
-
}
|
|
1090
|
-
return res;
|
|
1091
|
-
}).finally(()=>{
|
|
1092
|
-
this._flagsResponsePromise = void 0;
|
|
1093
|
-
});
|
|
1094
|
-
return this._flagsResponsePromise;
|
|
1095
|
-
}
|
|
1096
|
-
setKnownFeatureFlagDetails(flagsResponse) {
|
|
1097
|
-
this.wrap(()=>{
|
|
1098
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.FeatureFlagDetails, flagsResponse);
|
|
1099
|
-
var _flagsResponse_flags;
|
|
1100
|
-
this._events.emit('featureflags', (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getFlagValuesFromFlags)(null != (_flagsResponse_flags = null == flagsResponse ? void 0 : flagsResponse.flags) ? _flagsResponse_flags : {}));
|
|
1101
|
-
});
|
|
1102
|
-
}
|
|
1103
|
-
getKnownFeatureFlagDetails() {
|
|
1104
|
-
const storedDetails = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.FeatureFlagDetails);
|
|
1105
|
-
if (!storedDetails) {
|
|
1106
|
-
const featureFlags = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.FeatureFlags);
|
|
1107
|
-
const featureFlagPayloads = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.FeatureFlagPayloads);
|
|
1108
|
-
if (void 0 === featureFlags && void 0 === featureFlagPayloads) return;
|
|
1109
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.createFlagsResponseFromFlagsAndPayloads)(null != featureFlags ? featureFlags : {}, null != featureFlagPayloads ? featureFlagPayloads : {});
|
|
1110
|
-
}
|
|
1111
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.normalizeFlagsResponse)(storedDetails);
|
|
1112
|
-
}
|
|
1113
|
-
getKnownFeatureFlags() {
|
|
1114
|
-
const featureFlagDetails = this.getKnownFeatureFlagDetails();
|
|
1115
|
-
if (!featureFlagDetails) return;
|
|
1116
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getFlagValuesFromFlags)(featureFlagDetails.flags);
|
|
1117
|
-
}
|
|
1118
|
-
getKnownFeatureFlagPayloads() {
|
|
1119
|
-
const featureFlagDetails = this.getKnownFeatureFlagDetails();
|
|
1120
|
-
if (!featureFlagDetails) return;
|
|
1121
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getPayloadsFromFlags)(featureFlagDetails.flags);
|
|
1122
|
-
}
|
|
1123
|
-
getBootstrappedFeatureFlagDetails() {
|
|
1124
|
-
const details = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.BootstrapFeatureFlagDetails);
|
|
1125
|
-
if (!details) return;
|
|
1126
|
-
return details;
|
|
1127
|
-
}
|
|
1128
|
-
setBootstrappedFeatureFlagDetails(details) {
|
|
1129
|
-
this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.BootstrapFeatureFlagDetails, details);
|
|
1130
|
-
}
|
|
1131
|
-
getBootstrappedFeatureFlags() {
|
|
1132
|
-
const details = this.getBootstrappedFeatureFlagDetails();
|
|
1133
|
-
if (!details) return;
|
|
1134
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getFlagValuesFromFlags)(details.flags);
|
|
1135
|
-
}
|
|
1136
|
-
getBootstrappedFeatureFlagPayloads() {
|
|
1137
|
-
const details = this.getBootstrappedFeatureFlagDetails();
|
|
1138
|
-
if (!details) return;
|
|
1139
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getPayloadsFromFlags)(details.flags);
|
|
1140
|
-
}
|
|
1141
|
-
getFeatureFlag(key) {
|
|
1142
|
-
const details = this.getFeatureFlagDetails();
|
|
1143
|
-
if (!details) return;
|
|
1144
|
-
const featureFlag = details.flags[key];
|
|
1145
|
-
let response = (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.getFeatureFlagValue)(featureFlag);
|
|
1146
|
-
if (void 0 === response) response = false;
|
|
1147
|
-
if (this.sendFeatureFlagEvent && !this.flagCallReported[key]) {
|
|
1148
|
-
var _this_getBootstrappedFeatureFlags, _this_getBootstrappedFeatureFlagPayloads, _featureFlag_metadata, _featureFlag_metadata1, _featureFlag_reason, _featureFlag_reason1;
|
|
1149
|
-
const bootstrappedResponse = null == (_this_getBootstrappedFeatureFlags = this.getBootstrappedFeatureFlags()) ? void 0 : _this_getBootstrappedFeatureFlags[key];
|
|
1150
|
-
const bootstrappedPayload = null == (_this_getBootstrappedFeatureFlagPayloads = this.getBootstrappedFeatureFlagPayloads()) ? void 0 : _this_getBootstrappedFeatureFlagPayloads[key];
|
|
1151
|
-
this.flagCallReported[key] = true;
|
|
1152
|
-
var _featureFlag_reason_description;
|
|
1153
|
-
this.capture('$feature_flag_called', {
|
|
1154
|
-
$feature_flag: key,
|
|
1155
|
-
$feature_flag_response: response,
|
|
1156
|
-
...maybeAdd('$feature_flag_id', null == featureFlag ? void 0 : null == (_featureFlag_metadata = featureFlag.metadata) ? void 0 : _featureFlag_metadata.id),
|
|
1157
|
-
...maybeAdd('$feature_flag_version', null == featureFlag ? void 0 : null == (_featureFlag_metadata1 = featureFlag.metadata) ? void 0 : _featureFlag_metadata1.version),
|
|
1158
|
-
...maybeAdd('$feature_flag_reason', null != (_featureFlag_reason_description = null == featureFlag ? void 0 : null == (_featureFlag_reason = featureFlag.reason) ? void 0 : _featureFlag_reason.description) ? _featureFlag_reason_description : null == featureFlag ? void 0 : null == (_featureFlag_reason1 = featureFlag.reason) ? void 0 : _featureFlag_reason1.code),
|
|
1159
|
-
...maybeAdd('$feature_flag_bootstrapped_response', bootstrappedResponse),
|
|
1160
|
-
...maybeAdd('$feature_flag_bootstrapped_payload', bootstrappedPayload),
|
|
1161
|
-
$used_bootstrap_value: !this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.FlagsEndpointWasHit),
|
|
1162
|
-
...maybeAdd('$feature_flag_request_id', details.requestId)
|
|
1163
|
-
});
|
|
1164
|
-
}
|
|
1165
|
-
return response;
|
|
1166
|
-
}
|
|
1167
|
-
getFeatureFlagPayload(key) {
|
|
1168
|
-
const payloads = this.getFeatureFlagPayloads();
|
|
1169
|
-
if (!payloads) return;
|
|
1170
|
-
const response = payloads[key];
|
|
1171
|
-
if (void 0 === response) return null;
|
|
1172
|
-
return response;
|
|
1173
|
-
}
|
|
1174
|
-
getFeatureFlagPayloads() {
|
|
1175
|
-
var _this_getFeatureFlagDetails;
|
|
1176
|
-
return null == (_this_getFeatureFlagDetails = this.getFeatureFlagDetails()) ? void 0 : _this_getFeatureFlagDetails.featureFlagPayloads;
|
|
1177
|
-
}
|
|
1178
|
-
getFeatureFlags() {
|
|
1179
|
-
var _this_getFeatureFlagDetails;
|
|
1180
|
-
return null == (_this_getFeatureFlagDetails = this.getFeatureFlagDetails()) ? void 0 : _this_getFeatureFlagDetails.featureFlags;
|
|
1181
|
-
}
|
|
1182
|
-
getFeatureFlagDetails() {
|
|
1183
|
-
let details = this.getKnownFeatureFlagDetails();
|
|
1184
|
-
const overriddenFlags = this.getPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.OverrideFeatureFlags);
|
|
1185
|
-
if (!overriddenFlags) return details;
|
|
1186
|
-
details = null != details ? details : {
|
|
1187
|
-
featureFlags: {},
|
|
1188
|
-
featureFlagPayloads: {},
|
|
1189
|
-
flags: {}
|
|
1190
|
-
};
|
|
1191
|
-
var _details_flags;
|
|
1192
|
-
const flags = null != (_details_flags = details.flags) ? _details_flags : {};
|
|
1193
|
-
for(const key in overriddenFlags)if (overriddenFlags[key]) flags[key] = (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.updateFlagValue)(flags[key], overriddenFlags[key]);
|
|
1194
|
-
else delete flags[key];
|
|
1195
|
-
const result = {
|
|
1196
|
-
...details,
|
|
1197
|
-
flags
|
|
1198
|
-
};
|
|
1199
|
-
return (0, _featureFlagUtils__WEBPACK_IMPORTED_MODULE_1__.normalizeFlagsResponse)(result);
|
|
1200
|
-
}
|
|
1201
|
-
getFeatureFlagsAndPayloads() {
|
|
1202
|
-
const flags = this.getFeatureFlags();
|
|
1203
|
-
const payloads = this.getFeatureFlagPayloads();
|
|
1204
|
-
return {
|
|
1205
|
-
flags,
|
|
1206
|
-
payloads
|
|
1207
|
-
};
|
|
1208
|
-
}
|
|
1209
|
-
isFeatureEnabled(key) {
|
|
1210
|
-
const response = this.getFeatureFlag(key);
|
|
1211
|
-
if (void 0 === response) return;
|
|
1212
|
-
return !!response;
|
|
1213
|
-
}
|
|
1214
|
-
reloadFeatureFlags(options) {
|
|
1215
|
-
this.flagsAsync(true).then((res)=>{
|
|
1216
|
-
var _options_cb;
|
|
1217
|
-
null == options || null == (_options_cb = options.cb) || _options_cb.call(options, void 0, null == res ? void 0 : res.featureFlags);
|
|
1218
|
-
}).catch((e)=>{
|
|
1219
|
-
var _options_cb;
|
|
1220
|
-
null == options || null == (_options_cb = options.cb) || _options_cb.call(options, e, void 0);
|
|
1221
|
-
if (!(null == options ? void 0 : options.cb)) this.logMsgIfDebug(()=>console.log('PostHog Debug', 'Error reloading feature flags', e));
|
|
1222
|
-
});
|
|
1223
|
-
}
|
|
1224
|
-
async reloadRemoteConfigAsync() {
|
|
1225
|
-
return await this.remoteConfigAsync();
|
|
1226
|
-
}
|
|
1227
|
-
async reloadFeatureFlagsAsync(sendAnonDistinctId) {
|
|
1228
|
-
var _this;
|
|
1229
|
-
return null == (_this = await this.flagsAsync(null != sendAnonDistinctId ? sendAnonDistinctId : true)) ? void 0 : _this.featureFlags;
|
|
1230
|
-
}
|
|
1231
|
-
onFeatureFlags(cb) {
|
|
1232
|
-
return this.on('featureflags', async ()=>{
|
|
1233
|
-
const flags = this.getFeatureFlags();
|
|
1234
|
-
if (flags) cb(flags);
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
onFeatureFlag(key, cb) {
|
|
1238
|
-
return this.on('featureflags', async ()=>{
|
|
1239
|
-
const flagResponse = this.getFeatureFlag(key);
|
|
1240
|
-
if (void 0 !== flagResponse) cb(flagResponse);
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
async overrideFeatureFlag(flags) {
|
|
1244
|
-
this.wrap(()=>{
|
|
1245
|
-
if (null === flags) return this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.OverrideFeatureFlags, null);
|
|
1246
|
-
return this.setPersistedProperty(_types__WEBPACK_IMPORTED_MODULE_0__.PostHogPersistedProperty.OverrideFeatureFlags, flags);
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
captureException(error, additionalProperties) {
|
|
1250
|
-
const properties = {
|
|
1251
|
-
$exception_level: 'error',
|
|
1252
|
-
$exception_list: [
|
|
1253
|
-
{
|
|
1254
|
-
type: (0, _utils__WEBPACK_IMPORTED_MODULE_2__.isPlainError)(error) ? error.name : 'Error',
|
|
1255
|
-
value: (0, _utils__WEBPACK_IMPORTED_MODULE_2__.isPlainError)(error) ? error.message : error,
|
|
1256
|
-
mechanism: {
|
|
1257
|
-
handled: true,
|
|
1258
|
-
synthetic: false
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
],
|
|
1262
|
-
...additionalProperties
|
|
1263
|
-
};
|
|
1264
|
-
properties.$exception_personURL = new URL(`/project/${this.apiKey}/person/${this.getDistinctId()}`, this.host).toString();
|
|
1265
|
-
this.capture('$exception', properties);
|
|
1266
|
-
}
|
|
1267
|
-
captureTraceFeedback(traceId, userFeedback) {
|
|
1268
|
-
this.capture('$ai_feedback', {
|
|
1269
|
-
$ai_feedback_text: userFeedback,
|
|
1270
|
-
$ai_trace_id: String(traceId)
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
captureTraceMetric(traceId, metricName, metricValue) {
|
|
1274
|
-
this.capture('$ai_metric', {
|
|
1275
|
-
$ai_metric_name: metricName,
|
|
1276
|
-
$ai_metric_value: String(metricValue),
|
|
1277
|
-
$ai_trace_id: String(traceId)
|
|
1278
|
-
});
|
|
1279
|
-
}
|
|
1280
|
-
constructor(apiKey, options){
|
|
1281
|
-
var _options_disableGeoip;
|
|
1282
|
-
const disableGeoipOption = null != (_options_disableGeoip = null == options ? void 0 : options.disableGeoip) ? _options_disableGeoip : false;
|
|
1283
|
-
var _options_featureFlagsRequestTimeoutMs;
|
|
1284
|
-
const featureFlagsRequestTimeoutMs = null != (_options_featureFlagsRequestTimeoutMs = null == options ? void 0 : options.featureFlagsRequestTimeoutMs) ? _options_featureFlagsRequestTimeoutMs : 10000;
|
|
1285
|
-
super(apiKey, {
|
|
1286
|
-
...options,
|
|
1287
|
-
disableGeoip: disableGeoipOption,
|
|
1288
|
-
featureFlagsRequestTimeoutMs
|
|
1289
|
-
}), this.flagCallReported = {}, this._sessionMaxLengthSeconds = 86400, this.sessionProps = {};
|
|
1290
|
-
var _options_sendFeatureFlagEvent;
|
|
1291
|
-
this.sendFeatureFlagEvent = null != (_options_sendFeatureFlagEvent = null == options ? void 0 : options.sendFeatureFlagEvent) ? _options_sendFeatureFlagEvent : true;
|
|
1292
|
-
var _options_sessionExpirationTimeSeconds;
|
|
1293
|
-
this._sessionExpirationTimeSeconds = null != (_options_sessionExpirationTimeSeconds = null == options ? void 0 : options.sessionExpirationTimeSeconds) ? _options_sessionExpirationTimeSeconds : 1800;
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
129
|
})();
|
|
1297
130
|
exports.ErrorTracking = __webpack_exports__.ErrorTracking;
|
|
1298
|
-
exports.PostHogCore = __webpack_exports__.PostHogCore;
|
|
1299
|
-
exports.PostHogCoreStateless = __webpack_exports__.PostHogCoreStateless;
|
|
1300
131
|
exports.getFeatureFlagValue = __webpack_exports__.getFeatureFlagValue;
|
|
1301
|
-
exports.
|
|
1302
|
-
exports.
|
|
132
|
+
exports.testing = __webpack_exports__.testing;
|
|
133
|
+
exports.uuidv7 = __webpack_exports__.uuidv7;
|
|
1303
134
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
1304
135
|
"ErrorTracking",
|
|
1305
|
-
"PostHogCore",
|
|
1306
|
-
"PostHogCoreStateless",
|
|
1307
136
|
"getFeatureFlagValue",
|
|
1308
|
-
"
|
|
1309
|
-
"
|
|
137
|
+
"testing",
|
|
138
|
+
"uuidv7"
|
|
1310
139
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
1311
140
|
Object.defineProperty(exports, '__esModule', {
|
|
1312
141
|
value: true
|