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,6 +1,47 @@
1
- import posthogJs from 'posthog-js';
2
- import React, { createContext, useRef, useMemo, useEffect, useContext, useState, useCallback, Children } from 'react';
3
-
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 posthogJs from "posthog-js";
44
+ import React, { Children, createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
4
45
  var defaultPostHogInstance;
5
46
  function setDefaultPostHogInstance(instance) {
6
47
  defaultPostHogInstance = instance;
@@ -8,98 +49,92 @@ function setDefaultPostHogInstance(instance) {
8
49
  function getDefaultPostHogInstance() {
9
50
  return defaultPostHogInstance;
10
51
  }
11
-
12
52
  var PostHogContext = createContext({
13
53
  get client() {
14
54
  return getDefaultPostHogInstance();
15
55
  },
16
- bootstrap: undefined,
56
+ bootstrap: void 0
17
57
  });
18
-
19
58
  function isDeepEqual(obj1, obj2, visited) {
20
59
  if (visited === void 0) { visited = new WeakMap(); }
21
- if (obj1 === obj2) {
60
+ if (obj1 === obj2)
22
61
  return true;
23
- }
24
- if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
62
+ if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null)
25
63
  return false;
26
- }
27
- if (visited.has(obj1) && visited.get(obj1) === obj2) {
64
+ if (visited.has(obj1) && visited.get(obj1) === obj2)
28
65
  return true;
29
- }
30
66
  visited.set(obj1, obj2);
31
67
  var keys1 = Object.keys(obj1);
32
68
  var keys2 = Object.keys(obj2);
33
- if (keys1.length !== keys2.length) {
69
+ if (keys1.length !== keys2.length)
34
70
  return false;
35
- }
36
71
  for (var _i = 0, keys1_1 = keys1; _i < keys1_1.length; _i++) {
37
72
  var key = keys1_1[_i];
38
- if (!keys2.includes(key)) {
73
+ if (!keys2.includes(key))
39
74
  return false;
40
- }
41
- if (!isDeepEqual(obj1[key], obj2[key], visited)) {
75
+ if (!isDeepEqual(obj1[key], obj2[key], visited))
42
76
  return false;
43
- }
44
77
  }
45
78
  return true;
46
79
  }
47
-
48
- function PostHogProvider(_a) {
49
- var _b, _c;
50
- var children = _a.children, client = _a.client, apiKey = _a.apiKey, options = _a.options;
80
+ function PostHogProvider(_b) {
81
+ var _c, _d;
82
+ var children = _b.children, client = _b.client, apiKey = _b.apiKey, options = _b.options;
51
83
  var previousInitializationRef = useRef(null);
52
84
  var posthog = useMemo(function () {
53
85
  if (client) {
54
- if (apiKey) {
55
- console.warn('[PostHog.js] You have provided both `client` and `apiKey` to `PostHogProvider`. `apiKey` will be ignored in favour of `client`.');
56
- }
57
- if (options) {
58
- console.warn('[PostHog.js] You have provided both `client` and `options` to `PostHogProvider`. `options` will be ignored in favour of `client`.');
59
- }
86
+ if (apiKey)
87
+ console.warn("[PostHog.js] You have provided both `client` and `apiKey` to `PostHogProvider`. `apiKey` will be ignored in favour of `client`.");
88
+ if (options)
89
+ console.warn("[PostHog.js] You have provided both `client` and `options` to `PostHogProvider`. `options` will be ignored in favour of `client`.");
60
90
  return client;
61
91
  }
62
92
  var defaultInstance = getDefaultPostHogInstance();
63
- if (apiKey) {
93
+ if (apiKey)
64
94
  return defaultInstance;
65
- }
66
- console.warn('[PostHog.js] No `apiKey` or `client` were provided to `PostHogProvider`. Using default global `window.posthog` instance. You must initialize it manually. This is not recommended behavior.');
95
+ console.warn("[PostHog.js] No `apiKey` or `client` were provided to `PostHogProvider`. Using default global `window.posthog` instance. You must initialize it manually. This is not recommended behavior.");
67
96
  return defaultInstance;
68
- }, [client, apiKey, JSON.stringify(options)]);
97
+ }, [
98
+ client,
99
+ apiKey,
100
+ JSON.stringify(options)
101
+ ]);
69
102
  useEffect(function () {
70
- if (client || !apiKey) {
103
+ if (client || !apiKey)
71
104
  return;
72
- }
73
105
  var defaultInstance = getDefaultPostHogInstance();
74
106
  var previousInitialization = previousInitializationRef.current;
75
107
  if (!previousInitialization) {
76
- if (defaultInstance.__loaded) {
77
- console.warn('[PostHog.js] `posthog` was already loaded elsewhere. This may cause issues.');
78
- }
108
+ if (defaultInstance.__loaded)
109
+ console.warn("[PostHog.js] `posthog` was already loaded elsewhere. This may cause issues.");
79
110
  defaultInstance.init(apiKey, options);
80
111
  previousInitializationRef.current = {
81
112
  apiKey: apiKey,
82
- options: options !== null && options !== void 0 ? options : {},
113
+ options: options !== null && options !== void 0 ? options : {}
83
114
  };
84
115
  }
85
116
  else {
86
- if (apiKey !== previousInitialization.apiKey) {
117
+ if (apiKey !== previousInitialization.apiKey)
87
118
  console.warn("[PostHog.js] You have provided a different `apiKey` to `PostHogProvider` than the one that was already initialized. This is not supported by our provider and we'll keep using the previous key. If you need to toggle between API Keys you need to control the `client` yourself and pass it in as a prop rather than an `apiKey` prop.");
88
- }
89
- if (options && !isDeepEqual(options, previousInitialization.options)) {
119
+ if (options && !isDeepEqual(options, previousInitialization.options))
90
120
  defaultInstance.set_config(options);
91
- }
92
121
  previousInitializationRef.current = {
93
122
  apiKey: apiKey,
94
- options: options !== null && options !== void 0 ? options : {},
123
+ options: options !== null && options !== void 0 ? options : {}
95
124
  };
96
125
  }
97
- }, [client, apiKey, JSON.stringify(options)]);
98
- return (React.createElement(PostHogContext.Provider, { value: { client: posthog, bootstrap: (_b = options === null || options === void 0 ? void 0 : options.bootstrap) !== null && _b !== void 0 ? _b : (_c = client === null || client === void 0 ? void 0 : client.config) === null || _c === void 0 ? void 0 : _c.bootstrap } }, children));
126
+ }, [
127
+ client,
128
+ apiKey,
129
+ JSON.stringify(options)
130
+ ]);
131
+ return React.createElement(PostHogContext.Provider, { value: {
132
+ client: posthog,
133
+ bootstrap: (_c = options === null || options === void 0 ? void 0 : options.bootstrap) !== null && _c !== void 0 ? _c : (_d = client === null || client === void 0 ? void 0 : client.config) === null || _d === void 0 ? void 0 : _d.bootstrap
134
+ } }, children);
99
135
  }
