posthog-js 1.425.0 → 1.426.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 (123) hide show
  1. package/dist/all-external-dependencies.js +1 -1
  2. package/dist/all-external-dependencies.js.map +1 -1
  3. package/dist/array.full.es5.js +1 -1
  4. package/dist/array.full.es5.js.map +1 -1
  5. package/dist/array.full.js +1 -1
  6. package/dist/array.full.js.map +1 -1
  7. package/dist/array.full.no-external.js +1 -1
  8. package/dist/array.full.no-external.js.map +1 -1
  9. package/dist/array.js +1 -1
  10. package/dist/array.js.map +1 -1
  11. package/dist/array.no-external.js +1 -1
  12. package/dist/array.no-external.js.map +1 -1
  13. package/dist/conversations.js +1 -1
  14. package/dist/conversations.js.map +1 -1
  15. package/dist/crisp-chat-integration.js +1 -1
  16. package/dist/crisp-chat-integration.js.map +1 -1
  17. package/dist/customizations.full.js +1 -1
  18. package/dist/customizations.full.js.map +1 -1
  19. package/dist/customizations.js +1 -1
  20. package/dist/customizations.js.map +1 -1
  21. package/dist/dead-clicks-autocapture.js +1 -1
  22. package/dist/dead-clicks-autocapture.js.map +1 -1
  23. package/dist/default-extensions.js +1 -1
  24. package/dist/default-extensions.js.map +1 -1
  25. package/dist/element-inference.js +1 -1
  26. package/dist/element-inference.js.map +1 -1
  27. package/dist/exception-autocapture.js +1 -1
  28. package/dist/exception-autocapture.js.map +1 -1
  29. package/dist/extension-bundles.js +1 -1
  30. package/dist/extension-bundles.js.map +1 -1
  31. package/dist/external-scripts-loader.js +1 -1
  32. package/dist/external-scripts-loader.js.map +1 -1
  33. package/dist/intercom-integration.js +1 -1
  34. package/dist/intercom-integration.js.map +1 -1
  35. package/dist/lazy-recorder.js +1 -1
  36. package/dist/lazy-recorder.js.map +1 -1
  37. package/dist/logs.js +1 -1
  38. package/dist/logs.js.map +1 -1
  39. package/dist/main.js +1 -1
  40. package/dist/main.js.map +1 -1
  41. package/dist/module.d.ts +7 -3
  42. package/dist/module.full.d.ts +7 -3
  43. package/dist/module.full.js +1 -1
  44. package/dist/module.full.js.map +1 -1
  45. package/dist/module.full.no-external.d.ts +7 -3
  46. package/dist/module.full.no-external.js +1 -1
  47. package/dist/module.full.no-external.js.map +1 -1
  48. package/dist/module.js +1 -1
  49. package/dist/module.js.map +1 -1
  50. package/dist/module.no-external.d.ts +7 -3
  51. package/dist/module.no-external.js +1 -1
  52. package/dist/module.no-external.js.map +1 -1
  53. package/dist/module.slim.js +1 -1
  54. package/dist/module.slim.js.map +1 -1
  55. package/dist/module.slim.no-external.d.ts +7 -3
  56. package/dist/module.slim.no-external.js +1 -1
  57. package/dist/module.slim.no-external.js.map +1 -1
  58. package/dist/posthog-recorder.js +1 -1
  59. package/dist/posthog-recorder.js.map +1 -1
  60. package/dist/product-tours-preview.js +1 -1
  61. package/dist/product-tours-preview.js.map +1 -1
  62. package/dist/product-tours.js +1 -1
  63. package/dist/product-tours.js.map +1 -1
  64. package/dist/recorder-v2.js +1 -1
  65. package/dist/recorder-v2.js.map +1 -1
  66. package/dist/recorder.js +1 -1
  67. package/dist/recorder.js.map +1 -1
  68. package/dist/rrweb.d.ts +1 -0
  69. package/dist/rrweb.js +1 -1
  70. package/dist/rrweb.js.map +1 -1
  71. package/dist/src/constants.d.ts +2 -0
  72. package/dist/src/extensions/replay/external/lazy-loaded-session-recorder.d.ts +1 -0
  73. package/dist/src/posthog-core.d.ts +5 -2
  74. package/dist/src/posthog-persistence.d.ts +2 -1
  75. package/dist/surveys-preview.js +1 -1
  76. package/dist/surveys-preview.js.map +1 -1
  77. package/dist/surveys.js +1 -1
  78. package/dist/surveys.js.map +1 -1
  79. package/dist/tracing-headers.js +1 -1
  80. package/dist/tracing-headers.js.map +1 -1
  81. package/dist/web-vitals-soft-navs.js +1 -1
  82. package/dist/web-vitals-soft-navs.js.map +1 -1
  83. package/dist/web-vitals-with-attribution-soft-navs.js +1 -1
  84. package/dist/web-vitals-with-attribution-soft-navs.js.map +1 -1
  85. package/dist/web-vitals-with-attribution.js +1 -1
  86. package/dist/web-vitals-with-attribution.js.map +1 -1
  87. package/dist/web-vitals.js +1 -1
  88. package/dist/web-vitals.js.map +1 -1
  89. package/lib/package.json +6 -7
  90. package/lib/src/constants.d.ts +2 -0
  91. package/lib/src/constants.js +5 -3
  92. package/lib/src/constants.js.map +1 -1
  93. package/lib/src/extensions/replay/external/lazy-loaded-session-recorder.d.ts +1 -0
  94. package/lib/src/extensions/replay/external/lazy-loaded-session-recorder.js +24 -16
  95. package/lib/src/extensions/replay/external/lazy-loaded-session-recorder.js.map +1 -1
  96. package/lib/src/persistence-key-policy.js +1 -0
  97. package/lib/src/persistence-key-policy.js.map +1 -1
  98. package/lib/src/posthog-core.d.ts +5 -2
  99. package/lib/src/posthog-core.js +109 -21
  100. package/lib/src/posthog-core.js.map +1 -1
  101. package/lib/src/posthog-persistence.d.ts +2 -1
  102. package/lib/src/posthog-persistence.js +22 -5
  103. package/lib/src/posthog-persistence.js.map +1 -1
  104. package/lib/src/scroll-manager.js +6 -4
  105. package/lib/src/scroll-manager.js.map +1 -1
  106. package/lib/src/storage.js +1 -0
  107. package/lib/src/storage.js.map +1 -1
  108. package/package.json +11 -20
  109. package/react/dist/esm/index.js +232 -256
  110. package/react/dist/esm/index.js.map +1 -1
  111. package/react/dist/esm/slim/index.js +205 -225
  112. package/react/dist/esm/slim/index.js.map +1 -1
  113. package/react/dist/esm/surveys/index.js +48 -74
  114. package/react/dist/esm/surveys/index.js.map +1 -1
  115. package/react/dist/types/index.d.ts +72 -65
  116. package/react/dist/types/slim/index.d.ts +67 -60
  117. package/react/dist/types/surveys/index.d.ts +15 -16
  118. package/react/dist/umd/index.js +287 -289
  119. package/react/dist/umd/index.js.map +1 -1
  120. package/react/dist/umd/slim/index.js +253 -255
  121. package/react/dist/umd/slim/index.js.map +1 -1
  122. package/react/dist/umd/surveys/index.js +91 -91
  123. package/react/dist/umd/surveys/index.js.map +1 -1
