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