@posthog/core 1.69.9 → 1.71.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.
Files changed (122) hide show
  1. package/capture-v1/package.json +6 -0
  2. package/dist/capture-v1/compression.d.ts +18 -0
  3. package/dist/capture-v1/compression.d.ts.map +1 -0
  4. package/dist/capture-v1/compression.js +70 -0
  5. package/dist/capture-v1/compression.mjs +26 -0
  6. package/dist/capture-v1/errors.d.ts +48 -0
  7. package/dist/capture-v1/errors.d.ts.map +1 -0
  8. package/dist/capture-v1/errors.js +82 -0
  9. package/dist/capture-v1/errors.mjs +38 -0
  10. package/dist/capture-v1/index.d.ts +15 -0
  11. package/dist/capture-v1/index.d.ts.map +1 -0
  12. package/dist/capture-v1/index.js +88 -0
  13. package/dist/capture-v1/index.mjs +7 -0
  14. package/dist/capture-v1/sender.d.ts +150 -0
  15. package/dist/capture-v1/sender.d.ts.map +1 -0
  16. package/dist/capture-v1/sender.js +554 -0
  17. package/dist/capture-v1/sender.mjs +507 -0
  18. package/dist/capture-v1/serialize.d.ts +30 -0
  19. package/dist/capture-v1/serialize.d.ts.map +1 -0
  20. package/dist/capture-v1/serialize.js +106 -0
  21. package/dist/capture-v1/serialize.mjs +59 -0
  22. package/dist/capture-v1/transform.d.ts +19 -0
  23. package/dist/capture-v1/transform.d.ts.map +1 -0
  24. package/dist/capture-v1/transform.js +118 -0
  25. package/dist/capture-v1/transform.mjs +77 -0
  26. package/dist/capture-v1/types.d.ts +52 -0
  27. package/dist/capture-v1/types.d.ts.map +1 -0
  28. package/dist/capture-v1/types.js +44 -0
  29. package/dist/capture-v1/types.mjs +3 -0
  30. package/dist/capture-v1/uuid.d.ts +9 -0
  31. package/dist/capture-v1/uuid.d.ts.map +1 -0
  32. package/dist/capture-v1/uuid.js +75 -0
  33. package/dist/capture-v1/uuid.mjs +34 -0
  34. package/dist/featureFlagLocalEvaluation.d.ts +2 -0
  35. package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
  36. package/dist/featureFlagLocalEvaluation.js +38 -0
  37. package/dist/featureFlagLocalEvaluation.mjs +38 -0
  38. package/dist/featureFlagUtils.d.ts +7 -5
  39. package/dist/featureFlagUtils.d.ts.map +1 -1
  40. package/dist/featureFlagUtils.js +17 -11
  41. package/dist/featureFlagUtils.mjs +14 -11
  42. package/dist/index.d.ts +1 -1
  43. package/dist/index.d.ts.map +1 -1
  44. package/dist/index.js +27 -16
  45. package/dist/index.mjs +1 -1
  46. package/dist/posthog-core-stateless.d.ts +44 -7
  47. package/dist/posthog-core-stateless.d.ts.map +1 -1
  48. package/dist/posthog-core-stateless.js +103 -24
  49. package/dist/posthog-core-stateless.mjs +103 -24
  50. package/dist/posthog-core.d.ts +138 -53
  51. package/dist/posthog-core.d.ts.map +1 -1
  52. package/dist/posthog-core.js +341 -115
  53. package/dist/posthog-core.mjs +338 -115
  54. package/dist/types.d.ts +33 -1
  55. package/dist/types.d.ts.map +1 -1
  56. package/dist/utils/index.d.ts +1 -1
  57. package/dist/utils/index.d.ts.map +1 -1
  58. package/dist/utils/index.js +25 -12
  59. package/dist/utils/index.mjs +1 -1
  60. package/dist/utils/json-utils.d.ts +11 -1
  61. package/dist/utils/json-utils.d.ts.map +1 -1
  62. package/dist/utils/json-utils.js +50 -2
  63. package/dist/utils/json-utils.mjs +46 -1
  64. package/package.json +13 -3
  65. package/src/capture-v1/compression.ts +50 -0
  66. package/src/capture-v1/errors.ts +91 -0
  67. package/src/capture-v1/index.ts +34 -0
  68. package/src/capture-v1/sender.ts +779 -0
  69. package/src/capture-v1/serialize.ts +113 -0
  70. package/src/capture-v1/transform.ts +135 -0
  71. package/src/capture-v1/types.ts +59 -0
  72. package/src/capture-v1/uuid.ts +53 -0
  73. package/src/featureFlagLocalEvaluation.ts +51 -0
  74. package/src/featureFlagUtils.ts +22 -10
  75. package/src/index.ts +1 -0
  76. package/src/posthog-core-stateless.ts +190 -35
  77. package/src/posthog-core.ts +615 -178
  78. package/src/types.ts +31 -1
  79. package/src/utils/index.ts +1 -1
  80. package/src/utils/json-utils.ts +64 -1
  81. package/src/error-tracking/chunk-ids.spec.ts +0 -77
  82. package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
  83. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
  84. package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
  85. package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
  86. package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
  87. package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
  88. package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
  89. package/src/error-tracking/exception-steps.spec.ts +0 -115
  90. package/src/error-tracking/parsers/base.spec.ts +0 -156
  91. package/src/error-tracking/parsers/index.spec.ts +0 -270
  92. package/src/error-tracking/parsers/node.spec.ts +0 -34
  93. package/src/error-tracking/release.spec.ts +0 -34
  94. package/src/logs/index.spec.ts +0 -2421
  95. package/src/logs/logs-utils.spec.ts +0 -266
  96. package/src/metrics/index.spec.ts +0 -1249
  97. package/src/surveys/activation.spec.ts +0 -61
  98. package/src/surveys/events.spec.ts +0 -183
  99. package/src/surveys/keys.spec.ts +0 -29
  100. package/src/surveys/property-matching.spec.ts +0 -539
  101. package/src/surveys/shuffling.spec.ts +0 -51
  102. package/src/surveys/translations.spec.ts +0 -274
  103. package/src/surveys/validation.spec.ts +0 -168
  104. package/src/traces/config.spec.ts +0 -271
  105. package/src/traces/ids.spec.ts +0 -115
  106. package/src/traces/index.spec.ts +0 -3287
  107. package/src/traces/live-spans.spec.ts +0 -69
  108. package/src/traces/otlp.spec.ts +0 -368
  109. package/src/traces/span.spec.ts +0 -1137
  110. package/src/traces/traceparent.spec.ts +0 -184
  111. package/src/utils/bot-detection.spec.ts +0 -107
  112. package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
  113. package/src/utils/json-utils.spec.ts +0 -115
  114. package/src/utils/named-error.spec.ts +0 -36
  115. package/src/utils/number-utils.spec.ts +0 -212
  116. package/src/utils/otlp-any-value.spec.ts +0 -376
  117. package/src/utils/otlp-resource.spec.ts +0 -171
  118. package/src/utils/promise-queue.spec.ts +0 -55
  119. package/src/utils/string-utils.spec.ts +0 -158
  120. package/src/utils/type-utils.spec.ts +0 -38
  121. package/src/utils/webview-app-utils.spec.ts +0 -118
  122. package/src/vendor/uuidv7.spec.ts +0 -26