100
-
101
136
  var isFunction = function (f) {
102
- return typeof f === 'function';
137
+ return typeof f === "function";
103
138
  };
104
139
  var isUndefined = function (x) {
105
140
  return x === void 0;
@@ -107,186 +142,118 @@ var isUndefined = function (x) {
107
142
  var isNull = function (x) {
108
143
  return x === null;
109
144
  };
110
-
111
145
  function useFeatureFlagEnabled(flag, defaultValue) {
112
- var _a, _b;
113
- var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
114
- var _d = useState(function () { return client.isFeatureEnabled(flag); }), featureEnabled = _d[0], setFeatureEnabled = _d[1];
146
+ var _b, _c;
147
+ var _d = useContext(PostHogContext), client = _d.client, bootstrap = _d.bootstrap;
148
+ var _e = useState(function () { return client.isFeatureEnabled(flag); }), featureEnabled = _e[0], setFeatureEnabled = _e[1];
115
149
  useEffect(function () {
116
150
  return client.onFeatureFlags(function () {
117
151
  setFeatureEnabled(client.isFeatureEnabled(flag));
118
152
  });
119
153
  }, [client, flag]);
120
- var bootstrapped = (_a = bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags) === null || _a === void 0 ? void 0 : _a[flag];
121
- 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)) {
154
+ var bootstrapped = (_b = bootstrap === null || bootstrap === void 0 ? void 0 : bootstrap.featureFlags) === null || _b === void 0 ? void 0 : _b[flag];
155
+ 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))
122
156
  return isUndefined(bootstrapped) ? defaultValue : !!bootstrapped;