@@ -1,25 +1,63 @@
1
- import React, { createContext, useMemo, useContext, useState, useEffect, useRef, useCallback, Children } from 'react';
2
-
3
- var defaultPostHogInstance;
4
- function getDefaultPostHogInstance() {
5
- return defaultPostHogInstance;
6
- }
7
-
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
28
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
29
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
30
+ };
31
+ var __rest = (this && this.__rest) || function (s, e) {
32
+ var t = {};
33
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
34
+ t[p] = s[p];
35
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
36
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
37
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
38
+ t[p[i]] = s[p[i]];
39
+ }
40
+ return t;
41
+ };
42
+ var _a;
43
+ import React, { Children, createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
8
44
  var PostHogContext = createContext({
9
- get client() {
10
- return getDefaultPostHogInstance();
11
- },
12
- bootstrap: undefined,
45
+ get client() { },
46
+ bootstrap: void 0
13
47
  });
14
-
15
- function PostHogProvider(_a) {
16
- var client = _a.client, children = _a.children;
17
- var value = useMemo(function () { var _a; return ({ client: client, bootstrap: (_a = client.config) === null || _a === void 0 ? void 0 : _a.bootstrap }); }, [client]);
48
+ function PostHogProvider(_b) {
49
+ var client = _b.client, children = _b.children;
50
+ var value = useMemo(function () {
51
+ var _b;
52
+ return ({
53
+ client: client,
54
+ bootstrap: (_b = client.config) === null || _b === void 0 ? void 0 : _b.bootstrap
55
+ });
56
+ }, [client]);
18
57
  return React.createElement(PostHogContext.Provider, { value: value }, children);
19
58
  }
20
-
21
59
  var isFunction = function (f) {
22
- return typeof f === 'function';
60
+ return typeof f === "function";
23
61
  };
24
62
  var isUndefined = function (x) {
25
63
  return x === void 0;
@@ -27,186 +65,118 @@ var isUndefined = function (x) {
27
65
  var isNull = function (x) {
28
66
  return x === null;
29
67
  };
30
-
31
68
  function useFeatureFlagEnabled(flag, defaultValue) {
32
- var _a, _b;
33
- var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
34
- var _d = useState(function () { return client.isFeatureEnabled(flag); }), featureEnabled = _d[0], setFeatureEnabled = _d[1];
69
+ var _b, _c;
70
+ var _d = useContext(PostHogContext), client = _d.client, bootstrap = _d.bootstrap;
71
+ var _e = useState(function () { return client.isFeatureEnabled(flag); }), featureEnabled = _e[0], setFeatureEnabled = _e[1];
35
72
  useEffect(function () {
36
73
  return client.onFeatureFlags(function () {
37
74
  setFeatureEnabled(client.isFeatureEnabled(flag));
38
75
  });
39
76
  }, [client, flag]);
40
- var bootstrapped = (_a = bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags) === null || _a === void 0 ? void 0 : _a[flag];
41
- if (!((_b = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _b === void 0 ? void 0 : _b.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags)) {
77
+ var bootstrapped = (_b = bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags) === null || _b === void 0 ? void 0 : _b[flag];
78
+ if (!((_c = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _c === void 0 ? void 0 : _c.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags))
42
79
  return isUndefined(bootstrapped) ? defaultValue : !!bootstrapped;
43
- }
44
80
  return isUndefined(featureEnabled) ? defaultValue : featureEnabled;
45
81
  }
46
-
47
82
  function useFeatureFlagPayload(flag) {
48
- var _a;
49
- var _b = useContext(PostHogContext), client = _b.client, bootstrap = _b.bootstrap;
50
- var _c = useState(function () { var _a; return (_a = client.getFeatureFlagResult(flag, { send_event: false })) === null || _a === void 0 ? void 0 : _a.payload; }), featureFlagPayload = _c[0], setFeatureFlagPayload = _c[1];
83
+ var _b;
84
+ var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
85
+ var _d = useState(function () { var _b; return (_b = client.getFeatureFlagResult(flag, { send_event: false })) === null || _b === void 0 ? void 0 : _b.payload; }), featureFlagPayload = _d[0], setFeatureFlagPayload = _d[1];
51
86
  useEffect(function () {
52
87
  return client.onFeatureFlags(function () {
53
- var _a;
54
- setFeatureFlagPayload((_a = client.getFeatureFlagResult(flag, { send_event: false })) === null || _a === void 0 ? void 0 : _a.payload);
88
+ var _b;
89
+ setFeatureFlagPayload((_b = client.getFeatureFlagResult(flag, { send_event: false })) === null || _b === void 0 ? void 0 : _b.payload);
55
90
  });
56
91
  }, [client, flag]);
57
- if (!((_a = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _a === void 0 ? void 0 : _a.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlagPayloads)) {
92
+ if (!((_b = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _b === void 0 ? void 0 : _b.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlagPayloads))
58
93
  return bootstrap.featureFlagPayloads[flag];
59
- }
60
94
  return featureFlagPayload;
61
95
  }
62
-
63
96
  function useFeatureFlagResult(flag) {
64
- var _a, _b;
65
- var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
66
- var _d = useState(function () { return client.getFeatureFlagResult(flag); }), result = _d[0], setResult = _d[1];
97
+ var _b, _c;
98
+ var _d = useContext(PostHogContext), client = _d.client, bootstrap = _d.bootstrap;
99
+ var _e = useState(function () { return client.getFeatureFlagResult(flag); }), result = _e[0], setResult = _e[1];
67
100
  useEffect(function () {
68
101
  return client.onFeatureFlags(function () {
69
102
  setResult(client.getFeatureFlagResult(flag));
70
103
  });
71
104
  }, [client, flag]);
72
- if (!((_a = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _a === void 0 ? void 0 : _a.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags)) {
105
+ if (!((_b = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _b === void 0 ? void 0 : _b.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags)) {
73
106
  var bootstrappedValue = bootstrap.featureFlags[flag];
74
- if (isUndefined(bootstrappedValue)) {
75
- return undefined;
76
- }
107
+ if (isUndefined(bootstrappedValue))
108
+ return;
77
109
  return {
78
110
  key: flag,
79
- enabled: typeof bootstrappedValue === 'string' ? true : !!bootstrappedValue,
80
- variant: typeof bootstrappedValue === 'string' ? bootstrappedValue : undefined,
81
- payload: (_b = bootstrap.featureFlagPayloads) === null || _b === void 0 ? void 0 : _b[flag],
111
+ enabled: typeof bootstrappedValue === "string" ? true : !!bootstrappedValue,
112
+ variant: typeof bootstrappedValue === "string" ? bootstrappedValue : void 0,
113
+ payload: (_c = bootstrap.featureFlagPayloads) === null || _c === void 0 ? void 0 : _c[flag]
82
114
  };
83
115
  }
84
116
  return result;
85
117
  }
86
-
87
118
  function useActiveFeatureFlags() {
88
- var _a;
89
- var _b = useContext(PostHogContext), client = _b.client, bootstrap = _b.bootstrap;
90
- var _c = useState(function () { return client.featureFlags.getFlags(); }), featureFlags = _c[0], setFeatureFlags = _c[1];
119
+ var _b;
120
+ var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
121
+ var _d = useState(function () { return client.featureFlags.getFlags(); }), featureFlags = _d[0], setFeatureFlags = _d[1];
91
122
  useEffect(function () {
92
123
  return client.onFeatureFlags(function (flags) {
93
124
  setFeatureFlags(flags);
94
125
  });
95
126
  }, [client]);
96
- if (!((_a = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _a === void 0 ? void 0 : _a.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags)) {
97
- return Object.entries(bootstrap.featureFlags)
98
- .filter(function (_a) {
99
- var value = _a[1];
127
+ if (!((_b = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _b === void 0 ? void 0 : _b.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags))
128
+ return Object.entries(bootstrap.featureFlags).filter(function (_b) {
129
+ var value = _b[1];
100
130
  return value;
101
- })
102
- .map(function (_a) {
103
- var key = _a[0];
131
+ }).map(function (_b) {
132
+ var key = _b[0];
104
133
  return key;
105
134
  });
106
- }
107
135
  return featureFlags;
108
136
  }
109
-
110
137
  function useFeatureFlagVariantKey(flag) {
111
- var _a;
112
- var _b = useContext(PostHogContext), client = _b.client, bootstrap = _b.bootstrap;
113
- var _c = useState(function () {
114
- return client.getFeatureFlag(flag);
115
- }), featureFlagVariantKey = _c[0], setFeatureFlagVariantKey = _c[1];
138
+ var _b;
139
+ var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
140
+ var _d = useState(function () { return client.getFeatureFlag(flag); }), featureFlagVariantKey = _d[0], setFeatureFlagVariantKey = _d[1];
116
141
  useEffect(function () {
117
142
  return client.onFeatureFlags(function () {
118
143
  setFeatureFlagVariantKey(client.getFeatureFlag(flag));
119
144
  });
120
145
  }, [client, flag]);
121
- if (!((_a = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _a === void 0 ? void 0 : _a.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags)) {
146
+ if (!((_b = client === null || client === void 0 ? void 0 : client.featureFlags) === null || _b === void 0 ? void 0 : _b.hasLoadedFlags) && (bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags))
122
147
  return bootstrap.featureFlags[flag];
123
- }
124
148
  return featureFlagVariantKey;
125
149
  }
126
-
127
150
  var usePostHog = function () {
128
151
  var client = useContext(PostHogContext).client;
129
152
  return client;
130
153
  };
131
-
132
- /******************************************************************************
133
- Copyright (c) Microsoft Corporation.
134
-
135
- Permission to use, copy, modify, and/or distribute this software for any
136
- purpose with or without fee is hereby granted.
137
-
138
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
139
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
140
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
141
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
142
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
143
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
144
- PERFORMANCE OF THIS SOFTWARE.
145
- ***************************************************************************** */
146
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
147
-
148
- var extendStatics = function(d, b) {
149
- extendStatics = Object.setPrototypeOf ||
150
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
151
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
152
- return extendStatics(d, b);
153
- };
154
-
155
- function __extends(d, b) {
156
- if (typeof b !== "function" && b !== null)
157
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
158
- extendStatics(d, b);
159
- function __() { this.constructor = d; }
160
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
161
- }
162
-
163
- var __assign = function() {
164
- __assign = Object.assign || function __assign(t) {
165
- for (var s, i = 1, n = arguments.length; i < n; i++) {
166
- s = arguments[i];
167
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
168
- }
169
- return t;
170
- };
171
- return __assign.apply(this, arguments);
172
- };
173
-
174
- function __rest(s, e) {
175
- var t = {};
176
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
177
- t[p] = s[p];
178
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
179
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
180
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
181
- t[p[i]] = s[p[i]];
182
- }
183
- return t;
184
- }
185
-
186
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
187
- var e = new Error(message);
188
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
189
- };
190
-
191
- function VisibilityAndClickTracker(_a) {
192
- var children = _a.children, onIntersect = _a.onIntersect, onClick = _a.onClick, trackView = _a.trackView, options = _a.options, props = __rest(_a, ["children", "onIntersect", "onClick", "trackView", "options"]);
154
+ function VisibilityAndClickTracker(_b) {
155
+ var children = _b.children, onIntersect = _b.onIntersect, onClick = _b.onClick, trackView = _b.trackView, options = _b.options, props = __rest(_b, ["children", "onIntersect", "onClick", "trackView", "options"]);
193
156
  var ref = useRef(null);
194
- var observerOptions = useMemo(function () { return (__assign({ threshold: 0.1 }, options)); }, [options === null || options === void 0 ? void 0 : options.threshold, options === null || options === void 0 ? void 0 : options.root, options === null || options === void 0 ? void 0 : options.rootMargin]);
157
+ var observerOptions = useMemo(function () { return (__assign({ threshold: .1 }, options)); }, [
158
+ options === null || options === void 0 ? void 0 : options.threshold,
159
+ options === null || options === void 0 ? void 0 : options.root,
160
+ options === null || options === void 0 ? void 0 : options.rootMargin
161
+ ]);
195
162
  useEffect(function () {
196
163
  if (isNull(ref.current) || !trackView)
197
164
  return;
198
- var observer = new IntersectionObserver(function (_a) {
199
- var entry = _a[0];
165
+ var observer = new IntersectionObserver(function (_b) {
166
+ var entry = _b[0];
200
167
  return onIntersect(entry);
201
168
  }, observerOptions);
202
169
  observer.observe(ref.current);
203
170
  return function () { return observer.disconnect(); };
204
- }, [observerOptions, trackView, onIntersect]);
205
- return (React.createElement("div", __assign({ ref: ref }, props, { onClick: onClick }), children));
171
+ }, [
172
+ observerOptions,
173
+ trackView,
174
+ onIntersect
175
+ ]);
176
+ return React.createElement("div", __assign(__assign({ ref: ref }, props), { onClick: onClick }), children);
206
177
  }
207
-
208
- function VisibilityAndClickTrackers(_a) {
209
- var children = _a.children, trackInteraction = _a.trackInteraction, trackView = _a.trackView, options = _a.options, onInteract = _a.onInteract, onView = _a.onView, props = __rest(_a, ["children", "trackInteraction", "trackView", "options", "onInteract", "onView"]);
178
+ function VisibilityAndClickTrackers(_b) {
179
+ var children = _b.children, trackInteraction = _b.trackInteraction, trackView = _b.trackView, options = _b.options, onInteract = _b.onInteract, onView = _b.onView, props = __rest(_b, ["children", "trackInteraction", "trackView", "options", "onInteract", "onView"]);
210
180
  var clickTrackedRef = useRef(false);
211
181
  var visibilityTrackedRef = useRef(false);
212
182
  var cachedOnClick = useCallback(function () {
@@ -222,13 +192,12 @@ function VisibilityAndClickTrackers(_a) {
222
192
  }
223
193
  };
224
194
  var trackedChildren = Children.map(children, function (child) {
225
- return (React.createElement(VisibilityAndClickTracker, __assign({ onClick: cachedOnClick, onIntersect: onIntersect, trackView: trackView, options: options }, props), child));
195
+ return React.createElement(VisibilityAndClickTracker, __assign({ onClick: cachedOnClick, onIntersect: onIntersect, trackView: trackView, options: options }, props), child);
226
196
  });
227
197
  return React.createElement(React.Fragment, null, trackedChildren);
228
198
  }
229
-
230
- function PostHogFeature(_a) {
231
- var flag = _a.flag, match = _a.match, children = _a.children, fallback = _a.fallback, visibilityObserverOptions = _a.visibilityObserverOptions, trackInteraction = _a.trackInteraction, trackView = _a.trackView, props = __rest(_a, ["flag", "match", "children", "fallback", "visibilityObserverOptions", "trackInteraction", "trackView"]);
199
+ function PostHogFeature(_b) {
200
+ var flag = _b.flag, match = _b.match, children = _b.children, fallback = _b.fallback, visibilityObserverOptions = _b.visibilityObserverOptions, trackInteraction = _b.trackInteraction, trackView = _b.trackView, props = __rest(_b, ["flag", "match", "children", "fallback", "visibilityObserverOptions", "trackInteraction", "trackView"]);
232
201
  var payload = useFeatureFlagPayload(flag);
233
202
  var variant = useFeatureFlagVariantKey(flag);
234
203
  var posthog = usePostHog();
@@ -237,68 +206,89 @@ function PostHogFeature(_a) {
237
206
  if (!isUndefined(variant)) {
238
207
  if (isUndefined(match) || variant === match) {
239
208
  var childNode = isFunction(children) ? children(payload) : children;
240
- return (React.createElement(VisibilityAndClickTrackers, __assign({ flag: flag, options: visibilityObserverOptions, trackInteraction: shouldTrackInteraction, trackView: shouldTrackView, onInteract: function () { return captureFeatureInteraction({ flag: flag, posthog: posthog, flagVariant: variant }); }, onView: function () { return captureFeatureView({ flag: flag, posthog: posthog, flagVariant: variant }); } }, props), childNode));
209
+ return React.createElement(VisibilityAndClickTrackers, __assign({ flag: flag, options: visibilityObserverOptions, trackInteraction: shouldTrackInteraction, trackView: shouldTrackView, onInteract: function () { return captureFeatureInteraction({
210
+ flag: flag,
211
+ posthog: posthog,
212
+ flagVariant: variant
213
+ }); }, onView: function () { return captureFeatureView({
214
+ flag: flag,
215
+ posthog: posthog,
216
+ flagVariant: variant
217
+ }); } }, props), childNode);
241
218
  }
242
219
  }
243
220
  return React.createElement(React.Fragment, null, fallback);
244
221
  }
245
- function captureFeatureEvent(event, _a) {
246
- var _b;
247
- var flag = _a.flag, posthog = _a.posthog, flagVariant = _a.flagVariant;
222
+ function captureFeatureEvent(event, _b) {
223
+ var _c;
224
+ var flag = _b.flag, posthog = _b.posthog, flagVariant = _b.flagVariant;
248
225
  var properties = {
249
226
  feature_flag: flag,
250
- $set: (_b = {}, _b["".concat(event, "/").concat(flag)] = flagVariant !== null && flagVariant !== void 0 ? flagVariant : true, _b),
227
+ $set: (_c = {}, _c["".concat(event, "/").concat(flag)] = flagVariant !== null && flagVariant !== void 0 ? flagVariant : true, _c)
251
228
  };
252
- if (typeof flagVariant === 'string') {
229
+ if (typeof flagVariant === "string")
253
230
  properties.feature_flag_variant = flagVariant;
254
- }
255
231
  posthog.capture(event, properties);
256
232
  }
257
233
  function captureFeatureInteraction(options) {
258
- captureFeatureEvent('$feature_interaction', options);
234
+ captureFeatureEvent("$feature_interaction", options);
259
235
  }
260
236
  function captureFeatureView(options) {
261
- captureFeatureEvent('$feature_view', options);
237
+ captureFeatureEvent("$feature_view", options);
262
238
  }
263
-
264
- function TrackedChild(_a) {
265
- var child = _a.child, index = _a.index, name = _a.name, properties = _a.properties, observerOptions = _a.observerOptions;
239
+ function TrackedChild(_b) {
240
+ var child = _b.child, index = _b.index, name = _b.name, properties = _b.properties, observerOptions = _b.observerOptions;
266
241
  var trackedRef = useRef(false);
267
242
  var posthog = usePostHog();
268
243
  var onIntersect = useCallback(function (entry) {
269
244
  if (entry.isIntersecting && !trackedRef.current) {
270
- posthog.capture('$element_viewed', __assign({ element_name: name, child_index: index }, properties));
245
+ posthog.capture("$element_viewed", __assign({ element_name: name, child_index: index }, properties));
271
246
  trackedRef.current = true;
272
247
  }
273
- }, [posthog, name, index, properties]);
274
- return (React.createElement(VisibilityAndClickTracker, { onIntersect: onIntersect, trackView: true, options: observerOptions }, child));
248
+ }, [
249
+ posthog,
250
+ name,
251
+ index,
252
+ properties
253
+ ]);
254
+ return React.createElement(VisibilityAndClickTracker, {
255
+ onIntersect: onIntersect,
256
+ trackView: true,
257
+ options: observerOptions
258
+ }, child);
275
259
  }
276
- function PostHogCaptureOnViewed(_a) {
277
- var name = _a.name, properties = _a.properties, observerOptions = _a.observerOptions, trackAllChildren = _a.trackAllChildren, children = _a.children, props = __rest(_a, ["name", "properties", "observerOptions", "trackAllChildren", "children"]);
260
+ function PostHogCaptureOnViewed(_b) {
261
+ var name = _b.name, properties = _b.properties, observerOptions = _b.observerOptions, trackAllChildren = _b.trackAllChildren, children = _b.children, props = __rest(_b, ["name", "properties", "observerOptions", "trackAllChildren", "children"]);
278
262
  var trackedRef = useRef(false);
279
263
  var posthog = usePostHog();
280
264
  var onIntersect = useCallback(function (entry) {
281
265
  if (entry.isIntersecting && !trackedRef.current) {
282
- posthog.capture('$element_viewed', __assign({ element_name: name }, properties));
266
+ posthog.capture("$element_viewed", __assign({ element_name: name }, properties));
283
267
  trackedRef.current = true;
284
268
  }
285
- }, [posthog, name, properties]);
269
+ }, [
270
+ posthog,
271
+ name,
272
+ properties
273
+ ]);
286
274
  if (trackAllChildren) {
287
275
  var trackedChildren = Children.map(children, function (child, index) {
288
- return (React.createElement(TrackedChild, { key: index, child: child, index: index, name: name, properties: properties, observerOptions: observerOptions }));
276
+ return React.createElement(TrackedChild, {
277
+ key: index,
278
+ child: child,
279
+ index: index,
280
+ name: name,
281
+ properties: properties,
282
+ observerOptions: observerOptions
283
+ });
289
284
  });
290
- return React.createElement("div", __assign({}, props), trackedChildren);
285
+ return React.createElement("div", props, trackedChildren);
291
286
  }
292
- return (React.createElement(VisibilityAndClickTracker, __assign({ onIntersect: onIntersect, trackView: true, options: observerOptions }, props), children));
287
+ return React.createElement(VisibilityAndClickTracker, __assign({ onIntersect: onIntersect, trackView: true, options: observerOptions }, props), children);
293
288
  }
294
-
295
289
  var isError = function (value) {
296
290
  var tag = Object.prototype.toString.call(value);
297
- return (value instanceof Error ||
298
- tag === '[object Error]' ||
299
- tag === '[object Exception]' ||
300
- tag === '[object DOMException]' ||
301
- tag === '[object DOMError]');
291
+ return value instanceof Error || tag === "[object Error]" || tag === "[object Exception]" || tag === "[object DOMException]" || tag === "[object DOMError]";
302
292
  };
303
293
  var setCause = function (error, cause) {
304
294
  var seenErrors = new WeakSet();
@@ -306,9 +296,8 @@ var setCause = function (error, cause) {
306
296
  while (!seenErrors.has(currentError)) {
307
297
  seenErrors.add(currentError);
308
298
  if (!isError(currentError.cause)) {
309
- if (!isUndefined(currentError.cause)) {
299
+ if (!isUndefined(currentError.cause))
310
300
  cause.cause = currentError.cause;
311
- }
312
301
  currentError.cause = cause;
313
302
  return;
314
303
  }
@@ -316,11 +305,10 @@ var setCause = function (error, cause) {
316
305
  }
317
306
  };
318
307
  var addReactComponentStack = function (error, componentStack) {
319
- if (!componentStack) {
308
+ if (!componentStack)
320
309
  return error;
321
- }
322
310
  var componentStackError = new Error(isError(error) ? error.message : "Primitive value captured as exception: ".concat(String(error)));
323
- componentStackError.name = "React ErrorBoundary ".concat(isError(error) ? error.name : 'Error');
311
+ componentStackError.name = "React ErrorBoundary ".concat(isError(error) ? error.name : "Error");
324
312
  componentStackError.stack = componentStack;
325
313
  if (isError(error)) {
326
314
  setCause(error, componentStackError);
@@ -328,71 +316,63 @@ var addReactComponentStack = function (error, componentStack) {
328
316
  }
329
317
  return componentStackError;
330
318
  };
331
-
332
319
  var INITIAL_STATE = {
333
320
  componentStack: null,
334
321
  exceptionEvent: null,
335
- error: null,
336
- };
337
- var __POSTHOG_ERROR_MESSAGES = {
338
- INVALID_FALLBACK: '[PostHog.js][PostHogErrorBoundary] Invalid fallback prop, provide a valid React element or a function that returns a valid React element.',
322
+ error: null
339
323
  };
340
- var PostHogErrorBoundary = (function (_super) {
341
- __extends(PostHogErrorBoundary, _super);
342
- function PostHogErrorBoundary(props) {
343
- var _this = _super.call(this, props) || this;
344
- _this.state = INITIAL_STATE;
345
- return _this;
346
- }
347
- PostHogErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
348
- var additionalProperties = this.props.additionalProperties;
349
- var currentProperties;
350
- if (isFunction(additionalProperties)) {
351
- currentProperties = additionalProperties(error, errorInfo);
352
- }
353
- else if (typeof additionalProperties === 'object') {
354
- currentProperties = additionalProperties;
355
- }
356
- var client = this.context.client;
357
- var componentStack = errorInfo.componentStack;
358
- var exceptionEvent = client.captureException(addReactComponentStack(error, componentStack), currentProperties);
359
- this.setState({
360
- error: error,
361
- componentStack: componentStack !== null && componentStack !== void 0 ? componentStack : null,
362
- exceptionEvent: exceptionEvent,
363
- });
364
- };
365
- PostHogErrorBoundary.prototype.render = function () {
366
- var _a = this.props, children = _a.children, fallback = _a.fallback;
367
- var state = this.state;
368
- if (state.componentStack == null) {
369
- return isFunction(children) ? children() : children;
324
+ var __POSTHOG_ERROR_MESSAGES = { INVALID_FALLBACK: "[PostHog.js][PostHogErrorBoundary] Invalid fallback prop, provide a valid React element or a function that returns a valid React element." };
325
+ var PostHogErrorBoundary = (_a = (function (_super) {
326
+ __extends(class_1, _super);
327
+ function class_1(props) {
328
+ var _this = _super.call(this, props) || this;
329
+ _this.state = INITIAL_STATE;
330
+ return _this;
370
331
  }
371
- var element = isFunction(fallback)
372
- ? React.createElement(fallback, {
332
+ class_1.prototype.componentDidCatch = function (error, errorInfo) {
333
+ var additionalProperties = this.props.additionalProperties;
334
+ var currentProperties;
335
+ if (isFunction(additionalProperties))
336
+ currentProperties = additionalProperties(error, errorInfo);
337
+ else if (typeof additionalProperties === "object")
338
+ currentProperties = additionalProperties;
339
+ var client = this.context.client;
340
+ var componentStack = errorInfo.componentStack;
341
+ var exceptionEvent = client.captureException(addReactComponentStack(error, componentStack), currentProperties);
342
+ this.setState({
343
+ error: error,
344
+ componentStack: componentStack !== null && componentStack !== void 0 ? componentStack : null,
345
+ exceptionEvent: exceptionEvent
346
+ });
347
+ };
348
+ class_1.prototype.render = function () {
349
+ var _b = this.props, children = _b.children, fallback = _b.fallback;
350
+ var state = this.state;
351
+ if (state.componentStack == null)
352
+ return isFunction(children) ? children() : children;
353
+ var element = isFunction(fallback) ? React.createElement(fallback, {
373
354
  error: state.error,
374
355
  componentStack: state.componentStack,
375
- exceptionEvent: state.exceptionEvent,
376
- })
377
- : fallback;
378
- if (React.isValidElement(element)) {
379
- return element;
380
- }
381
- console.warn(__POSTHOG_ERROR_MESSAGES.INVALID_FALLBACK);
382
- return React.createElement(React.Fragment, null);
383
- };
384
- PostHogErrorBoundary.contextType = PostHogContext;
385
- return PostHogErrorBoundary;
386
- }(React.Component));
387
-
356
+ exceptionEvent: state.exceptionEvent
357
+ }) : fallback;
358
+ if (React.isValidElement(element))
359
+ return element;
360
+ console.warn(__POSTHOG_ERROR_MESSAGES.INVALID_FALLBACK);
361
+ return React.createElement(React.Fragment, null);
362
+ };
363
+ return class_1;
364
+ }(React.Component)),
365
+ __setFunctionName(_a, "PostHogErrorBoundary"),
366
+ (function () {
367
+ _a.contextType = PostHogContext;
368
+ })(),
369
+ _a);
388
370
  var setupReactErrorHandler = function (client, callback) {
389
371
  return function (error, errorInfo) {
390
372
  var event = client.captureException(addReactComponentStack(error, errorInfo.componentStack));
391
- if (callback) {
373
+ if (callback)
392
374
  callback(event, error, errorInfo);
393
- }
394
375
  };
395
376
  };
396
-
397
377
  export { PostHogCaptureOnViewed, PostHogContext, PostHogErrorBoundary, PostHogFeature, PostHogProvider, captureFeatureInteraction, captureFeatureView, setupReactErrorHandler, useActiveFeatureFlags, useFeatureFlagEnabled, useFeatureFlagPayload, useFeatureFlagResult, useFeatureFlagVariantKey, usePostHog };
398
- //# sourceMappingURL=index.js.map
378
+ //# sourceMappingURL=index.js.map