@posthog/browser 0.4.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/ARCHITECTURE.md +36 -48
  2. package/README.md +97 -69
  3. package/dist/composition/npm/core.d.ts +3 -4
  4. package/dist/composition/npm/core.js +2 -1
  5. package/dist/composition/npm/core.mjs +2 -1
  6. package/dist/composition/npm/index.d.ts +4 -5
  7. package/dist/composition/npm/index.js +2 -1
  8. package/dist/composition/npm/index.mjs +2 -1
  9. package/dist/composition/npm/root-composition.d.ts +4 -4
  10. package/dist/composition/npm/root-composition.js +0 -16
  11. package/dist/composition/npm/root-composition.mjs +0 -16
  12. package/dist/core/context/browser-client.d.ts +4 -35
  13. package/dist/core/extensions/registry.d.ts +15 -36
  14. package/dist/core/extensions/registry.js +67 -198
  15. package/dist/core/extensions/registry.mjs +67 -198
  16. package/dist/core/posthog.d.ts +3 -2
  17. package/dist/core/posthog.js +190 -173
  18. package/dist/core/posthog.mjs +191 -174
  19. package/dist/core/state/state.d.ts +33 -3
  20. package/dist/core/state/state.js +122 -27
  21. package/dist/core/state/state.mjs +107 -27
  22. package/dist/core/types.d.ts +134 -14
  23. package/dist/persistence/cookie.d.ts +19 -0
  24. package/dist/persistence/cookie.js +273 -0
  25. package/dist/persistence/cookie.mjs +235 -0
  26. package/dist/platform/logger.d.ts +5 -1
  27. package/dist/platform/logger.js +3 -3
  28. package/dist/platform/logger.mjs +3 -3
  29. package/dist/primitives/id.d.ts +5 -0
  30. package/dist/primitives/id.js +10 -2
  31. package/dist/primitives/id.mjs +6 -1
  32. package/dist/primitives/version.js +1 -1
  33. package/dist/primitives/version.mjs +1 -1
  34. package/dist/products/analytics/analytics-core.d.ts +89 -0
  35. package/dist/products/analytics/analytics-core.js +563 -0
  36. package/dist/products/analytics/analytics-core.mjs +516 -0
  37. package/dist/products/analytics/analytics-internal.d.ts +16 -37
  38. package/dist/products/analytics/analytics-internal.js +2 -10
  39. package/dist/products/analytics/analytics-internal.mjs +1 -3
  40. package/dist/products/analytics/analytics-options.d.ts +0 -9
  41. package/dist/products/analytics/analytics-options.js +1 -38
  42. package/dist/products/analytics/analytics-options.mjs +1 -17
  43. package/dist/products/analytics/delivery/analytics-delivery.js +1 -1
  44. package/dist/products/analytics/delivery/analytics-delivery.mjs +1 -1
  45. package/dist/products/analytics/delivery/lane.d.ts +8 -1
  46. package/dist/products/analytics/delivery/lane.js +16 -4
  47. package/dist/products/analytics/delivery/lane.mjs +16 -4
  48. package/dist/products/analytics/groups.d.ts +8 -0
  49. package/dist/products/analytics/groups.js +84 -0
  50. package/dist/products/analytics/groups.mjs +40 -0
  51. package/dist/products/analytics/person.d.ts +11 -0
  52. package/dist/products/analytics/person.js +91 -0
  53. package/dist/products/analytics/person.mjs +41 -0
  54. package/dist/products/analytics/properties/analytics-properties.d.ts +1 -0
  55. package/dist/products/analytics/properties/analytics-properties.js +3 -0
  56. package/dist/products/analytics/properties/analytics-properties.mjs +1 -1
  57. package/dist/products/autocapture/autocapture.js +2 -6
  58. package/dist/products/autocapture/autocapture.mjs +2 -6
  59. package/dist/products/flags/flags-internal.d.ts +4 -2
  60. package/dist/products/flags/flags-options.d.ts +16 -2
  61. package/dist/products/flags/flags-token.d.ts +31 -4
  62. package/dist/products/flags/flags.d.ts +1 -1
  63. package/dist/products/flags/flags.js +112 -11
  64. package/dist/products/flags/flags.mjs +112 -11
  65. package/dist/products/logs/logs.js +2 -5
  66. package/dist/products/logs/logs.mjs +2 -5
  67. package/dist/products/surveys/surveys-extension.js +78 -46
  68. package/dist/products/surveys/surveys-extension.mjs +80 -48
  69. package/dist/products/surveys/surveys-internal.d.ts +6 -0
  70. package/package.json +7 -7
  71. package/dist/products/analytics/analytics-api.d.ts +0 -32
  72. package/dist/products/analytics/analytics-api.js +0 -18
  73. package/dist/products/analytics/analytics-api.mjs +0 -1
  74. package/dist/products/analytics/analytics-buffer.d.ts +0 -4
  75. package/dist/products/analytics/analytics-buffer.js +0 -41
  76. package/dist/products/analytics/analytics-buffer.mjs +0 -3
  77. package/dist/products/analytics/analytics-extension.d.ts +0 -87
  78. package/dist/products/analytics/analytics-extension.js +0 -649
  79. package/dist/products/analytics/analytics-extension.mjs +0 -611
  80. package/dist/products/analytics/analytics.d.ts +0 -6
  81. package/dist/products/analytics/analytics.js +0 -42
  82. package/dist/products/analytics/analytics.mjs +0 -4
  83. package/dist/products/analytics/automatic-analytics.d.ts +0 -3
  84. package/dist/products/analytics/automatic-analytics.js +0 -44
  85. package/dist/products/analytics/automatic-analytics.mjs +0 -6