123
- }
124
157
  return isUndefined(featureEnabled) ? defaultValue : featureEnabled;
125
158
  }
126
-
127
159
  function useFeatureFlagPayload(flag) {
128
- var _a;
129
- var _b = useContext(PostHogContext), client = _b.client, bootstrap = _b.bootstrap;
130
- 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];
160
+ var _b;
161
+ var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
162
+ 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];
131
163
  useEffect(function () {
132
164
  return client.onFeatureFlags(function () {
133
- var _a;
134
- setFeatureFlagPayload((_a = client.getFeatureFlagResult(flag, { send_event: false })) === null || _a === void 0 ? void 0 : _a.payload);
165
+ var _b;
166
+ setFeatureFlagPayload((_b = client.getFeatureFlagResult(flag, { send_event: false })) === null || _b === void 0 ? void 0 : _b.payload);
135
167
  });
136
168
  }, [client, flag]);
137
- 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)) {
169
+ 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))
138
170
  return bootstrap.featureFlagPayloads[flag];
139
- }
140
171
  return featureFlagPayload;
141
172
  }
142
-
143
173
  function useFeatureFlagResult(flag) {
144
- var _a, _b;
145
- var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
146
- var _d = useState(function () { return client.getFeatureFlagResult(flag); }), result = _d[0], setResult = _d[1];
174
+ var _b, _c;
175
+ var _d = useContext(PostHogContext), client = _d.client, bootstrap = _d.bootstrap;
176
+ var _e = useState(function () { return client.getFeatureFlagResult(flag); }), result = _e[0], setResult = _e[1];
147
177
  useEffect(function () {
148
178
  return client.onFeatureFlags(function () {
149
179
  setResult(client.getFeatureFlagResult(flag));
150
180
  });
151
181
  }, [client, flag]);
152
- 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)) {
182
+ 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)) {
153
183
  var bootstrappedValue = bootstrap.featureFlags[flag];
154
- if (isUndefined(bootstrappedValue)) {
155
- return undefined;
156
- }
184
+ if (isUndefined(bootstrappedValue))
185
+ return;
157
186
  return {
158
187
  key: flag,
159
- enabled: typeof bootstrappedValue === 'string' ? true : !!bootstrappedValue,
160
- variant: typeof bootstrappedValue === 'string' ? bootstrappedValue : undefined,
161
- payload: (_b = bootstrap.featureFlagPayloads) === null || _b === void 0 ? void 0 : _b[flag],
188
+ enabled: typeof bootstrappedValue === "string" ? true : !!bootstrappedValue,
189
+ variant: typeof bootstrappedValue === "string" ? bootstrappedValue : void 0,
190
+ payload: (_c = bootstrap.featureFlagPayloads) === null || _c === void 0 ? void 0 : _c[flag]
162
191
  };
163
192
  }
164
193
  return result;
165
194
  }