@@ -28,15 +28,57 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
- PostHogCore: ()=>PostHogCore
31
+ PostHogCore: ()=>PostHogCore,
32
+ PostHogCoreBase: ()=>PostHogCoreBase
32
33
  });
33
34
  const external_featureFlagUtils_js_namespaceObject = require("./featureFlagUtils.js");
34
35
  const external_types_js_namespaceObject = require("./types.js");
35
36
  const external_posthog_core_stateless_js_namespaceObject = require("./posthog-core-stateless.js");
36
37
  const uuidv7_js_namespaceObject = require("./vendor/uuidv7.js");
37
38
  const index_js_namespaceObject = require("./utils/index.js");
39
+ const resolveSendFeatureFlagEvent = (options)=>options?.sendFeatureFlagEvent ?? options?.sendEvent;
40
+ const holdsNoCachedFlags = (storedDetails)=>{
41
+ if (void 0 !== storedDetails.noFlagsCached) return storedDetails.noFlagsCached;
42
+ const failedOrQuotaLimited = void 0 !== storedDetails.requestError || storedDetails.quotaLimited?.includes(external_posthog_core_stateless_js_namespaceObject.QuotaLimitedFeature.FeatureFlags) === true;
43
+ return failedOrQuotaLimited && void 0 === storedDetails.minimalFlagCalledEvents && 0 === Object.keys(storedDetails.flags ?? {}).length;
44
+ };
45
+ const eventOptionsOf = (options)=>{
46
+ const eventOptions = options?.options;
47
+ return (0, index_js_namespaceObject.isObject)(eventOptions) ? eventOptions : void 0;
48
+ };
49
+ const IDENTITY_EVENTS = [
50
+ '$identify',
51
+ '$create_alias',
52
+ '$merge_dangerously',
53
+ '$groupidentify',
54
+ '$set',
55
+ '$set_once'
56
+ ];
57
+ const isFilledString = (value)=>'string' == typeof value && value.length > 0;
58
+ function fillLibraryIdentity(properties, lib, libVersion) {
59
+ if (isFilledString(properties.$lib)) {
60
+ if (properties.$lib === lib && !isFilledString(properties.$lib_version)) properties.$lib_version = libVersion;
61
+ } else {
62
+ properties.$lib = lib;
63
+ properties.$lib_version = libVersion;
64
+ }
65
+ }
66
+ function personPropertiesHashOrNull(distinctId, userPropertiesToSet, userPropertiesToSetOnce) {
67
+ try {
68
+ return (0, index_js_namespaceObject.getPersonPropertiesHash)(distinctId, userPropertiesToSet, userPropertiesToSetOnce);
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+ function sentPersonPropertiesHash(message) {
74
+ const properties = (0, index_js_namespaceObject.isObject)(message.properties) ? message.properties : {};
75
+ const set = properties.$set;
76
+ const setOnce = properties.$set_once;
77
+ if (!(0, index_js_namespaceObject.isNullish)(set) && !(0, index_js_namespaceObject.isObject)(set) || !(0, index_js_namespaceObject.isNullish)(setOnce) && !(0, index_js_namespaceObject.isObject)(setOnce)) return null;
78
+ return personPropertiesHashOrNull(String(message.distinct_id), set, setOnce);
79
+ }
38
80
  const SESSION_ACTIVITY_PERSIST_GRANULARITY_MS = 5000;
39
- class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.PostHogCoreStateless {
81
+ class PostHogCoreBase extends external_posthog_core_stateless_js_namespaceObject.PostHogCoreStateless {
40
82
  constructor(projectToken, options){
41
83
  const disableGeoipOption = options?.disableGeoip ?? false;
42
84
  const featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 10000;
@@ -44,7 +86,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
44
86
  ...options,
45
87
  disableGeoip: disableGeoipOption,
46
88
  featureFlagsRequestTimeoutMs
47
- }), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._cachedPersonProperties = null;
89
+ }), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._flagsResetCount = 0, this._cachedPersonProperties = null, this._pendingPersonPropertiesHash = void 0;
48
90
  this.sendFeatureFlagEvent = options?.sendFeatureFlagEvent ?? true;
49
91
  this.disableRemoteFeatureFlags = options?.disableRemoteFeatureFlags ?? false;
50
92
  this._sessionExpirationTimeSeconds = options?.sessionExpirationTimeSeconds ?? 1800;
@@ -67,7 +109,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
67
109
  const bootstrapFeatureFlags = bootstrap.featureFlags;
68
110
  const bootstrapFeatureFlagPayloads = bootstrap.featureFlagPayloads ?? {};
69
111
  if (bootstrapFeatureFlags && Object.keys(bootstrapFeatureFlags).length) {
70
- const normalizedBootstrapFeatureFlagDetails = (0, external_featureFlagUtils_js_namespaceObject.createFlagsResponseFromFlagsAndPayloads)(bootstrapFeatureFlags, bootstrapFeatureFlagPayloads);
112
+ const normalizedBootstrapFeatureFlagDetails = (0, external_featureFlagUtils_js_namespaceObject.createFlagsResponseFromFlagsAndPayloads)(bootstrapFeatureFlags, bootstrapFeatureFlagPayloads, this.usesLegacyFlagValues() ? external_featureFlagUtils_js_namespaceObject.parsePayload : (payload)=>payload);
71
113
  if (Object.keys(normalizedBootstrapFeatureFlagDetails.flags).length > 0) {
72
114
  this.setBootstrappedFeatureFlagDetails(normalizedBootstrapFeatureFlagDetails);
73
115
  const currentFeatureFlagDetails = this.getKnownFeatureFlagDetails() || {
@@ -77,6 +119,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
77
119
  const newFeatureFlagDetails = {
78
120
  ...this.getStoredFlagDetails(),
79
121
  requestError: void 0,
122
+ noFlagsCached: void 0,
80
123
  flags: {
81
124
  ...normalizedBootstrapFeatureFlagDetails.flags,
82
125
  ...Object.fromEntries(Object.entries(currentFeatureFlagDetails.flags).filter(([key, detail])=>!detail.failed || !Object.prototype.hasOwnProperty.call(normalizedBootstrapFeatureFlagDetails.flags, key)))
@@ -111,6 +154,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
111
154
  }
112
155
  reset(propertiesToKeep) {
113
156
  this.wrap(()=>{
157
+ this._flagsResetCount++;
114
158
  const allPropertiesToKeep = [
115
159
  external_types_js_namespaceObject.PostHogPersistedProperty.Queue,
116
160
  external_types_js_namespaceObject.PostHogPersistedProperty.AiQueue,
@@ -135,31 +179,110 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
135
179
  this.flagCallReported = {};
136
180
  }
137
181
  }
182
+ usesLegacyFlagValues() {
183
+ return false;
184
+ }
185
+ isFlagValueEnabled(value) {
186
+ return this.usesLegacyFlagValues() ? (0, external_featureFlagUtils_js_namespaceObject.getEnabledFromValue)(value) : (0, external_featureFlagUtils_js_namespaceObject.isEnabledFlagValue)(value);
187
+ }
138
188
  getCommonEventProperties() {
139
- const featureFlags = this.getFeatureFlags();
189
+ const featureFlags = this.getFeatureFlagValues();
140
190
  const featureVariantProperties = {};
141
191
  if (featureFlags) for (const [feature, variant] of Object.entries(featureFlags))featureVariantProperties[`$feature/${feature}`] = variant;
142
192
  return {
143
- ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$active_feature_flags', featureFlags ? Object.keys(featureFlags) : void 0),
193
+ ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$active_feature_flags', featureFlags ? Object.keys(featureFlags).filter((key)=>this.usesLegacyFlagValues() || (0, external_featureFlagUtils_js_namespaceObject.isEnabledFlagValue)(featureFlags[key])) : void 0),
144
194
  ...featureVariantProperties,
145
195
  ...super.getCommonEventProperties()
146
196
  };
147
197
  }
148
- enrichProperties(properties) {
198
+ enrichProperties(properties, options) {
149
199
  const userProperties = properties || {};
150
- return {
200
+ if (this.usesLegacyEventPropertyOrder()) return {
151
201
  ...this.props,
152
202
  ...this.sessionProps,
153
203
  ...this.getCommonEventProperties(),
154
204
  ...userProperties,
155
205
  $session_id: this.getSessionId()
156
206
  };
207
+ const { $lib, $lib_version, ...sdkProperties } = this.getCommonEventProperties();
208
+ const callerSessionId = userProperties.$session_id;
209
+ const sessionId = isFilledString(callerSessionId) && callerSessionId.trim() ? void 0 : this.getSessionId();
210
+ const registered = {
211
+ ...sdkProperties,
212
+ ...this.props,
213
+ ...this.sessionProps,
214
+ ...options?.disableGeoip != null && {
215
+ $geoip_disable: options.disableGeoip
216
+ }
217
+ };
218
+ const enriched = {
219
+ ...registered,
220
+ ...userProperties
221
+ };
222
+ if ((0, index_js_namespaceObject.isObject)(registered.$groups) && (0, index_js_namespaceObject.isObject)(userProperties.$groups)) enriched.$groups = {
223
+ ...registered.$groups,
224
+ ...userProperties.$groups
225
+ };
226
+ if (!isFilledString(enriched.$session_id) || !enriched.$session_id.trim()) enriched.$session_id = sessionId ?? this.getSessionId();
227
+ fillLibraryIdentity(enriched, $lib, $lib_version);
228
+ return enriched;
229
+ }
230
+ usesLegacyEventPropertyOrder() {
231
+ return false;
232
+ }
233
+ usesLegacyEventPersonState() {
234
+ return false;
235
+ }
236
+ stampPersonState(properties, options) {
237
+ const hasPersonProcessing = this._hasPersonProcessing();
238
+ let stampedOptions = options;
239
+ if (this.usesLegacyEventPersonState()) properties['$process_person_profile'] = hasPersonProcessing;
240
+ else if (null == properties['$process_person_profile']) {
241
+ delete properties['$process_person_profile'];
242
+ const eventOptions = eventOptionsOf(options);
243
+ if (!hasPersonProcessing && eventOptions?.process_person_profile == null) {
244
+ const personless = {
245
+ ...options,
246
+ options: {
247
+ ...eventOptions,
248
+ process_person_profile: false
249
+ }
250
+ };
251
+ stampedOptions = personless;
252
+ }
253
+ }
254
+ if (this.usesLegacyEventPersonState() || !Object.prototype.hasOwnProperty.call(properties, '$is_identified')) properties['$is_identified'] = this._isIdentified();
255
+ if (hasPersonProcessing) this._requirePersonProcessing('capture');
256
+ return stampedOptions;
257
+ }
258
+ prepareMessage(message, options) {
259
+ const eventGeoipDisable = message?.properties?.['$geoip_disable'];
260
+ const geoipDisable = this.usesLegacyEventPropertyOrder() ? void 0 : null != eventGeoipDisable ? eventGeoipDisable : options?.disableGeoip;
261
+ const prepared = super.prepareMessage(message, options);
262
+ if (null != geoipDisable) prepared.properties['$geoip_disable'] = geoipDisable;
263
+ const eventOptions = eventOptionsOf(options);
264
+ if (eventOptions) prepared.options = {
265
+ ...eventOptions
266
+ };
267
+ return prepared;
268
+ }
269
+ enrichIdentityProperties(properties, options) {
270
+ const enriched = this.enrichProperties(properties, options);
271
+ if (!this.usesLegacyEventPersonState()) delete enriched['$process_person_profile'];
272
+ return enriched;
157
273
  }
158
274
  mergeCommonEventProperties(properties) {
159
- return {
275
+ if (this.usesLegacyEventPropertyOrder()) return {
160
276
  ...this.getCommonEventProperties(),
161
277
  ...properties
162
278
  };
279
+ const { $lib, $lib_version, ...sdkProperties } = this.getCommonEventProperties();
280
+ const merged = {
281
+ ...sdkProperties,
282
+ ...properties
283
+ };
284
+ fillLibraryIdentity(merged, $lib, $lib_version);
285
+ return merged;
163
286
  }
164
287
  getSessionId() {
165
288
  if (!this._isInitialized) return '';
@@ -220,21 +343,26 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
220
343
  unregisterForSession(property) {
221
344
  delete this.sessionProps[property];
222
345
  }
346
+ isIgnoredIdentifyId(distinctId) {
347
+ if ('string' != typeof distinctId || '' !== distinctId.trim()) return false;
348
+ return '' !== distinctId || !this.usesLegacyEventPersonState();
349
+ }
223
350
  identify(distinctId, properties, options) {
224
351
  this.wrap(()=>{
352
+ if (this.isIgnoredIdentifyId(distinctId)) return void this._logger.warn('identify() was called with an empty or whitespace-only distinct id, so it is ignored.');
225
353
  if (!this._requirePersonProcessing('posthog.identify')) return;
226
354
  const previousDistinctId = this.getDistinctId();
227
355
  const idWasSupplied = !!distinctId;
228
356
  distinctId = distinctId || previousDistinctId;
229
- if (properties?.$groups) this.groups(properties.$groups);
357
+ if (this.usesLegacyEventPropertyOrder() && properties?.$groups) this.groups(properties.$groups);
230
358
  const userPropsOnce = properties?.$set_once;
231
359
  delete properties?.$set_once;
232
360
  const userProps = properties?.$set || properties;
233
- const allProperties = this.enrichProperties({
361
+ const allProperties = this.enrichIdentityProperties({
234
362
  $anon_distinct_id: this.getAnonymousId(),
235
363
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$set', userProps),
236
364
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$set_once', userPropsOnce)
237
- });
365
+ }, options);
238
366
  const userPropsObj = (0, index_js_namespaceObject.isObject)(userProps) ? userProps : void 0;
239
367
  const userPropsOnceObj = (0, index_js_namespaceObject.isObject)(userPropsOnce) ? userPropsOnce : void 0;
240
368
  const identityChanged = distinctId !== previousDistinctId;
@@ -245,8 +373,8 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
245
373
  this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.DistinctId, distinctId);
246
374
  this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.PersonMode, 'identified');
247
375
  this.reloadFeatureFlags();
248
- super.identifyStateless(distinctId, allProperties, options);
249
- this._cachedPersonProperties = (0, index_js_namespaceObject.getPersonPropertiesHash)(distinctId, userPropsObj, userPropsOnceObj);
376
+ const newDistinctId = distinctId;
377
+ this._captureWithPersonPropertiesHash(this._surelyProcessesPerson(options) ? personPropertiesHashOrNull(newDistinctId, userPropsObj, userPropsOnceObj) : null, ()=>super.identifyStateless(newDistinctId, allProperties, options));
250
378
  } else if (shouldTransitionToIdentified) {
251
379
  this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.PersonMode, 'identified');
252
380
  const setProps = userPropsObj || {};
@@ -255,49 +383,48 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
255
383
  $set: setProps,
256
384
  $set_once: setOnceProps
257
385
  }, false);
258
- this.capture('$set', {
259
- $set: setProps,
260
- $set_once: setOnceProps
261
- });
262
- this._cachedPersonProperties = (0, index_js_namespaceObject.getPersonPropertiesHash)(distinctId, userPropsObj, userPropsOnceObj);
386
+ this._captureWithPersonPropertiesHash(this._surelyProcessesPerson(options) ? personPropertiesHashOrNull(distinctId, userPropsObj, userPropsOnceObj) : null, ()=>this.capture('$set', {
387
+ $set: setProps,
388
+ $set_once: setOnceProps
389
+ }, options));
263
390
  if (userPropsObj || userPropsOnceObj) this.reloadFeatureFlags();
264
- } else if (userPropsObj || userPropsOnceObj) this.setPersonProperties(userPropsObj, userPropsOnceObj);
391
+ } else if (userPropsObj || userPropsOnceObj) this.setPersonProperties(userPropsObj, userPropsOnceObj, true, options);
265
392
  });
266
393
  }
267
394
  capture(event, properties, options) {
268
395
  if ('$exception' === event && !options?._originatedFromCaptureException) this._logger.warn("Using `posthog.capture('$exception')` is unreliable because it does not attach required metadata. Use `posthog.captureException(error)` instead, which attaches required metadata automatically.");
269
396
  this.wrap(()=>{
270
397
  const distinctId = this.getDistinctId();
271
- if (properties?.$groups) this.groups(properties.$groups);
272
- const allProperties = this.enrichProperties(properties);
273
- const hasPersonProcessing = this._hasPersonProcessing();
274
- allProperties['$process_person_profile'] = hasPersonProcessing;
275
- allProperties['$is_identified'] = this._isIdentified();
276
- if (hasPersonProcessing) this._requirePersonProcessing('capture');
277
- super.captureStateless(distinctId, event, allProperties, options);
398
+ if (this.usesLegacyEventPropertyOrder() && properties?.$groups) this.groups(properties.$groups);
399
+ const allProperties = this.enrichProperties(properties, options);
400
+ if (!this.usesLegacyEventPersonState() && IDENTITY_EVENTS.includes(event) && properties?.['$process_person_profile'] == null) delete allProperties['$process_person_profile'];
401
+ const stampedOptions = this.stampPersonState(allProperties, options);
402
+ super.captureStateless(distinctId, event, allProperties, stampedOptions);
278
403
  });
279
404
  }
280
- alias(alias) {
405
+ alias(alias, options) {
281
406
  this.wrap(()=>{
282
407
  if (!this._requirePersonProcessing('posthog.alias')) return;
283
408
  const distinctId = this.getDistinctId();
284
- const allProperties = this.enrichProperties({});
285
- super.aliasStateless(alias, distinctId, allProperties);
409
+ const allProperties = this.enrichIdentityProperties({}, options);
410
+ super.aliasStateless(alias, distinctId, allProperties, options);
286
411
  });
287
412
  }
288
413
  autocapture(eventType, elements, properties = {}, options) {
289
414
  this.wrap(()=>{
290
415
  const distinctId = this.getDistinctId();
416
+ const autocaptureProperties = {
417
+ ...this.enrichProperties(properties, options),
418
+ $event_type: eventType,
419
+ $elements: elements
420
+ };
421
+ const stampedOptions = this.usesLegacyEventPersonState() ? options : this.stampPersonState(autocaptureProperties, options);
291
422
  const payload = {
292
423
  distinct_id: distinctId,
293
424
  event: '$autocapture',
294
- properties: {
295
- ...this.enrichProperties(properties),
296
- $event_type: eventType,
297
- $elements: elements
298
- }
425
+ properties: autocaptureProperties
299
426
  };
300
- this.enqueue('autocapture', payload, options);
427
+ this.enqueue('autocapture', payload, stampedOptions);
301
428
  });
302
429
  }
303
430
  groups(groups) {
@@ -327,7 +454,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
327
454
  this.wrap(()=>{
328
455
  if (!this._requirePersonProcessing('posthog.groupIdentify')) return;
329
456
  const distinctId = this.getDistinctId();
330
- const eventProperties = this.enrichProperties({});
457
+ const eventProperties = this.enrichIdentityProperties({}, options);
331
458
  super.groupIdentifyStateless(groupType, groupKey, groupProperties, options, distinctId, eventProperties);
332
459
  });
333
460
  }
@@ -501,6 +628,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
501
628
  });
502
629
  return this._remoteConfigResponsePromise;
503
630
  }
631
+ getFlagsRequestTimezone() {}
504
632
  getFlagsForContext(...args) {
505
633
  return super.getFlags(...args);
506
634
  }
@@ -509,6 +637,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
509
637
  const fetchConfig = options?.fetchConfig ?? false;
510
638
  const triggerOnRemoteConfig = options?.triggerOnRemoteConfig ?? false;
511
639
  this._flagsResponsePromise = this._initPromise.then(async ()=>{
640
+ const resetCount = this._flagsResetCount;
512
641
  const distinctId = this.getDistinctId();
513
642
  const groups = this.props.$groups || {};
514
643
  const personProperties = this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.PersonProperties) || {};
@@ -517,37 +646,47 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
517
646
  const extraProperties = {
518
647
  $anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : void 0,
519
648
  $device_id: deviceId ?? void 0,
649
+ ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('timezone', this.getFlagsRequestTimezone()),
520
650
  ...this.disableRemoteFeatureFlags ? {
521
651
  disable_flags: true
522
652
  } : {}
523
653
  };
524
654
  const result = await this.getFlagsForContext(distinctId, groups, personProperties, groupProperties, extraProperties, fetchConfig);
525
655
  if (void 0 === result) return;
656
+ const isForPreviousIdentity = resetCount !== this._flagsResetCount;
526
657
  if (!result.success) {
527
- if (!this.disableRemoteFeatureFlags) this.setKnownFeatureFlagDetails({
528
- flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
529
- requestError: result.error,
530
- minimalFlagCalledEvents: this.getStoredFlagDetails()?.minimalFlagCalledEvents
531
- });
658
+ if (!this.disableRemoteFeatureFlags && !isForPreviousIdentity) {
659
+ const storedDetails = this.getStoredFlagDetails();
660
+ this.setKnownFeatureFlagDetails({
661
+ flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
662
+ requestError: result.error,
663
+ minimalFlagCalledEvents: storedDetails?.minimalFlagCalledEvents,
664
+ noFlagsCached: !storedDetails || holdsNoCachedFlags(storedDetails)
665
+ });
666
+ }
532
667
  return;
533
668
  }
534
669
  const res = result.response;
535
670
  if (res?.quotaLimited?.includes(external_posthog_core_stateless_js_namespaceObject.QuotaLimitedFeature.FeatureFlags)) {
536
- if (!this.disableRemoteFeatureFlags) this.setKnownFeatureFlagDetails({
537
- flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
538
- quotaLimited: res.quotaLimited,
539
- minimalFlagCalledEvents: this.getStoredFlagDetails()?.minimalFlagCalledEvents
540
- });
671
+ if (!this.disableRemoteFeatureFlags && !isForPreviousIdentity) {
672
+ const storedDetails = this.getStoredFlagDetails();
673
+ this.setKnownFeatureFlagDetails({
674
+ flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
675
+ quotaLimited: res.quotaLimited,
676
+ minimalFlagCalledEvents: storedDetails?.minimalFlagCalledEvents,
677
+ noFlagsCached: !storedDetails || holdsNoCachedFlags(storedDetails)
678
+ });
679
+ }
541
680
  this._logger.warn('[FEATURE FLAGS] Feature flags quota limit exceeded. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
542
681
  this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
543
682
  return res;
544
683
  }
545
684
  if (res?.featureFlags) {
546
- if (this.disableRemoteFeatureFlags) {
685
+ if (this.disableRemoteFeatureFlags || isForPreviousIdentity) {
547
686
  this.cacheSessionReplay('flags', res);
548
687
  this.syncRemoteConfigSessionRecording(res);
549
688
  this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
550
- return res;
689
+ return isForPreviousIdentity ? void 0 : res;
551
690
  }
552
691
  let newFeatureFlagDetails = res;
553
692
  if (res.errorsWhileComputingFlags) {
@@ -606,11 +745,14 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
606
745
  if (void 0 === featureFlags && void 0 === featureFlagPayloads) return;
607
746
  return (0, external_featureFlagUtils_js_namespaceObject.createFlagsResponseFromFlagsAndPayloads)(featureFlags ?? {}, featureFlagPayloads ?? {});
608
747
  }
609
- return (0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(storedDetails);
748
+ return (0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(storedDetails, (payload)=>this.decodeFeatureFlagPayload(payload));
610
749
  }
611
750
  getStoredFlagDetails() {
612
751
  return this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.FeatureFlagDetails);
613
752
  }
753
+ didLatestFeatureFlagsLoadFail() {
754
+ return this.getStoredFlagDetails()?.requestError !== void 0;
755
+ }
614
756
  isMinimalFlagCalledEventsEnabled() {
615
757
  return this.getStoredFlagDetails()?.minimalFlagCalledEvents === true;
616
758
  }
@@ -635,13 +777,27 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
635
777
  getBootstrappedFeatureFlagPayloads() {
636
778
  const details = this.getBootstrappedFeatureFlagDetails();
637
779
  if (!details) return;
638
- return (0, external_featureFlagUtils_js_namespaceObject.getPayloadsFromFlags)(details.flags);
780
+ return (0, external_featureFlagUtils_js_namespaceObject.getPayloadsFromFlags)(details.flags, (payload)=>this.decodeFeatureFlagPayload(payload));
639
781
  }
640
782
  getFeatureFlagResult(key, options) {
641
- return this._getFeatureFlagResult(key, options);
783
+ return this._getFeatureFlagResult(key, {
784
+ sendEvent: resolveSendFeatureFlagEvent(options)
785
+ });
786
+ }
787
+ decodeFeatureFlagPayload(payload) {
788
+ return (0, external_featureFlagUtils_js_namespaceObject.parsePayload)(payload);
789
+ }
790
+ getFlagsResponseFormat() {
791
+ return {
792
+ version: super.getFlagsResponseFormat().version,
793
+ read: (body)=>(0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(body, (payload)=>this.decodeFeatureFlagPayload(payload))
794
+ };
642
795
  }
643
796
  getAllFeatureFlags() {
644
- return (0, external_featureFlagUtils_js_namespaceObject.flagDetailsToResults)(this.getFeatureFlagDetails()?.flags ?? {});
797
+ const flags = this.getFeatureFlagDetails()?.flags;
798
+ const storedDetails = this.getStoredFlagDetails();
799
+ if (!flags || storedDetails && holdsNoCachedFlags(storedDetails)) return;
800
+ return (0, external_featureFlagUtils_js_namespaceObject.flagDetailsToResults)(flags, (payload)=>this.decodeFeatureFlagPayload(payload), (value)=>this.isFlagValueEnabled(value));
645
801
  }
646
802
  _getFeatureFlagResult(key, options = {}) {
647
803
  const storedDetails = this.getStoredFlagDetails();
@@ -679,7 +835,9 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
679
835
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$feature_flag_reason', featureFlag?.reason?.description ?? featureFlag?.reason?.code),
680
836
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$feature_flag_bootstrapped_response', bootstrappedResponse),
681
837
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$feature_flag_bootstrapped_payload', bootstrappedPayload),
682
- $used_bootstrap_value: !this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.FlagsEndpointWasHit),
838
+ ...this.usesLegacyFlagValues() || void 0 !== bootstrappedResponse ? {
839
+ $used_bootstrap_value: !this.getPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.FlagsEndpointWasHit)
840
+ } : {},
683
841
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$feature_flag_request_id', details?.requestId),
684
842
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$feature_flag_evaluated_at', details?.evaluatedAt),
685
843
  ...(0, external_posthog_core_stateless_js_namespaceObject.maybeAdd)('$feature_flag_error', featureFlagError),
@@ -704,32 +862,21 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
704
862
  return;
705
863
  }
706
864
  const rawPayload = featureFlag?.metadata?.payload;
707
- const payload = void 0 !== rawPayload ? (0, external_featureFlagUtils_js_namespaceObject.parsePayload)(rawPayload) : null;
865
+ const payload = void 0 !== rawPayload ? this.decodeFeatureFlagPayload(rawPayload) : null;
708
866
  return {
709
867
  key,
710
- enabled: (0, external_featureFlagUtils_js_namespaceObject.getEnabledFromValue)(flagValue),
868
+ enabled: this.isFlagValueEnabled(flagValue),
711
869
  variant: (0, external_featureFlagUtils_js_namespaceObject.getVariantFromValue)(flagValue),
712
870
  payload
713
871
  };
714
872
  }
715
873
  getFeatureFlag(key, options) {
716
874
  const result = this._getFeatureFlagResult(key, {
717
- missingFlagBehavior: 'getFeatureFlag',
718
- sendEvent: options?.sendEvent
875
+ sendEvent: resolveSendFeatureFlagEvent(options)
719
876
  });
720
877
  return result?.variant ?? result?.enabled;
721
878
  }
722
- getFeatureFlagPayload(key) {
723
- const result = this._getFeatureFlagResult(key, {
724
- missingFlagBehavior: 'getFeatureFlagPayload',
725
- sendEvent: false
726
- });
727
- return result?.payload;
728
- }
729
- getFeatureFlagPayloads() {
730
- return this.getFeatureFlagDetails()?.featureFlagPayloads;
731
- }
732
- getFeatureFlags() {
879
+ getFeatureFlagValues() {
733
880
  return this.getFeatureFlagDetails()?.featureFlags;
734
881
  }
735
882
  getFeatureFlagDetails() {
@@ -744,21 +891,16 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
744
891
  const flags = {
745
892
  ...details.flags ?? {}
746
893
  };
747
- for(const key in overriddenFlags)if (overriddenFlags[key]) flags[key] = (0, external_featureFlagUtils_js_namespaceObject.updateFlagValue)(flags[key], overriddenFlags[key]);
894
+ for(const key in overriddenFlags)if (overriddenFlags[key]) flags[key] = {
895
+ ...(0, external_featureFlagUtils_js_namespaceObject.updateFlagValue)(flags[key], overriddenFlags[key]),
896
+ key
897
+ };
748
898
  else delete flags[key];
749
899
  const result = {
750
900
  ...details,
751
901
  flags
752
902
  };
753
- return (0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(result);
754
- }
755
- getFeatureFlagsAndPayloads() {
756
- const flags = this.getFeatureFlags();
757
- const payloads = this.getFeatureFlagPayloads();
758
- return {
759
- flags,
760
- payloads
761
- };
903
+ return (0, external_featureFlagUtils_js_namespaceObject.normalizeFlagsResponse)(result, (payload)=>this.decodeFeatureFlagPayload(payload));
762
904
  }
763
905
  isFeatureEnabled(key, options) {
764
906
  if (options?.defaultValue === void 0) {
@@ -766,13 +908,13 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
766
908
  return void 0 === response ? void 0 : !!response;
767
909
  }
768
910
  const result = this._getFeatureFlagResult(key, {
769
- sendEvent: options.sendEvent
911
+ sendEvent: resolveSendFeatureFlagEvent(options)
770
912
  });
771
913
  const value = result?.variant ?? result?.enabled;
772
914
  return void 0 === value ? options.defaultValue : !!value;
773
915
  }
774
916
  reloadFeatureFlags(options) {
775
- if (this.disableRemoteFeatureFlags && !this.disabled) return void this._initPromise.then(()=>options?.cb?.(void 0, this.getFeatureFlags()));
917
+ if (this.disableRemoteFeatureFlags && !this.disabled) return void this._initPromise.then(()=>options?.cb?.(void 0, this.getFeatureFlagValues()));
776
918
  this.flagsAsync({
777
919
  sendAnonDistinctId: true
778
920
  }).then((res)=>{
@@ -785,33 +927,15 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
785
927
  async reloadRemoteConfigAsync() {
786
928
  return await this.remoteConfigAsync();
787
929
  }
788
- async reloadFeatureFlagsAsync(sendAnonDistinctId) {
930
+ async loadFeatureFlagsAsync(sendAnonDistinctId) {
789
931
  if (this.disableRemoteFeatureFlags && !this.disabled) {
790
932
  await this._initPromise;
791
- return this.getFeatureFlags();
933
+ return this.getFeatureFlagValues();
792
934
  }
793
935
  return (await this.flagsAsync({
794
936
  sendAnonDistinctId: sendAnonDistinctId
795
937
  }))?.featureFlags;
796
938
  }
797
- onFeatureFlags(cb) {
798
- return this.on('featureflags', async ()=>{
799
- const flags = this.getFeatureFlags();
800
- if (flags) cb(flags);
801
- });
802
- }
803
- onFeatureFlag(key, cb) {
804
- return this.on('featureflags', async ()=>{
805
- const flagResponse = this.getFeatureFlag(key);
806
- if (void 0 !== flagResponse) cb(flagResponse);
807
- });
808
- }
809
- async overrideFeatureFlag(flags) {
810
- this.wrap(()=>{
811
- if (null === flags) return this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.OverrideFeatureFlags, null);
812
- return this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.OverrideFeatureFlags, flags);
813
- });
814
- }
815
939
  updateFlags(flags, payloads, options) {
816
940
  this.wrap(()=>{
817
941
  const existingDetails = options?.merge ? this.getKnownFeatureFlagDetails()?.flags : void 0;
@@ -819,7 +943,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
819
943
  const existingPayloads = {};
820
944
  for(const key in existingDetails){
821
945
  const storedPayload = existingDetails[key].metadata?.payload;
822
- if (!existingDetails[key].failed && void 0 !== storedPayload) existingPayloads[key] = (0, external_featureFlagUtils_js_namespaceObject.parsePayload)(storedPayload);
946
+ if (!existingDetails[key].failed && void 0 !== storedPayload) existingPayloads[key] = this.decodeFeatureFlagPayload(storedPayload);
823
947
  }
824
948
  const finalFlags = {
825
949
  ...existingFlags,
@@ -919,26 +1043,46 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
919
1043
  $set_once: {}
920
1044
  });
921
1045
  }
922
- setPersonProperties(userPropertiesToSet, userPropertiesToSetOnce, reloadFeatureFlags = true) {
1046
+ setPersonProperties(userPropertiesToSet, userPropertiesToSetOnce, reloadFeatureFlags = true, options) {
923
1047
  this.wrap(()=>{
924
1048
  const isSetEmpty = (0, index_js_namespaceObject.isNullish)(userPropertiesToSet) || (0, index_js_namespaceObject.isEmptyObject)(userPropertiesToSet);
925
1049
  const isSetOnceEmpty = (0, index_js_namespaceObject.isNullish)(userPropertiesToSetOnce) || (0, index_js_namespaceObject.isEmptyObject)(userPropertiesToSetOnce);
926
1050
  if (isSetEmpty && isSetOnceEmpty) return;
927
1051
  if (!this._requirePersonProcessing('posthog.setPersonProperties')) return;
928
- const hash = (0, index_js_namespaceObject.getPersonPropertiesHash)(this.getDistinctId(), userPropertiesToSet, userPropertiesToSetOnce);
929
- if (this._cachedPersonProperties === hash) return void this._logger.info('A duplicate setPersonProperties call was made with the same properties. It has been ignored.');
1052
+ const hash = personPropertiesHashOrNull(this.getDistinctId(), userPropertiesToSet, userPropertiesToSetOnce);
1053
+ const tracksHash = this._surelyProcessesPerson(options);
1054
+ if (tracksHash && null !== hash && this._cachedPersonProperties === hash) return void this._logger.info('A duplicate setPersonProperties call was made with the same properties. It has been ignored.');
930
1055
  this.setPersonPropertiesForFlags({
931
1056
  $set: userPropertiesToSet || {},
932
1057
  $set_once: userPropertiesToSetOnce || {}
933
1058
  }, reloadFeatureFlags);
934
- this.capture('$set', {
935
- $set: userPropertiesToSet || {},
936
- $set_once: userPropertiesToSetOnce || {}
937
- });
938
- this._cachedPersonProperties = hash;
1059
+ this._captureWithPersonPropertiesHash(tracksHash ? hash : null, ()=>this.capture('$set', {
1060
+ $set: userPropertiesToSet || {},
1061
+ $set_once: userPropertiesToSetOnce || {}
1062
+ }, options));
939
1063
  });
940
1064
  }
941
- unsetPersonProperties(propertyNames, reloadFeatureFlags = true) {
1065
+ _surelyProcessesPerson(options) {
1066
+ const eventOptions = options?.options;
1067
+ const setting = (0, index_js_namespaceObject.isObject)(eventOptions) ? eventOptions.process_person_profile : void 0;
1068
+ return (0, index_js_namespaceObject.isNullish)(setting) || true === setting;
1069
+ }
1070
+ _captureWithPersonPropertiesHash(hash, capture) {
1071
+ this._pendingPersonPropertiesHash = hash;
1072
+ try {
1073
+ capture();
1074
+ } finally{
1075
+ this._pendingPersonPropertiesHash = void 0;
1076
+ }
1077
+ }
1078
+ _recordPersonPropertiesHash(captured, sent) {
1079
+ const option = (0, index_js_namespaceObject.isObject)(sent.options) ? sent.options.process_person_profile : void 0;
1080
+ const properties = (0, index_js_namespaceObject.isObject)(sent.properties) ? sent.properties : {};
1081
+ const setting = (0, index_js_namespaceObject.isNullish)(option) ? properties.$process_person_profile : option;
1082
+ const surelyProcessesPerson = null !== captured.hash && sent.event === captured.event && ((0, index_js_namespaceObject.isNullish)(setting) || true === setting) && null !== captured.payloadHash && sentPersonPropertiesHash(sent) === captured.payloadHash;
1083
+ this._cachedPersonProperties = surelyProcessesPerson ? captured.hash : null;
1084
+ }
1085
+ unsetPersonProperties(propertyNames, reloadFeatureFlags = true, options) {
942
1086
  this.wrap(()=>{
943
1087
  const names = ((0, index_js_namespaceObject.isArray)(propertyNames) ? propertyNames : [
944
1088
  propertyNames
@@ -954,11 +1098,23 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
954
1098
  if (reloadFeatureFlags) this.reloadFeatureFlags();
955
1099
  this.capture('$set', {
956
1100
  $unset: names
957
- });
1101
+ }, options);
958
1102
  this._cachedPersonProperties = null;
959
1103
  });
960
1104
  }
961
1105
  processBeforeEnqueue(message) {
1106
+ const hash = this._pendingPersonPropertiesHash;
1107
+ this._pendingPersonPropertiesHash = void 0;
1108
+ const captured = void 0 === hash ? void 0 : {
1109
+ hash,
1110
+ event: message.event,
1111
+ payloadHash: sentPersonPropertiesHash(message)
1112
+ };
1113
+ const result = this._runBeforeSendOnMessage(message);
1114
+ if (result && captured) this._recordPersonPropertiesHash(captured, result);
1115
+ return result;
1116
+ }
1117
+ _runBeforeSendOnMessage(message) {
962
1118
  if (!this._beforeSend) return message;
963
1119
  const timestamp = message.timestamp;
964
1120
  const props = message.properties || {};
@@ -970,6 +1126,7 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
970
1126
  $set_once: props.$set_once,
971
1127
  timestamp: 'string' == typeof timestamp ? new Date(timestamp) : timestamp
972
1128
  };
1129
+ if (void 0 !== message.options) captureEvent.options = message.options;
973
1130
  const result = this._runBeforeSend(captureEvent);
974
1131
  if (!result) return null;
975
1132
  const resultProps = {
@@ -984,7 +1141,10 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
984
1141
  uuid: (0, index_js_namespaceObject.getEventUuid)(result.uuid ?? message.uuid, uuidv7_js_namespaceObject.uuidv7),
985
1142
  event: result.event,
986
1143
  properties: resultProps,
987
- timestamp: result.timestamp
1144
+ timestamp: result.timestamp,
1145
+ ...void 0 !== result.options ? {
1146
+ options: result.options
1147
+ } : {}
988
1148
  };
989
1149
  }
990
1150
  _runBeforeSend(captureEvent) {
@@ -1001,15 +1161,81 @@ class PostHogCore extends external_posthog_core_stateless_js_namespaceObject.Pos
1001
1161
  return null;
1002
1162
  }
1003
1163
  } catch (e) {
1004
- this._logger.error(`Error in before_send function for event '${captureEvent.event}':`, e);
1164
+ const errorType = e instanceof Error ? e.name : typeof e;
1165
+ this._logger.error(`Error in before_send function for event '${captureEvent.event}' (${errorType})`);
1005
1166
  return null;
1006
1167
  }
1007
1168
  return result;
1008
1169
  }
1009
1170
  }
1171
+ class PostHogCore extends PostHogCoreBase {
1172
+ usesLegacyEventPersonState() {
1173
+ return true;
1174
+ }
1175
+ usesLegacyEventPropertyOrder() {
1176
+ return true;
1177
+ }
1178
+ usesLegacyFlagValues() {
1179
+ return true;
1180
+ }
1181
+ async reloadFeatureFlagsAsync(sendAnonDistinctId) {
1182
+ return this.loadFeatureFlagsAsync(sendAnonDistinctId);
1183
+ }
1184
+ getAllFeatureFlags() {
1185
+ return (0, external_featureFlagUtils_js_namespaceObject.flagDetailsToResults)(this.getFeatureFlagDetails()?.flags ?? {});
1186
+ }
1187
+ onFeatureFlags(cb) {
1188
+ return this.on('featureflags', async ()=>{
1189
+ const flags = this.getFeatureFlagValues();
1190
+ if (flags) cb(flags);
1191
+ });
1192
+ }
1193
+ getFeatureFlag(key, options) {
1194
+ const result = this._getFeatureFlagResult(key, {
1195
+ missingFlagBehavior: 'getFeatureFlag',
1196
+ sendEvent: resolveSendFeatureFlagEvent(options)
1197
+ });
1198
+ return result?.variant ?? result?.enabled;
1199
+ }
1200
+ getFeatureFlagPayload(key) {
1201
+ const result = this._getFeatureFlagResult(key, {
1202
+ missingFlagBehavior: 'getFeatureFlagPayload',
1203
+ sendEvent: false
1204
+ });
1205
+ return result?.payload;
1206
+ }
1207
+ getFeatureFlagPayloads() {
1208
+ return this.getFeatureFlagDetails()?.featureFlagPayloads;
1209
+ }
1210
+ getFeatureFlags() {
1211
+ return this.getFeatureFlagDetails()?.featureFlags;
1212
+ }
1213
+ getFeatureFlagsAndPayloads() {
1214
+ const flags = this.getFeatureFlags();
1215
+ const payloads = this.getFeatureFlagPayloads();
1216
+ return {
1217
+ flags,
1218
+ payloads
1219
+ };
1220
+ }
1221
+ onFeatureFlag(key, cb) {
1222
+ return this.on('featureflags', async ()=>{
1223
+ const flagResponse = this.getFeatureFlag(key);
1224
+ if (void 0 !== flagResponse) cb(flagResponse);
1225
+ });
1226
+ }
1227
+ async overrideFeatureFlag(flags) {
1228
+ this.wrap(()=>{
1229
+ if (null === flags) return this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.OverrideFeatureFlags, null);
1230
+ return this.setPersistedProperty(external_types_js_namespaceObject.PostHogPersistedProperty.OverrideFeatureFlags, flags);
1231
+ });
1232
+ }
1233
+ }
1010
1234
  exports.PostHogCore = __webpack_exports__.PostHogCore;
1235
+ exports.PostHogCoreBase = __webpack_exports__.PostHogCoreBase;
1011
1236
  for(var __rspack_i in __webpack_exports__)if (-1 === [
1012
- "PostHogCore"
1237
+ "PostHogCore",
1238
+ "PostHogCoreBase"
1013
1239
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
1014
1240
  Object.defineProperty(exports, '__esModule', {
1015
1241
  value: true