@@ -1,20 +1,5 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, getters, values)=>{
5
- var define = (defs, kind)=>{
6
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
- enumerable: true,
8
- [kind]: defs[key]
9
- });
10
- };
11
- define(getters, "get");
12
- define(values, "value");
13
- };
14
- })();
15
- (()=>{
16
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
- })();
18
3
  (()=>{
19
4
  __webpack_require__.r = (exports1)=>{
20
5
  if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
@@ -27,29 +12,7 @@ var __webpack_require__ = {};
27
12
  })();
28
13
  var __webpack_exports__ = {};
29
14
  __webpack_require__.r(__webpack_exports__);
30
- const snapshotAutomaticAnalyticsOptions = (options = {})=>{
31
- const snapshot = {};
32
- for (const key of [
33
- 'flushAt',
34
- 'flushInterval',
35
- 'personProfiles',
36
- 'load'
37
- ])try {
38
- const value = options[key];
39
- if (void 0 !== value) Object.defineProperty(snapshot, key, {
40
- value,
41
- enumerable: true
42
- });
43
- } catch {}
44
- return snapshot;
45
- };
46
- __webpack_require__.d(__webpack_exports__, {}, {
47
- snapshotAutomaticAnalyticsOptions: snapshotAutomaticAnalyticsOptions
48
- });
49
- exports.snapshotAutomaticAnalyticsOptions = __webpack_exports__.snapshotAutomaticAnalyticsOptions;
50
- for(var __rspack_i in __webpack_exports__)if (-1 === [
51
- "snapshotAutomaticAnalyticsOptions"
52
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
53
16
  Object.defineProperty(exports, '__esModule', {
54
17
  value: true
55
18
  });
@@ -1,17 +1 @@
1
- const snapshotAutomaticAnalyticsOptions = (options = {})=>{
2
- const snapshot = {};
3
- for (const key of [
4
- 'flushAt',
5
- 'flushInterval',
6
- 'personProfiles',
7
- 'load'
8
- ])try {
9
- const value = options[key];
10
- if (void 0 !== value) Object.defineProperty(snapshot, key, {
11
- value,
12
- enumerable: true
13
- });
14
- } catch {}
15
- return snapshot;
16
- };
17
- export { snapshotAutomaticAnalyticsOptions };
1
+ export { };
@@ -216,7 +216,7 @@ const createAnalyticsDelivery = (buffer, client, host, options, beforeTeardown)=
216
216
  };
217
217
  lane.attach(delivery);
218
218
  return {
219
- flush: ()=>lane.flush(),
219
+ flush: (immediate)=>lane.flush(immediate),
220
220
  deliverImmediate: delivery.deliverImmediate,
221
221
  deliverUnload: (messages)=>delivery.teardown?.(messages, external_capture_v1_js_namespaceObject.CAPTURE_V1_TEARDOWN_BUDGET_BYTES),
222
222
  dispose
@@ -184,7 +184,7 @@ const createAnalyticsDelivery = (buffer, client, host, options, beforeTeardown)=
184
184
  };
185
185
  lane.attach(delivery);
186
186
  return {
187
- flush: ()=>lane.flush(),
187
+ flush: (immediate)=>lane.flush(immediate),
188
188
  deliverImmediate: delivery.deliverImmediate,
189
189
  deliverUnload: (messages)=>delivery.teardown?.(messages, CAPTURE_V1_TEARDOWN_BUDGET_BYTES),
190
190
  dispose
@@ -29,9 +29,15 @@ export declare class Lane<E> {
29
29
  private _driveEpoch;
30
30
  private _activeEpoch;
31
31
  private _forceTarget;
32
+ /** The last event an immediate flush covered; it survives one failed drain until those events are attempted. */
33
+ private _immediateTarget;
32
34
  constructor(_buffer: EventBuffer<E>, _onError?: (error: unknown) => void, _onAvailable?: () => void);
33
35
  attach(delivery: LaneDelivery<E>): void;
34
- flush(): Promise<void>;
36
+ /**
37
+ * Drives delivery through the events queued now. With `immediate`, one more drain is forced if an earlier batch
38
+ * fails before those events are attempted; behind a full batch of older events, they can still wait for the next drain.
39
+ */
40
+ flush(immediate?: boolean): Promise<void>;
35
41
  /** Pauses scheduled work while preserving active and queued accounting. */
36
42
  pause(): void;
37
43
  /** Redrives retained work after a connectivity transition. */
@@ -43,6 +49,7 @@ export declare class Lane<E> {
43
49
  private _clearTimer;
44
50
  private _trimQueue;
45
51
  private _updateSettled;
52
+ private _takeUnattemptedImmediateTarget;
46
53
  private _reportError;
47
54
  private _reportAvailable;
48
55
  private _resolveFlushWaiters;
@@ -44,6 +44,7 @@ class Lane {
44
44
  } else if ('purge' === change) {
45
45
  this._retryBlocked = false;
46
46
  this._forceTarget = void 0;
47
+ this._immediateTarget = void 0;
47
48
  this._clearTimer();
48
49
  this._cancelActive();
49
50
  } else {
@@ -61,11 +62,15 @@ class Lane {
61
62
  this._buffer._expireQueue(this._buffer._now());
62
63
  this._schedule();
63
64
  }
64
- flush() {
65
+ flush(immediate = false) {
65
66
  this._buffer._expireQueue(this._buffer._now());
66
67
  const attached = this._delivery;
67
- if (!attached || !this._buffer._activeEntries && 0 === this._buffer._queue.length || !this._canDeliver(attached)) return Promise.resolve();
68
68
  const target = this._buffer._nextId;
69
+ if (immediate) {
70
+ this._immediateTarget = target;
71
+ this._forceTarget = Math.max(this._forceTarget ?? 0, target);
72
+ }
73
+ if (!attached || !this._buffer._activeEntries && 0 === this._buffer._queue.length || !this._canDeliver(attached)) return Promise.resolve();
69
74
  this._retryBlocked = false;
70
75
  this._clearTimer();
71
76
  this._forceTarget = Math.max(this._forceTarget ?? 0, target);
@@ -149,8 +154,14 @@ class Lane {
149
154
  const firstPending = void 0 === activeId ? queuedId : void 0 === queuedId ? activeId : Math.min(activeId, queuedId);
150
155
  this._settledId = void 0 === firstPending ? this._buffer._nextId : firstPending - 1;
151
156
  if (void 0 !== this._forceTarget && this._settledId >= this._forceTarget) this._forceTarget = void 0;
157
+ if (void 0 !== this._immediateTarget && this._settledId >= this._immediateTarget) this._immediateTarget = void 0;
152
158
  if (!this._drain) this._resolveFlushWaiters(false);
153
159
  }
160
+ _takeUnattemptedImmediateTarget() {
161
+ const target = this._immediateTarget;
162
+ this._immediateTarget = void 0;
163
+ return void 0 !== target && this._buffer._queue.some((entry)=>entry[0] <= target && 0 === entry[4]) ? target : void 0;
164
+ }
154
165
  _reportError(error) {
155
166
  try {
156
167
  this._onError(error);
@@ -241,7 +252,8 @@ class Lane {
241
252
  return;
242
253
  }
243
254
  if (!this._canDeliver(attached)) return void this._clearTimer();
244
- const forced = void 0 !== this._forceTarget && this._buffer._queue[0][0] <= this._forceTarget;
255
+ const head = this._buffer._queue[0];
256
+ const forced = void 0 !== this._forceTarget && head[0] <= this._forceTarget && !(this._retryBlocked && head[5] > this._buffer._now());
245
257
  if (forced || !this._retryBlocked && this._buffer._queue.length >= this._readFlushAt(attached)) {
246
258
  this._clearTimer();
247
259
  this._beginDrive(false);
@@ -329,7 +341,7 @@ class Lane {
329
341
  if (completionGeneration === this._buffer._generation) {
330
342
  this._trimQueue();
331
343
  this._retryBlocked = true;
332
- this._forceTarget = void 0;
344
+ this._forceTarget = this._takeUnattemptedImmediateTarget();
333
345
  this._updateSettled();
334
346
  }
335
347
  } else this._updateSettled();
@@ -15,6 +15,7 @@ class Lane {
15
15
  } else if ('purge' === change) {
16
16
  this._retryBlocked = false;
17
17
  this._forceTarget = void 0;
18
+ this._immediateTarget = void 0;
18
19
  this._clearTimer();
19
20
  this._cancelActive();
20
21
  } else {
@@ -32,11 +33,15 @@ class Lane {
32
33
  this._buffer._expireQueue(this._buffer._now());
33
34
  this._schedule();
34
35
  }
35
- flush() {
36
+ flush(immediate = false) {
36
37
  this._buffer._expireQueue(this._buffer._now());
37
38
  const attached = this._delivery;
38
- if (!attached || !this._buffer._activeEntries && 0 === this._buffer._queue.length || !this._canDeliver(attached)) return Promise.resolve();
39
39
  const target = this._buffer._nextId;
40
+ if (immediate) {
41
+ this._immediateTarget = target;
42
+ this._forceTarget = Math.max(this._forceTarget ?? 0, target);
43
+ }
44
+ if (!attached || !this._buffer._activeEntries && 0 === this._buffer._queue.length || !this._canDeliver(attached)) return Promise.resolve();
40
45
  this._retryBlocked = false;
41
46
  this._clearTimer();
42
47
  this._forceTarget = Math.max(this._forceTarget ?? 0, target);
@@ -120,8 +125,14 @@ class Lane {
120
125
  const firstPending = void 0 === activeId ? queuedId : void 0 === queuedId ? activeId : Math.min(activeId, queuedId);
121
126
  this._settledId = void 0 === firstPending ? this._buffer._nextId : firstPending - 1;
122
127
  if (void 0 !== this._forceTarget && this._settledId >= this._forceTarget) this._forceTarget = void 0;
128
+ if (void 0 !== this._immediateTarget && this._settledId >= this._immediateTarget) this._immediateTarget = void 0;
123
129
  if (!this._drain) this._resolveFlushWaiters(false);
124
130
  }
131
+ _takeUnattemptedImmediateTarget() {
132
+ const target = this._immediateTarget;
133
+ this._immediateTarget = void 0;
134
+ return void 0 !== target && this._buffer._queue.some((entry)=>entry[0] <= target && 0 === entry[4]) ? target : void 0;
135
+ }
125
136
  _reportError(error) {
126
137
  try {
127
138
  this._onError(error);
@@ -212,7 +223,8 @@ class Lane {
212
223
  return;
213
224
  }
214
225
  if (!this._canDeliver(attached)) return void this._clearTimer();
215
- const forced = void 0 !== this._forceTarget && this._buffer._queue[0][0] <= this._forceTarget;
226
+ const head = this._buffer._queue[0];
227
+ const forced = void 0 !== this._forceTarget && head[0] <= this._forceTarget && !(this._retryBlocked && head[5] > this._buffer._now());
216
228
  if (forced || !this._retryBlocked && this._buffer._queue.length >= this._readFlushAt(attached)) {
217
229
  this._clearTimer();
218
230
  this._beginDrive(false);
@@ -300,7 +312,7 @@ class Lane {
300
312
  if (completionGeneration === this._buffer._generation) {
301
313
  this._trimQueue();
302
314
  this._retryBlocked = true;
303
- this._forceTarget = void 0;
315
+ this._forceTarget = this._takeUnattemptedImmediateTarget();
304
316
  this._updateSettled();
305
317
  }
306
318
  } else this._updateSettled();
@@ -0,0 +1,8 @@
1
+ import type { CaptureOptions } from '@posthog/browser-common';
2
+ import type { IPostHog } from '../../core/types';
3
+ /** Associates future events with a group and, when person processing is enabled, records its properties. */
4
+ export declare const group: (posthog: IPostHog, type: string, key: string, properties?: Record<string, unknown>) => void;
5
+ /** Sends a group-profile update without changing group membership. */
6
+ export declare const groupIdentify: (posthog: IPostHog, type: string, key: string | number, properties?: Record<string, unknown>, options?: CaptureOptions) => void;
7
+ /** Clears group memberships, retaining identity, sessions and registered properties. */
8
+ export declare const resetGroups: (posthog: IPostHog) => void;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ group: ()=>group,
32
+ groupIdentify: ()=>groupIdentify,
33
+ resetGroups: ()=>resetGroups
34
+ });
35
+ const external_analytics_core_js_namespaceObject = require("./analytics-core.js");
36
+ const isValidGroupKey = (value)=>(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(value) || Number.isFinite(value);
37
+ const group = (posthog, type, key, properties)=>{
38
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
39
+ if (!analytics || !(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(type) || !(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(key) || 'never' === analytics._personProfiles || !analytics._canMutate()) return;
40
+ const changed = analytics._core._state.group(type, key);
41
+ if (!changed && !properties) return;
42
+ analytics._groupPublisher.publish({
43
+ type,
44
+ key,
45
+ changed,
46
+ properties
47
+ });
48
+ if (!analytics._hasPersonProcessing()) return;
49
+ analytics.capture('$groupidentify', {
50
+ $group_type: type,
51
+ $group_key: key,
52
+ ...properties ? {
53
+ $group_set: properties
54
+ } : {}
55
+ });
56
+ };
57
+ const groupIdentify = (posthog, type, key, properties = {}, options = {})=>{
58
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
59
+ if (!analytics?._canMutate() || !analytics._core.canCapture) return;
60
+ if (!(0, external_analytics_core_js_namespaceObject.isNonEmptyString)(type) || !isValidGroupKey(key)) return void posthog.logger.warn('Group identify requires a non-empty type and a string or finite numeric key');
61
+ if (!analytics._core._state.prepare() || !analytics._requirePersonProcessing()) return;
62
+ analytics.capture('$groupidentify', {
63
+ $group_type: type,
64
+ $group_key: key,
65
+ $group_set: properties
66
+ }, options);
67
+ };
68
+ const resetGroups = (posthog)=>{
69
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
70
+ if (!analytics?._canMutate()) return;
71
+ analytics._core._state.resetGroups();
72
+ analytics._groupsResetPublisher.publish(void 0);
73
+ };
74
+ exports.group = __webpack_exports__.group;
75
+ exports.groupIdentify = __webpack_exports__.groupIdentify;
76
+ exports.resetGroups = __webpack_exports__.resetGroups;
77
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
78
+ "group",
79
+ "groupIdentify",
80
+ "resetGroups"
81
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
82
+ Object.defineProperty(exports, '__esModule', {
83
+ value: true
84
+ });
@@ -0,0 +1,40 @@
1
+ import { analyticsOf, isNonEmptyString } from "./analytics-core.mjs";
2
+ const isValidGroupKey = (value)=>isNonEmptyString(value) || Number.isFinite(value);
3
+ const group = (posthog, type, key, properties)=>{
4
+ const analytics = analyticsOf(posthog);
5
+ if (!analytics || !isNonEmptyString(type) || !isNonEmptyString(key) || 'never' === analytics._personProfiles || !analytics._canMutate()) return;
6
+ const changed = analytics._core._state.group(type, key);
7
+ if (!changed && !properties) return;
8
+ analytics._groupPublisher.publish({
9
+ type,
10
+ key,
11
+ changed,
12
+ properties
13
+ });
14
+ if (!analytics._hasPersonProcessing()) return;
15
+ analytics.capture('$groupidentify', {
16
+ $group_type: type,
17
+ $group_key: key,
18
+ ...properties ? {
19
+ $group_set: properties
20
+ } : {}
21
+ });
22
+ };
23
+ const groupIdentify = (posthog, type, key, properties = {}, options = {})=>{
24
+ const analytics = analyticsOf(posthog);
25
+ if (!analytics?._canMutate() || !analytics._core.canCapture) return;
26
+ if (!isNonEmptyString(type) || !isValidGroupKey(key)) return void posthog.logger.warn('Group identify requires a non-empty type and a string or finite numeric key');
27
+ if (!analytics._core._state.prepare() || !analytics._requirePersonProcessing()) return;
28
+ analytics.capture('$groupidentify', {
29
+ $group_type: type,
30
+ $group_key: key,
31
+ $group_set: properties
32
+ }, options);
33
+ };
34
+ const resetGroups = (posthog)=>{
35
+ const analytics = analyticsOf(posthog);
36
+ if (!analytics?._canMutate()) return;
37
+ analytics._core._state.resetGroups();
38
+ analytics._groupsResetPublisher.publish(void 0);
39
+ };
40
+ export { group, groupIdentify, resetGroups };
@@ -0,0 +1,11 @@
1
+ import type { IPostHog } from '../../core/types';
2
+ /** Enables person processing for the current identity without identifying it. */
3
+ export declare const createPersonProfile: (posthog: IPostHog) => void;
4
+ /** Sets person properties for the current identity. */
5
+ export declare const setPersonProperties: (posthog: IPostHog, set?: Record<string, unknown>, setOnce?: Record<string, unknown>) => void;
6
+ /** Removes person properties from the current identity. */
7
+ export declare const unsetPersonProperties: (posthog: IPostHog, names: string | readonly string[]) => void;
8
+ /** Marks the current person as an internal or test user. */
9
+ export declare const setInternalOrTestUser: (posthog: IPostHog) => void;
10
+ /** Links another distinct ID to the current person without changing the current identity. */
11
+ export declare const alias: (posthog: IPostHog, aliasId: string) => void;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ alias: ()=>alias,
32
+ createPersonProfile: ()=>createPersonProfile,
33
+ setInternalOrTestUser: ()=>setInternalOrTestUser,
34
+ setPersonProperties: ()=>setPersonProperties,
35
+ unsetPersonProperties: ()=>unsetPersonProperties
36
+ });
37
+ const external_analytics_core_js_namespaceObject = require("./analytics-core.js");
38
+ const person_processing_js_namespaceObject = require("./properties/person-processing.js");
39
+ const createPersonProfile = (posthog)=>{
40
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
41
+ if (!analytics?._canMutate() || analytics._hasPersonProcessing()) return;
42
+ const properties = (0, person_processing_js_namespaceObject.snapshotPersonProperties)(analytics._core._state.distinctId, {}, {});
43
+ if (properties) analytics._setPersonProperties(properties);
44
+ };
45
+ const setPersonProperties = (posthog, set, setOnce)=>{
46
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
47
+ if (!analytics?._canMutate()) return;
48
+ const properties = (0, person_processing_js_namespaceObject.snapshotPersonProperties)(analytics._core._state.distinctId, set, setOnce);
49
+ if (!properties) return void posthog.logger.warn('Person properties must be JSON-serializable objects');
50
+ if (Object.keys(properties.set).length || Object.keys(properties.setOnce).length) analytics._setPersonProperties(properties);
51
+ };
52
+ const unsetPersonProperties = (posthog, names)=>{
53
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
54
+ if (!analytics?._canMutate()) return;
55
+ const properties = (0, person_processing_js_namespaceObject.personPropertyNames)(names);
56
+ if (!properties.length || !analytics._requirePersonProcessing()) return;
57
+ analytics._lastPersonProperties = void 0;
58
+ analytics._changePropertiesPublisher.publish({
59
+ unset: properties
60
+ });
61
+ analytics._capture('$set', {
62
+ $unset: properties
63
+ }, {}, false, {
64
+ signature: void 0
65
+ });
66
+ };
67
+ const setInternalOrTestUser = (posthog)=>setPersonProperties(posthog, {
68
+ $internal_or_test_user: true
69
+ });
70
+ const alias = (posthog, aliasId)=>{
71
+ const analytics = (0, external_analytics_core_js_namespaceObject.analyticsOf)(posthog);
72
+ if (!analytics || !(0, external_analytics_core_js_namespaceObject.isValidDistinctId)(aliasId) || !posthog.canCapture || !analytics._canMutate()) return;
73
+ if (analytics._requirePersonProcessing()) analytics._capture('$create_alias', {
74
+ alias: aliasId
75
+ });
76
+ };
77
+ exports.alias = __webpack_exports__.alias;
78
+ exports.createPersonProfile = __webpack_exports__.createPersonProfile;
79
+ exports.setInternalOrTestUser = __webpack_exports__.setInternalOrTestUser;
80
+ exports.setPersonProperties = __webpack_exports__.setPersonProperties;
81
+ exports.unsetPersonProperties = __webpack_exports__.unsetPersonProperties;
82
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
83
+ "alias",
84
+ "createPersonProfile",
85
+ "setInternalOrTestUser",
86
+ "setPersonProperties",
87
+ "unsetPersonProperties"
88
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
89
+ Object.defineProperty(exports, '__esModule', {
90
+ value: true
91
+ });
@@ -0,0 +1,41 @@
1
+ import { analyticsOf, isValidDistinctId } from "./analytics-core.mjs";
2
+ import { personPropertyNames, snapshotPersonProperties } from "./properties/person-processing.mjs";
3
+ const createPersonProfile = (posthog)=>{
4
+ const analytics = analyticsOf(posthog);
5
+ if (!analytics?._canMutate() || analytics._hasPersonProcessing()) return;
6
+ const properties = snapshotPersonProperties(analytics._core._state.distinctId, {}, {});
7
+ if (properties) analytics._setPersonProperties(properties);
8
+ };
9
+ const setPersonProperties = (posthog, set, setOnce)=>{
10
+ const analytics = analyticsOf(posthog);
11
+ if (!analytics?._canMutate()) return;
12
+ const properties = snapshotPersonProperties(analytics._core._state.distinctId, set, setOnce);
13
+ if (!properties) return void posthog.logger.warn('Person properties must be JSON-serializable objects');
14
+ if (Object.keys(properties.set).length || Object.keys(properties.setOnce).length) analytics._setPersonProperties(properties);
15
+ };
16
+ const unsetPersonProperties = (posthog, names)=>{
17
+ const analytics = analyticsOf(posthog);
18
+ if (!analytics?._canMutate()) return;
19
+ const properties = personPropertyNames(names);
20
+ if (!properties.length || !analytics._requirePersonProcessing()) return;
21
+ analytics._lastPersonProperties = void 0;
22
+ analytics._changePropertiesPublisher.publish({
23
+ unset: properties
24
+ });
25
+ analytics._capture('$set', {
26
+ $unset: properties
27
+ }, {}, false, {
28
+ signature: void 0
29
+ });
30
+ };
31
+ const setInternalOrTestUser = (posthog)=>setPersonProperties(posthog, {
32
+ $internal_or_test_user: true
33
+ });
34
+ const alias = (posthog, aliasId)=>{
35
+ const analytics = analyticsOf(posthog);
36
+ if (!analytics || !isValidDistinctId(aliasId) || !posthog.canCapture || !analytics._canMutate()) return;
37
+ if (analytics._requirePersonProcessing()) analytics._capture('$create_alias', {
38
+ alias: aliasId
39
+ });
40
+ };
41
+ export { alias, createPersonProfile, setInternalOrTestUser, setPersonProperties, unsetPersonProperties };
@@ -1,4 +1,5 @@
1
1
  import type { KeyValueStore } from '@posthog/browser-common';
2
+ export declare const REGISTERED_PROPERTIES = "superProperties";
2
3
  export declare const snapshotRegisteredProperties: (value: Record<string, unknown>) => Record<string, unknown> | undefined;
3
4
  /** Persistent event context in analytics' existing host-owned namespace. */
4
5
  export declare class RegisteredProperties {
@@ -75,11 +75,14 @@ class RegisteredProperties {
75
75
  __webpack_require__.d(__webpack_exports__, {
76
76
  RegisteredProperties: ()=>RegisteredProperties
77
77
  }, {
78
+ REGISTERED_PROPERTIES: REGISTERED_PROPERTIES,
78
79
  snapshotRegisteredProperties: snapshotRegisteredProperties
79
80
  });
81
+ exports.REGISTERED_PROPERTIES = __webpack_exports__.REGISTERED_PROPERTIES;
80
82
  exports.RegisteredProperties = __webpack_exports__.RegisteredProperties;
81
83
  exports.snapshotRegisteredProperties = __webpack_exports__.snapshotRegisteredProperties;
82
84
  for(var __rspack_i in __webpack_exports__)if (-1 === [
85
+ "REGISTERED_PROPERTIES",
83
86
  "RegisteredProperties",
84
87
  "snapshotRegisteredProperties"
85
88
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -43,4 +43,4 @@ class RegisteredProperties {
43
43
  this._kv.set(REGISTERED_PROPERTIES, values);
44
44
  }
45
45
  }
46
- export { RegisteredProperties, snapshotRegisteredProperties };
46
+ export { REGISTERED_PROPERTIES, RegisteredProperties, snapshotRegisteredProperties };
@@ -92,15 +92,11 @@ const autocapture = (options = {})=>{
92
92
  });
93
93
  const extension = {
94
94
  name: 'autocapture',
95
- bindings: {
96
- autocapture: shared
97
- },
98
- async setup (client) {
99
- await client.resolveExtension('analytics');
95
+ setup (client) {
100
96
  if (disposed) return;
101
97
  const selectors = client.surveys?.getElementSelectors?.();
102
98
  if (selectors) extension.setElementSelectors(selectors);
103
- shared.setup(client.sharedClient);
99
+ shared.setup(client);
104
100
  },
105
101
  setElementSelectors: (selectors)=>shared.setElementSelectors(new Set(selectors)),
106
102
  dispose: ()=>{
@@ -60,15 +60,11 @@ const autocapture = (options = {})=>{
60
60
  });
61
61
  const extension = {
62
62
  name: 'autocapture',
63
- bindings: {
64
- autocapture: shared
65
- },
66
- async setup (client) {
67
- await client.resolveExtension('analytics');
63
+ setup (client) {
68
64
  if (disposed) return;
69
65
  const selectors = client.surveys?.getElementSelectors?.();
70
66
  if (selectors) extension.setElementSelectors(selectors);
71
- shared.setup(client.sharedClient);
67
+ shared.setup(client);
72
68
  },
73
69
  setElementSelectors: (selectors)=>shared.setElementSelectors(new Set(selectors)),
74
70
  dispose: ()=>{
@@ -1,8 +1,10 @@
1
+ import type { FlagsOptions } from './flags-options';
1
2
  import type { FeatureFlags } from './flags-token';
2
- /** SDK-specific flags configuration and persisted survey targeting context. */
3
+ /** SDK-specific flags configuration read by surveys. Person properties are read from the shared client store. */
3
4
  export interface FlagsExtension extends FeatureFlags {
4
5
  getSurveyContext(): {
5
6
  remoteEvaluation: boolean;
6
- personProperties: Record<string, unknown> | undefined;
7
7
  };
8
+ /** Serves the flags and payloads that `reset({ bootstrap })` supplies for the new identity. */
9
+ bootstrap(bootstrap: NonNullable<FlagsOptions['bootstrap']>): void;
8
10
  }
@@ -1,4 +1,4 @@
1
- import type { FeatureFlagResult, JsonType } from '@posthog/types';
1
+ import type { EarlyAccessFeature, EarlyAccessFeatureCallback, EarlyAccessFeatureStage, FeatureFlagResult, JsonType } from '@posthog/types';
2
2
  export interface FlagsOptions {
3
3
  /** Evaluate flags remotely. Defaults to true; false retains bootstrap and injected values. */
4
4
  featureFlagEvaluation?: boolean;
@@ -16,7 +16,21 @@ export interface FlagsOptions {
16
16
  deduplicateCallsPerSession?: boolean;
17
17
  onlyEvaluateSurveyFeatureFlags?: boolean;
18
18
  }
19
+ export interface FlagsReadOptions {
20
+ /** Emit a deduplicated `$feature_flag_called` event. Defaults to true. */
21
+ sendFeatureFlagEvent?: boolean;
22
+ /**
23
+ * Return undefined unless the latest flag request in this SDK instance
24
+ * succeeded, instead of using persisted or bootstrapped values, as in
25
+ * posthog-js.
26
+ *
27
+ * Use this to avoid showing a previously enabled feature that has since
28
+ * been disabled on the server while the initial flag request is pending.
29
+ * This option does not force or wait for a reload.
30
+ */
31
+ fresh?: boolean;
32
+ }
19
33
  export type FlagsConfiguration = false | FlagsOptions;
20
34
  export type FlagsCallback = (flags: FeatureFlagResult[], errorsLoading: boolean) => void;
21
- export type { FeatureFlagResult, JsonType };
35
+ export type { EarlyAccessFeature, EarlyAccessFeatureCallback, EarlyAccessFeatureStage, FeatureFlagResult, JsonType };
22
36
  export type { FeatureFlagsReloadResult } from '@posthog/browser-common/feature-flags';