166
-
167
195
  function useActiveFeatureFlags() {
168
- var _a;
169
- var _b = useContext(PostHogContext), client = _b.client, bootstrap = _b.bootstrap;
170
- var _c = useState(function () { return client.featureFlags.getFlags(); }), featureFlags = _c[0], setFeatureFlags = _c[1];
196
+ var _b;
197
+ var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
198
+ var _d = useState(function () { return client.featureFlags.getFlags(); }), featureFlags = _d[0], setFeatureFlags = _d[1];
171
199
  useEffect(function () {
172
200
  return client.onFeatureFlags(function (flags) {
173
201
  setFeatureFlags(flags);
174
202
  });
175
203
  }, [client]);
176
- 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)) {
177
- return Object.entries(bootstrap.featureFlags)
178
- .filter(function (_a) {
179
- var value = _a[1];
204
+ 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))
205
+ return Object.entries(bootstrap.featureFlags).filter(function (_b) {
206
+ var value = _b[1];
180
207
  return value;
181
- })
182
- .map(function (_a) {
183
- var key = _a[0];
208
+ }).map(function (_b) {
209
+ var key = _b[0];
184
210
  return key;
185
211
  });
186
- }
187
212
  return featureFlags;
188
213
  }
189
-
190
214
  function useFeatureFlagVariantKey(flag) {
191
- var _a;
192
- var _b = useContext(PostHogContext), client = _b.client, bootstrap = _b.bootstrap;
193
- var _c = useState(function () {
194
- return client.getFeatureFlag(flag);
195
- }), featureFlagVariantKey = _c[0], setFeatureFlagVariantKey = _c[1];
215
+ var _b;
216
+ var _c = useContext(PostHogContext), client = _c.client, bootstrap = _c.bootstrap;
217
+ var _d = useState(function () { return client.getFeatureFlag(flag); }), featureFlagVariantKey = _d[0], setFeatureFlagVariantKey = _d[1];
196
218
  useEffect(function () {
197
219
  return client.onFeatureFlags(function () {
198
220
  setFeatureFlagVariantKey(client.getFeatureFlag(flag));
199
221
  });
200
222
  }, [client, flag]);
201
- 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)) {
223
+ 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))
202
224
  return bootstrap.featureFlags[flag];
203
- }
204
225
  return featureFlagVariantKey;
205
226
  }
206
-
207
227
  var usePostHog = function () {
208
228
  var client = useContext(PostHogContext).client;
209
229
  return client;
210
230
  };
211
-
212
- /******************************************************************************
213
- Copyright (c) Microsoft Corporation.
214
-
215
- Permission to use, copy, modify, and/or distribute this software for any
216
- purpose with or without fee is hereby granted.
217
-
218
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
219
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
220
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
221
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
222
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
223
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
224
- PERFORMANCE OF THIS SOFTWARE.
225
- ***************************************************************************** */
226
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
227
-
228
- var extendStatics = function(d, b) {
229
- extendStatics = Object.setPrototypeOf ||
230
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
231
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
232
- return extendStatics(d, b);
233
- };
234
-
235
- function __extends(d, b) {
236
- if (typeof b !== "function" && b !== null)
237
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
238
- extendStatics(d, b);
239
- function __() { this.constructor = d; }
240
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
241
- }
242
-
243
- var __assign = function() {
244
- __assign = Object.assign || function __assign(t) {
245
- for (var s, i = 1, n = arguments.length; i < n; i++) {
246
- s = arguments[i];
247
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
248
- }
249
- return t;
250
- };
251
- return __assign.apply(this, arguments);
252
- };
253
-
254
- function __rest(s, e) {
255
- var t = {};
256
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
257
- t[p] = s[p];
258
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
259
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
260
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
261
- t[p[i]] = s[p[i]];
262
- }
263
- return t;
264
- }
265
-
266
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
267
- var e = new Error(message);
268
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
269
- };
270
-
271
- function VisibilityAndClickTracker(_a) {
272
- var children = _a.children, onIntersect = _a.onIntersect, onClick = _a.onClick, trackView = _a.trackView, options = _a.options, props = __rest(_a, ["children", "onIntersect", "onClick", "trackView", "options"]);
231
+ function VisibilityAndClickTracker(_b) {
232
+ var children = _b.children, onIntersect = _b.onIntersect, onClick = _b.onClick, trackView = _b.trackView, options = _b.options, props = __rest(_b, ["children", "onIntersect", "onClick", "trackView", "options"]);
273
233
  var ref = useRef(null);
274
- 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]);
234
+ var observerOptions = useMemo(function () { return (__assign({ threshold: .1 }, options)); }, [
235
+ options === null || options === void 0 ? void 0 : options.threshold,
236
+ options === null || options === void 0 ? void 0 : options.root,
237
+ options === null || options === void 0 ? void 0 : options.rootMargin
238
+ ]);
275
239
  useEffect(function () {
276
240
  if (isNull(ref.current) || !trackView)
277
241
  return;
278
- var observer = new IntersectionObserver(function (_a) {
279
- var entry = _a[0];
242
+ var observer = new IntersectionObserver(function (_b) {
243
+ var entry = _b[0];
280
244
  return onIntersect(entry);
281
245
  }, observerOptions);
282
246
  observer.observe(ref.current);
283
247
  return function () { return observer.disconnect(); };
284
- }, [observerOptions, trackView, onIntersect]);
285
- return (React.createElement("div", __assign({ ref: ref }, props, { onClick: onClick }), children));
248
+ }, [
249
+ observerOptions,
250
+ trackView,
251
+ onIntersect
252
+ ]);
253
+ return React.createElement("div", __assign(__assign({ ref: ref }, props), { onClick: onClick }), children);
286
254
  }
287
-
288
- function VisibilityAndClickTrackers(_a) {
289
- 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"]);
255
+ function VisibilityAndClickTrackers(_b) {
256
+ 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"]);
290
257
  var clickTrackedRef = useRef(false);
291
258
  var visibilityTrackedRef = useRef(false);
292
259
  var cachedOnClick = useCallback(function () {
@@ -302,13 +269,12 @@ function VisibilityAndClickTrackers(_a) {
302
269
  }
303
270
  };
304
271
  var trackedChildren = Children.map(children, function (child) {
305
- return (React.createElement(VisibilityAndClickTracker, __assign({ onClick: cachedOnClick, onIntersect: onIntersect, trackView: trackView, options: options }, props), child));
272
+ return React.createElement(VisibilityAndClickTracker, __assign({ onClick: cachedOnClick, onIntersect: onIntersect, trackView: trackView, options: options }, props), child);
306
273
  });
307
274
  return React.createElement(React.Fragment, null, trackedChildren);
308
275
  }
309
-
310
- function PostHogFeature(_a) {
311
- 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"]);
276
+ function PostHogFeature(_b) {
277
+ 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"]);
312
278
  var payload = useFeatureFlagPayload(flag);
313
279
  var variant = useFeatureFlagVariantKey(flag);
314
280
  var posthog = usePostHog();
@@ -317,68 +283,89 @@ function PostHogFeature(_a) {
317
283
  if (!isUndefined(variant)) {
318
284
  if (isUndefined(match) || variant === match) {
319
285
  var childNode = isFunction(children) ? children(payload) : children;
320
- 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));
286
+ return React.createElement(VisibilityAndClickTrackers, __assign({ flag: flag, options: visibilityObserverOptions, trackInteraction: shouldTrackInteraction, trackView: shouldTrackView, onInteract: function () { return captureFeatureInteraction({
287
+ flag: flag,
288
+ posthog: posthog,
289
+ flagVariant: variant
290
+ }); }, onView: function () { return captureFeatureView({
291
+ flag: flag,
292
+ posthog: posthog,
293
+ flagVariant: variant
294
+ }); } }, props), childNode);
321
295
  }
322
296
  }
323
297
  return React.createElement(React.Fragment, null, fallback);
324
298
  }
325
- function captureFeatureEvent(event, _a) {
326
- var _b;
327
- var flag = _a.flag, posthog = _a.posthog, flagVariant = _a.flagVariant;
299
+ function captureFeatureEvent(event, _b) {
300
+ var _c;
301
+ var flag = _b.flag, posthog = _b.posthog, flagVariant = _b.flagVariant;
328
302
  var properties = {
329
303
  feature_flag: flag,
330
- $set: (_b = {}, _b["".concat(event, "/").concat(flag)] = flagVariant !== null && flagVariant !== void 0 ? flagVariant : true, _b),
304
+ $set: (_c = {}, _c["".concat(event, "/").concat(flag)] = flagVariant !== null && flagVariant !== void 0 ? flagVariant : true, _c)
331
305
  };
332
- if (typeof flagVariant === 'string') {
306
+ if (typeof flagVariant === "string")
333
307
  properties.feature_flag_variant = flagVariant;
334
- }
335
308
  posthog.capture(event, properties);
336
309
  }
337
310
  function captureFeatureInteraction(options) {
338
- captureFeatureEvent('$feature_interaction', options);
311
+ captureFeatureEvent("$feature_interaction", options);
339
312
  }
340
313
  function captureFeatureView(options) {
341
- captureFeatureEvent('$feature_view', options);
314
+ captureFeatureEvent("$feature_view", options);
342
315
  }
343
-
344
- function TrackedChild(_a) {
345
- var child = _a.child, index = _a.index, name = _a.name, properties = _a.properties, observerOptions = _a.observerOptions;
316
+ function TrackedChild(_b) {
317
+ var child = _b.child, index = _b.index, name = _b.name, properties = _b.properties, observerOptions = _b.observerOptions;
346
318
  var trackedRef = useRef(false);
347
319
  var posthog = usePostHog();
348
320
  var onIntersect = useCallback(function (entry) {
349
321
  if (entry.isIntersecting && !trackedRef.current) {
350
- posthog.capture('$element_viewed', __assign({ element_name: name, child_index: index }, properties));
322
+ posthog.capture("$element_viewed", __assign({ element_name: name, child_index: index }, properties));
351
323
  trackedRef.current = true;
352
324
  }
353
- }, [posthog, name, index, properties]);
354
- return (React.createElement(VisibilityAndClickTracker, { onIntersect: onIntersect, trackView: true, options: observerOptions }, child));
325
+ }, [
326
+ posthog,
327
+ name,
328
+ index,
329
+ properties
330
+ ]);
331
+ return React.createElement(VisibilityAndClickTracker, {
332
+ onIntersect: onIntersect,
333
+ trackView: true,
334
+ options: observerOptions
335
+ }, child);
355
336
  }
356
- function PostHogCaptureOnViewed(_a) {
357
- var name = _a.name, properties = _a.properties, observerOptions = _a.observerOptions, trackAllChildren = _a.trackAllChildren, children = _a.children, props = __rest(_a, ["name", "properties", "observerOptions", "trackAllChildren", "children"]);
337
+ function PostHogCaptureOnViewed(_b) {
338
+ var name = _b.name, properties = _b.properties, observerOptions = _b.observerOptions, trackAllChildren = _b.trackAllChildren, children = _b.children, props = __rest(_b, ["name", "properties", "observerOptions", "trackAllChildren", "children"]);
358
339
  var trackedRef = useRef(false);
359
340
  var posthog = usePostHog();
360
341
  var onIntersect = useCallback(function (entry) {
361
342
  if (entry.isIntersecting && !trackedRef.current) {
362
- posthog.capture('$element_viewed', __assign({ element_name: name }, properties));
343
+ posthog.capture("$element_viewed", __assign({ element_name: name }, properties));
363
344
  trackedRef.current = true;
364
345
  }
365
- }, [posthog, name, properties]);
346
+ }, [
347
+ posthog,
348
+ name,
349
+ properties
350
+ ]);
366
351
  if (trackAllChildren) {
367
352
  var trackedChildren = Children.map(children, function (child, index) {
368
- return (React.createElement(TrackedChild, { key: index, child: child, index: index, name: name, properties: properties, observerOptions: observerOptions }));
353
+ return React.createElement(TrackedChild, {
354
+ key: index,
355
+ child: child,
356
+ index: index,
357
+ name: name,
358
+ properties: properties,
359
+ observerOptions: observerOptions
360
+ });
369
361
  });
370
- return React.createElement("div", __assign({}, props), trackedChildren);
362
+ return React.createElement("div", props, trackedChildren);
371
363
  }
372
- return (React.createElement(VisibilityAndClickTracker, __assign({ onIntersect: onIntersect, trackView: true, options: observerOptions }, props), children));
364
+ return React.createElement(VisibilityAndClickTracker, __assign({ onIntersect: onIntersect, trackView: true, options: observerOptions }, props), children);
373
365
  }
374
-
375
366
  var isError = function (value) {
376
367
  var tag = Object.prototype.toString.call(value);
377
- return (value instanceof Error ||
378
- tag === '[object Error]' ||
379
- tag === '[object Exception]' ||
380
- tag === '[object DOMException]' ||
381
- tag === '[object DOMError]');
368
+ return value instanceof Error || tag === "[object Error]" || tag === "[object Exception]" || tag === "[object DOMException]" || tag === "[object DOMError]";
382
369
  };
383
370
  var setCause = function (error, cause) {
384
371
  var seenErrors = new WeakSet();
@@ -386,9 +373,8 @@ var setCause = function (error, cause) {
386
373
  while (!seenErrors.has(currentError)) {
387
374
  seenErrors.add(currentError);
388
375
  if (!isError(currentError.cause)) {
389
- if (!isUndefined(currentError.cause)) {
376
+ if (!isUndefined(currentError.cause))
390
377
  cause.cause = currentError.cause;
391
- }
392
378
  currentError.cause = cause;
393
379
  return;
394
380
  }
@@ -396,11 +382,10 @@ var setCause = function (error, cause) {
396
382
  }
397
383
  };
398
384
  var addReactComponentStack = function (error, componentStack) {
399
- if (!componentStack) {
385
+ if (!componentStack)
400
386
  return error;
401
- }
402
387
  var componentStackError = new Error(isError(error) ? error.message : "Primitive value captured as exception: ".concat(String(error)));
403
- componentStackError.name = "React ErrorBoundary ".concat(isError(error) ? error.name : 'Error');
388
+ componentStackError.name = "React ErrorBoundary ".concat(isError(error) ? error.name : "Error");
404
389
  componentStackError.stack = componentStack;
405
390
  if (isError(error)) {
406
391
  setCause(error, componentStackError);
@@ -408,73 +393,64 @@ var addReactComponentStack = function (error, componentStack) {
408
393
  }
409
394
  return componentStackError;
410
395
  };
411
-
412
396
  var INITIAL_STATE = {
413
397
  componentStack: null,
414
398
  exceptionEvent: null,
415
- error: null,
416
- };
417
- var __POSTHOG_ERROR_MESSAGES = {
418
- INVALID_FALLBACK: '[PostHog.js][PostHogErrorBoundary] Invalid fallback prop, provide a valid React element or a function that returns a valid React element.',
399
+ error: null
419
400
  };
420
- var PostHogErrorBoundary = (function (_super) {
421
- __extends(PostHogErrorBoundary, _super);
422
- function PostHogErrorBoundary(props) {
423
- var _this = _super.call(this, props) || this;
424
- _this.state = INITIAL_STATE;
425
- return _this;
426
- }
427
- PostHogErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
428
- var additionalProperties = this.props.additionalProperties;
429
- var currentProperties;
430
- if (isFunction(additionalProperties)) {
431
- currentProperties = additionalProperties(error, errorInfo);
432
- }
433
- else if (typeof additionalProperties === 'object') {
434
- currentProperties = additionalProperties;
435
- }
436
- var client = this.context.client;
437
- var componentStack = errorInfo.componentStack;
438
- var exceptionEvent = client.captureException(addReactComponentStack(error, componentStack), currentProperties);
439
- this.setState({
440
- error: error,
441
- componentStack: componentStack !== null && componentStack !== void 0 ? componentStack : null,
442
- exceptionEvent: exceptionEvent,
443
- });
444
- };
445
- PostHogErrorBoundary.prototype.render = function () {
446
- var _a = this.props, children = _a.children, fallback = _a.fallback;
447
- var state = this.state;
448
- if (state.componentStack == null) {
449
- return isFunction(children) ? children() : children;
401
+ 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." };
402
+ var PostHogErrorBoundary = (_a = (function (_super) {
403
+ __extends(class_1, _super);
404
+ function class_1(props) {
405
+ var _this = _super.call(this, props) || this;
406
+ _this.state = INITIAL_STATE;
407
+ return _this;
450
408
  }
451
- var element = isFunction(fallback)
452
- ? React.createElement(fallback, {
409
+ class_1.prototype.componentDidCatch = function (error, errorInfo) {
410
+ var additionalProperties = this.props.additionalProperties;
411
+ var currentProperties;
412
+ if (isFunction(additionalProperties))
413
+ currentProperties = additionalProperties(error, errorInfo);
414
+ else if (typeof additionalProperties === "object")
415
+ currentProperties = additionalProperties;
416
+ var client = this.context.client;
417
+ var componentStack = errorInfo.componentStack;
418
+ var exceptionEvent = client.captureException(addReactComponentStack(error, componentStack), currentProperties);
419
+ this.setState({
420
+ error: error,
421
+ componentStack: componentStack !== null && componentStack !== void 0 ? componentStack : null,
422
+ exceptionEvent: exceptionEvent
423
+ });
424
+ };
425
+ class_1.prototype.render = function () {
426
+ var _b = this.props, children = _b.children, fallback = _b.fallback;
427
+ var state = this.state;
428
+ if (state.componentStack == null)
429
+ return isFunction(children) ? children() : children;
430
+ var element = isFunction(fallback) ? React.createElement(fallback, {
453
431
  error: state.error,
454
432
  componentStack: state.componentStack,
455
- exceptionEvent: state.exceptionEvent,
456
- })
457
- : fallback;
458
- if (React.isValidElement(element)) {
459
- return element;
460
- }
461
- console.warn(__POSTHOG_ERROR_MESSAGES.INVALID_FALLBACK);
462
- return React.createElement(React.Fragment, null);
463
- };
464
- PostHogErrorBoundary.contextType = PostHogContext;
465
- return PostHogErrorBoundary;
466
- }(React.Component));
467
-
433
+ exceptionEvent: state.exceptionEvent
434
+ }) : fallback;
435
+ if (React.isValidElement(element))
436
+ return element;
437
+ console.warn(__POSTHOG_ERROR_MESSAGES.INVALID_FALLBACK);
438
+ return React.createElement(React.Fragment, null);
439
+ };
440
+ return class_1;
441
+ }(React.Component)),
442
+ __setFunctionName(_a, "PostHogErrorBoundary"),
443
+ (function () {
444
+ _a.contextType = PostHogContext;
445
+ })(),
446
+ _a);
468
447
  var setupReactErrorHandler = function (client, callback) {
469
448
  return function (error, errorInfo) {
470
449
  var event = client.captureException(addReactComponentStack(error, errorInfo.componentStack));
471
- if (callback) {
450
+ if (callback)
472
451
  callback(event, error, errorInfo);
473
- }
474
452
  };
475
453
  };
476
-
477
454
  setDefaultPostHogInstance(posthogJs);
478
-
479
455
  export { PostHogCaptureOnViewed, PostHogContext, PostHogErrorBoundary, PostHogFeature, PostHogProvider, captureFeatureInteraction, captureFeatureView, setupReactErrorHandler, useActiveFeatureFlags, useFeatureFlagEnabled, useFeatureFlagPayload, useFeatureFlagResult, useFeatureFlagVariantKey, usePostHog };
480
- //# sourceMappingURL=index.js.map
456
+ //# sourceMappingURL=index.js.map