@hanzo/insights-react 1.8.1 → 1.9.1
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.
- package/LICENSE +1 -1
- package/README.md +40 -40
- package/dist/esm/index.js +48 -48
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/surveys/index.js +12 -12
- package/dist/esm/surveys/index.js.map +1 -1
- package/dist/types/index.d.ts +29 -29
- package/dist/umd/index.js +55 -55
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/surveys/index.js +16 -16
- package/dist/umd/surveys/index.js.map +1 -1
- package/package.json +38 -32
- package/src/components/{PostHogCaptureOnViewed.tsx → InsightsCaptureOnViewed.tsx} +12 -37
- package/src/components/{PostHogErrorBoundary.tsx → InsightsErrorBoundary.tsx} +13 -13
- package/src/components/{PostHogFeature.tsx → InsightsFeature.tsx} +14 -14
- package/src/components/__tests__/{PostHogCaptureOnViewed.test.tsx → InsightsCaptureOnViewed.test.tsx} +33 -33
- package/src/components/__tests__/{PostHogErrorBoundary.test.tsx → InsightsErrorBoundary.test.tsx} +17 -17
- package/src/components/__tests__/{PostHogFeature.test.tsx → InsightsFeature.test.tsx} +73 -73
- package/src/components/index.ts +6 -6
- package/src/context/InsightsContext.ts +9 -0
- package/src/context/InsightsProvider.tsx +108 -0
- package/src/context/__tests__/{PostHogContext.test.tsx → InsightsContext.test.tsx} +9 -9
- package/src/context/__tests__/{PostHogProvider.test.tsx → InsightsProvider.test.tsx} +33 -33
- package/src/context/index.ts +2 -2
- package/src/helpers/error-helpers.ts +2 -2
- package/src/hooks/__tests__/featureFlags.test.tsx +15 -15
- package/src/hooks/__tests__/useInsights.test.tsx +19 -0
- package/src/hooks/__tests__/useThumbSurvey.test.tsx +7 -7
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useActiveFeatureFlags.ts +2 -2
- package/src/hooks/useFeatureFlagEnabled.ts +2 -2
- package/src/hooks/useFeatureFlagPayload.ts +2 -2
- package/src/hooks/useFeatureFlagResult.ts +2 -2
- package/src/hooks/useFeatureFlagVariantKey.ts +2 -2
- package/src/hooks/useInsights.ts +7 -0
- package/src/hooks/useThumbSurvey.ts +13 -13
- package/src/utils/type-utils.ts +2 -2
- package/surveys/package.json +1 -1
- package/src/context/PostHogContext.ts +0 -9
- package/src/context/PostHogProvider.tsx +0 -136
- package/src/hooks/__tests__/usePostHog.test.tsx +0 -19
- package/src/hooks/usePostHog.ts +0 -7
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @hanzo/react
|
|
2
2
|
|
|
3
|
-
React components and hooks for
|
|
3
|
+
React components and hooks for Insights analytics integration.
|
|
4
4
|
|
|
5
|
-
[SEE FULL DOCS](https://
|
|
5
|
+
[SEE FULL DOCS](https://insights.hanzo.ai/docs/libraries/react)
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm install @
|
|
10
|
+
npm install @hanzo/react @hanzo/insights
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
### Setting up the Provider
|
|
16
16
|
|
|
17
|
-
Wrap your application with `
|
|
17
|
+
Wrap your application with `InsightsProvider` to make the Insights client available throughout your app:
|
|
18
18
|
|
|
19
19
|
```tsx
|
|
20
|
-
import {
|
|
20
|
+
import { InsightsProvider } from '@hanzo/react'
|
|
21
21
|
|
|
22
22
|
function App() {
|
|
23
23
|
return (
|
|
24
|
-
<
|
|
24
|
+
<InsightsProvider apiKey="<YOUR_PROJECT_API_KEY>" options={{ api_host: 'https://us.i.insights.hanzo.ai' }}>
|
|
25
25
|
<YourApp />
|
|
26
|
-
</
|
|
26
|
+
</InsightsProvider>
|
|
27
27
|
)
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
Or pass an existing
|
|
31
|
+
Or pass an existing Insights client instance:
|
|
32
32
|
|
|
33
33
|
```tsx
|
|
34
|
-
import
|
|
35
|
-
import {
|
|
34
|
+
import insights from '@hanzo/insights'
|
|
35
|
+
import { InsightsProvider } from '@hanzo/react'
|
|
36
36
|
|
|
37
37
|
// Initialize your client
|
|
38
|
-
|
|
38
|
+
insights.init('<YOUR_PROJECT_API_KEY>', { api_host: 'https://us.i.insights.hanzo.ai' })
|
|
39
39
|
|
|
40
40
|
function App() {
|
|
41
41
|
return (
|
|
42
|
-
<
|
|
42
|
+
<InsightsProvider client={insights}>
|
|
43
43
|
<YourApp />
|
|
44
|
-
</
|
|
44
|
+
</InsightsProvider>
|
|
45
45
|
)
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
### Hooks
|
|
50
50
|
|
|
51
|
-
####
|
|
51
|
+
#### useInsights
|
|
52
52
|
|
|
53
|
-
Access the
|
|
53
|
+
Access the Insights client instance to capture events, identify users, etc.
|
|
54
54
|
|
|
55
55
|
```tsx
|
|
56
|
-
import {
|
|
56
|
+
import { useInsights } from '@hanzo/react'
|
|
57
57
|
|
|
58
58
|
function MyComponent() {
|
|
59
|
-
const
|
|
59
|
+
const insights = useInsights()
|
|
60
60
|
|
|
61
61
|
const handleClick = () => {
|
|
62
|
-
|
|
62
|
+
insights.capture('button_clicked', { button_name: 'signup' })
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
return <button onClick={handleClick}>Sign Up</button>
|
|
@@ -71,7 +71,7 @@ function MyComponent() {
|
|
|
71
71
|
Check if a feature flag is enabled for the current user.
|
|
72
72
|
|
|
73
73
|
```tsx
|
|
74
|
-
import { useFeatureFlagEnabled } from '@
|
|
74
|
+
import { useFeatureFlagEnabled } from '@hanzo/react'
|
|
75
75
|
|
|
76
76
|
function MyComponent() {
|
|
77
77
|
const isEnabled = useFeatureFlagEnabled('new-feature')
|
|
@@ -88,7 +88,7 @@ function MyComponent() {
|
|
|
88
88
|
Get the variant key for a multivariate feature flag.
|
|
89
89
|
|
|
90
90
|
```tsx
|
|
91
|
-
import { useFeatureFlagVariantKey } from '@
|
|
91
|
+
import { useFeatureFlagVariantKey } from '@hanzo/react'
|
|
92
92
|
|
|
93
93
|
function MyComponent() {
|
|
94
94
|
const variant = useFeatureFlagVariantKey('experiment-flag')
|
|
@@ -108,7 +108,7 @@ function MyComponent() {
|
|
|
108
108
|
Get the payload associated with a feature flag.
|
|
109
109
|
|
|
110
110
|
```tsx
|
|
111
|
-
import { useFeatureFlagPayload } from '@
|
|
111
|
+
import { useFeatureFlagPayload } from '@hanzo/react'
|
|
112
112
|
|
|
113
113
|
function MyComponent() {
|
|
114
114
|
const payload = useFeatureFlagPayload('feature-with-payload')
|
|
@@ -122,7 +122,7 @@ function MyComponent() {
|
|
|
122
122
|
Get all active feature flags for the current user.
|
|
123
123
|
|
|
124
124
|
```tsx
|
|
125
|
-
import { useActiveFeatureFlags } from '@
|
|
125
|
+
import { useActiveFeatureFlags } from '@hanzo/react'
|
|
126
126
|
|
|
127
127
|
function MyComponent() {
|
|
128
128
|
const activeFlags = useActiveFeatureFlags()
|
|
@@ -139,60 +139,60 @@ function MyComponent() {
|
|
|
139
139
|
|
|
140
140
|
### Components
|
|
141
141
|
|
|
142
|
-
####
|
|
142
|
+
#### InsightsFeature
|
|
143
143
|
|
|
144
144
|
A component that renders content based on a feature flag's value. Automatically tracks feature views and interactions.
|
|
145
145
|
|
|
146
146
|
```tsx
|
|
147
|
-
import {
|
|
147
|
+
import { InsightsFeature } from '@hanzo/react'
|
|
148
148
|
|
|
149
149
|
function MyComponent() {
|
|
150
150
|
return (
|
|
151
|
-
<
|
|
151
|
+
<InsightsFeature flag="new-cta" fallback={<OldButton />}>
|
|
152
152
|
<NewButton />
|
|
153
|
-
</
|
|
153
|
+
</InsightsFeature>
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
// With variant matching
|
|
158
158
|
function MyComponent() {
|
|
159
159
|
return (
|
|
160
|
-
<
|
|
160
|
+
<InsightsFeature flag="experiment" match="test" fallback={<ControlVersion />}>
|
|
161
161
|
<TestVersion />
|
|
162
|
-
</
|
|
162
|
+
</InsightsFeature>
|
|
163
163
|
)
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
// With payload as render function
|
|
167
167
|
function MyComponent() {
|
|
168
168
|
return (
|
|
169
|
-
<
|
|
169
|
+
<InsightsFeature flag="banner-config">
|
|
170
170
|
{(payload) => <Banner title={payload.title} color={payload.color} />}
|
|
171
|
-
</
|
|
171
|
+
</InsightsFeature>
|
|
172
172
|
)
|
|
173
173
|
}
|
|
174
174
|
```
|
|
175
175
|
|
|
176
|
-
####
|
|
176
|
+
#### InsightsErrorBoundary
|
|
177
177
|
|
|
178
|
-
An error boundary that captures React errors and reports them to
|
|
178
|
+
An error boundary that captures React errors and reports them to Insights.
|
|
179
179
|
|
|
180
180
|
```tsx
|
|
181
|
-
import {
|
|
181
|
+
import { InsightsErrorBoundary } from '@hanzo/react'
|
|
182
182
|
|
|
183
183
|
function App() {
|
|
184
184
|
return (
|
|
185
|
-
<
|
|
186
|
-
<
|
|
185
|
+
<InsightsProvider apiKey="<YOUR_PROJECT_API_KEY>">
|
|
186
|
+
<InsightsErrorBoundary>
|
|
187
187
|
<YourApp />
|
|
188
|
-
</
|
|
189
|
-
</
|
|
188
|
+
</InsightsErrorBoundary>
|
|
189
|
+
</InsightsProvider>
|
|
190
190
|
)
|
|
191
191
|
}
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
-
Please see the main [
|
|
194
|
+
Please see the main [Insights docs](https://www.insights.hanzo.ai/docs).
|
|
195
195
|
|
|
196
196
|
## Questions?
|
|
197
197
|
|
|
198
|
-
### [Check out our community page.](https://
|
|
198
|
+
### [Check out our community page.](https://insights.hanzo.ai/posts)
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import insightsJs from '@hanzo/insights';
|
|
2
2
|
import React, { createContext, useRef, useMemo, useEffect, useContext, useState, useCallback, Children } from 'react';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
client:
|
|
4
|
+
var InsightsContext = createContext({
|
|
5
|
+
client: insightsJs,
|
|
6
6
|
bootstrap: undefined,
|
|
7
7
|
});
|
|
8
8
|
|
|
@@ -35,25 +35,25 @@ function isDeepEqual(obj1, obj2, visited) {
|
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function
|
|
38
|
+
function InsightsProvider(_a) {
|
|
39
39
|
var _b, _c;
|
|
40
40
|
var children = _a.children, client = _a.client, apiKey = _a.apiKey, options = _a.options;
|
|
41
41
|
var previousInitializationRef = useRef(null);
|
|
42
|
-
var
|
|
42
|
+
var insights = useMemo(function () {
|
|
43
43
|
if (client) {
|
|
44
44
|
if (apiKey) {
|
|
45
|
-
console.warn('[
|
|
45
|
+
console.warn('[Insights] You have provided both `client` and `apiKey` to `InsightsProvider`. `apiKey` will be ignored in favour of `client`.');
|
|
46
46
|
}
|
|
47
47
|
if (options) {
|
|
48
|
-
console.warn('[
|
|
48
|
+
console.warn('[Insights] You have provided both `client` and `options` to `InsightsProvider`. `options` will be ignored in favour of `client`.');
|
|
49
49
|
}
|
|
50
50
|
return client;
|
|
51
51
|
}
|
|
52
52
|
if (apiKey) {
|
|
53
|
-
return
|
|
53
|
+
return insightsJs;
|
|
54
54
|
}
|
|
55
|
-
console.warn('[
|
|
56
|
-
return
|
|
55
|
+
console.warn('[Insights] No `apiKey` or `client` were provided to `InsightsProvider`. Using default global instance. You must initialize it manually. This is not recommended behavior.');
|
|
56
|
+
return insightsJs;
|
|
57
57
|
}, [client, apiKey, JSON.stringify(options)]);
|
|
58
58
|
useEffect(function () {
|
|
59
59
|
if (client) {
|
|
@@ -61,10 +61,10 @@ function PostHogProvider(_a) {
|
|
|
61
61
|
}
|
|
62
62
|
var previousInitialization = previousInitializationRef.current;
|
|
63
63
|
if (!previousInitialization) {
|
|
64
|
-
if (
|
|
65
|
-
console.warn('[
|
|
64
|
+
if (insightsJs.__loaded) {
|
|
65
|
+
console.warn('[Insights] `insights` was already loaded elsewhere. This may cause issues.');
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
insightsJs.init(apiKey, options);
|
|
68
68
|
previousInitializationRef.current = {
|
|
69
69
|
apiKey: apiKey,
|
|
70
70
|
options: options !== null && options !== void 0 ? options : {},
|
|
@@ -72,10 +72,10 @@ function PostHogProvider(_a) {
|
|
|
72
72
|
}
|
|
73
73
|
else {
|
|
74
74
|
if (apiKey !== previousInitialization.apiKey) {
|
|
75
|
-
console.warn("[
|
|
75
|
+
console.warn("[Insights] You have provided a different `apiKey` to `InsightsProvider` 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.");
|
|
76
76
|
}
|
|
77
77
|
if (options && !isDeepEqual(options, previousInitialization.options)) {
|
|
78
|
-
|
|
78
|
+
insightsJs.set_config(options);
|
|
79
79
|
}
|
|
80
80
|
previousInitializationRef.current = {
|
|
81
81
|
apiKey: apiKey,
|
|
@@ -83,7 +83,7 @@ function PostHogProvider(_a) {
|
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
}, [client, apiKey, JSON.stringify(options)]);
|
|
86
|
-
return (React.createElement(
|
|
86
|
+
return (React.createElement(InsightsContext.Provider, { value: { client: insights, 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));
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
var isFunction = function (f) {
|
|
@@ -98,7 +98,7 @@ var isNull = function (x) {
|
|
|
98
98
|
|
|
99
99
|
function useFeatureFlagEnabled(flag) {
|
|
100
100
|
var _a, _b;
|
|
101
|
-
var _c = useContext(
|
|
101
|
+
var _c = useContext(InsightsContext), client = _c.client, bootstrap = _c.bootstrap;
|
|
102
102
|
var _d = useState(function () { return client.isFeatureEnabled(flag); }), featureEnabled = _d[0], setFeatureEnabled = _d[1];
|
|
103
103
|
useEffect(function () {
|
|
104
104
|
return client.onFeatureFlags(function () {
|
|
@@ -114,7 +114,7 @@ function useFeatureFlagEnabled(flag) {
|
|
|
114
114
|
|
|
115
115
|
function useFeatureFlagPayload(flag) {
|
|
116
116
|
var _a;
|
|
117
|
-
var _b = useContext(
|
|
117
|
+
var _b = useContext(InsightsContext), client = _b.client, bootstrap = _b.bootstrap;
|
|
118
118
|
var _c = useState(function () { return client.getFeatureFlagPayload(flag); }), featureFlagPayload = _c[0], setFeatureFlagPayload = _c[1];
|
|
119
119
|
useEffect(function () {
|
|
120
120
|
return client.onFeatureFlags(function () {
|
|
@@ -129,7 +129,7 @@ function useFeatureFlagPayload(flag) {
|
|
|
129
129
|
|
|
130
130
|
function useFeatureFlagResult(flag) {
|
|
131
131
|
var _a, _b;
|
|
132
|
-
var _c = useContext(
|
|
132
|
+
var _c = useContext(InsightsContext), client = _c.client, bootstrap = _c.bootstrap;
|
|
133
133
|
var _d = useState(function () { return client.getFeatureFlagResult(flag); }), result = _d[0], setResult = _d[1];
|
|
134
134
|
useEffect(function () {
|
|
135
135
|
return client.onFeatureFlags(function () {
|
|
@@ -153,7 +153,7 @@ function useFeatureFlagResult(flag) {
|
|
|
153
153
|
|
|
154
154
|
function useActiveFeatureFlags() {
|
|
155
155
|
var _a;
|
|
156
|
-
var _b = useContext(
|
|
156
|
+
var _b = useContext(InsightsContext), client = _b.client, bootstrap = _b.bootstrap;
|
|
157
157
|
var _c = useState(function () { return client.featureFlags.getFlags(); }), featureFlags = _c[0], setFeatureFlags = _c[1];
|
|
158
158
|
useEffect(function () {
|
|
159
159
|
return client.onFeatureFlags(function (flags) {
|
|
@@ -168,7 +168,7 @@ function useActiveFeatureFlags() {
|
|
|
168
168
|
|
|
169
169
|
function useFeatureFlagVariantKey(flag) {
|
|
170
170
|
var _a;
|
|
171
|
-
var _b = useContext(
|
|
171
|
+
var _b = useContext(InsightsContext), client = _b.client, bootstrap = _b.bootstrap;
|
|
172
172
|
var _c = useState(function () {
|
|
173
173
|
return client.getFeatureFlag(flag);
|
|
174
174
|
}), featureFlagVariantKey = _c[0], setFeatureFlagVariantKey = _c[1];
|
|
@@ -183,8 +183,8 @@ function useFeatureFlagVariantKey(flag) {
|
|
|
183
183
|
return featureFlagVariantKey;
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
var
|
|
187
|
-
var client = useContext(
|
|
186
|
+
var useInsights = function () {
|
|
187
|
+
var client = useContext(InsightsContext).client;
|
|
188
188
|
return client;
|
|
189
189
|
};
|
|
190
190
|
|
|
@@ -286,24 +286,24 @@ function VisibilityAndClickTrackers(_a) {
|
|
|
286
286
|
return React.createElement(React.Fragment, null, trackedChildren);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
-
function
|
|
289
|
+
function InsightsFeature(_a) {
|
|
290
290
|
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"]);
|
|
291
291
|
var payload = useFeatureFlagPayload(flag);
|
|
292
292
|
var variant = useFeatureFlagVariantKey(flag);
|
|
293
|
-
var
|
|
293
|
+
var insights = useInsights();
|
|
294
294
|
var shouldTrackInteraction = trackInteraction !== null && trackInteraction !== void 0 ? trackInteraction : true;
|
|
295
295
|
var shouldTrackView = trackView !== null && trackView !== void 0 ? trackView : true;
|
|
296
296
|
if (!isUndefined(variant)) {
|
|
297
297
|
if (isUndefined(match) || variant === match) {
|
|
298
298
|
var childNode = isFunction(children) ? children(payload) : children;
|
|
299
|
-
return (React.createElement(VisibilityAndClickTrackers, __assign({ flag: flag, options: visibilityObserverOptions, trackInteraction: shouldTrackInteraction, trackView: shouldTrackView, onInteract: function () { return captureFeatureInteraction({ flag: flag,
|
|
299
|
+
return (React.createElement(VisibilityAndClickTrackers, __assign({ flag: flag, options: visibilityObserverOptions, trackInteraction: shouldTrackInteraction, trackView: shouldTrackView, onInteract: function () { return captureFeatureInteraction({ flag: flag, insights: insights, flagVariant: variant }); }, onView: function () { return captureFeatureView({ flag: flag, insights: insights, flagVariant: variant }); } }, props), childNode));
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
return React.createElement(React.Fragment, null, fallback);
|
|
303
303
|
}
|
|
304
304
|
function captureFeatureInteraction(_a) {
|
|
305
305
|
var _b;
|
|
306
|
-
var flag = _a.flag,
|
|
306
|
+
var flag = _a.flag, insights = _a.insights, flagVariant = _a.flagVariant;
|
|
307
307
|
var properties = {
|
|
308
308
|
feature_flag: flag,
|
|
309
309
|
$set: (_b = {}, _b["$feature_interaction/".concat(flag)] = flagVariant !== null && flagVariant !== void 0 ? flagVariant : true, _b),
|
|
@@ -311,11 +311,11 @@ function captureFeatureInteraction(_a) {
|
|
|
311
311
|
if (typeof flagVariant === 'string') {
|
|
312
312
|
properties.feature_flag_variant = flagVariant;
|
|
313
313
|
}
|
|
314
|
-
|
|
314
|
+
insights.capture('$feature_interaction', properties);
|
|
315
315
|
}
|
|
316
316
|
function captureFeatureView(_a) {
|
|
317
317
|
var _b;
|
|
318
|
-
var flag = _a.flag,
|
|
318
|
+
var flag = _a.flag, insights = _a.insights, flagVariant = _a.flagVariant;
|
|
319
319
|
var properties = {
|
|
320
320
|
feature_flag: flag,
|
|
321
321
|
$set: (_b = {}, _b["$feature_view/".concat(flag)] = flagVariant !== null && flagVariant !== void 0 ? flagVariant : true, _b),
|
|
@@ -323,31 +323,31 @@ function captureFeatureView(_a) {
|
|
|
323
323
|
if (typeof flagVariant === 'string') {
|
|
324
324
|
properties.feature_flag_variant = flagVariant;
|
|
325
325
|
}
|
|
326
|
-
|
|
326
|
+
insights.capture('$feature_view', properties);
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
function TrackedChild(_a) {
|
|
330
330
|
var child = _a.child, index = _a.index, name = _a.name, properties = _a.properties, observerOptions = _a.observerOptions;
|
|
331
331
|
var trackedRef = useRef(false);
|
|
332
|
-
var
|
|
332
|
+
var insights = useInsights();
|
|
333
333
|
var onIntersect = useCallback(function (entry) {
|
|
334
334
|
if (entry.isIntersecting && !trackedRef.current) {
|
|
335
|
-
|
|
335
|
+
insights.capture('$element_viewed', __assign({ element_name: name, child_index: index }, properties));
|
|
336
336
|
trackedRef.current = true;
|
|
337
337
|
}
|
|
338
|
-
}, [
|
|
338
|
+
}, [insights, name, index, properties]);
|
|
339
339
|
return (React.createElement(VisibilityAndClickTracker, { onIntersect: onIntersect, trackView: true, options: observerOptions }, child));
|
|
340
340
|
}
|
|
341
|
-
function
|
|
341
|
+
function InsightsCaptureOnViewed(_a) {
|
|
342
342
|
var name = _a.name, properties = _a.properties, observerOptions = _a.observerOptions, trackAllChildren = _a.trackAllChildren, children = _a.children, props = __rest(_a, ["name", "properties", "observerOptions", "trackAllChildren", "children"]);
|
|
343
343
|
var trackedRef = useRef(false);
|
|
344
|
-
var
|
|
344
|
+
var insights = useInsights();
|
|
345
345
|
var onIntersect = useCallback(function (entry) {
|
|
346
346
|
if (entry.isIntersecting && !trackedRef.current) {
|
|
347
|
-
|
|
347
|
+
insights.capture('$element_viewed', __assign({ element_name: name }, properties));
|
|
348
348
|
trackedRef.current = true;
|
|
349
349
|
}
|
|
350
|
-
}, [
|
|
350
|
+
}, [insights, name, properties]);
|
|
351
351
|
if (trackAllChildren) {
|
|
352
352
|
var trackedChildren = Children.map(children, function (child, index) {
|
|
353
353
|
return (React.createElement(TrackedChild, { key: index, child: child, index: index, name: name, properties: properties, observerOptions: observerOptions }));
|
|
@@ -362,17 +362,17 @@ var INITIAL_STATE = {
|
|
|
362
362
|
exceptionEvent: null,
|
|
363
363
|
error: null,
|
|
364
364
|
};
|
|
365
|
-
var
|
|
366
|
-
INVALID_FALLBACK: '[
|
|
365
|
+
var __INSIGHTS_ERROR_MESSAGES = {
|
|
366
|
+
INVALID_FALLBACK: '[Insights][InsightsErrorBoundary] Invalid fallback prop, provide a valid React element or a function that returns a valid React element.',
|
|
367
367
|
};
|
|
368
|
-
var
|
|
369
|
-
__extends(
|
|
370
|
-
function
|
|
368
|
+
var InsightsErrorBoundary = (function (_super) {
|
|
369
|
+
__extends(InsightsErrorBoundary, _super);
|
|
370
|
+
function InsightsErrorBoundary(props) {
|
|
371
371
|
var _this = _super.call(this, props) || this;
|
|
372
372
|
_this.state = INITIAL_STATE;
|
|
373
373
|
return _this;
|
|
374
374
|
}
|
|
375
|
-
|
|
375
|
+
InsightsErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
|
|
376
376
|
var additionalProperties = this.props.additionalProperties;
|
|
377
377
|
var currentProperties;
|
|
378
378
|
if (isFunction(additionalProperties)) {
|
|
@@ -390,7 +390,7 @@ var PostHogErrorBoundary = (function (_super) {
|
|
|
390
390
|
exceptionEvent: exceptionEvent,
|
|
391
391
|
});
|
|
392
392
|
};
|
|
393
|
-
|
|
393
|
+
InsightsErrorBoundary.prototype.render = function () {
|
|
394
394
|
var _a = this.props, children = _a.children, fallback = _a.fallback;
|
|
395
395
|
var state = this.state;
|
|
396
396
|
if (state.componentStack == null) {
|
|
@@ -406,11 +406,11 @@ var PostHogErrorBoundary = (function (_super) {
|
|
|
406
406
|
if (React.isValidElement(element)) {
|
|
407
407
|
return element;
|
|
408
408
|
}
|
|
409
|
-
console.warn(
|
|
409
|
+
console.warn(__INSIGHTS_ERROR_MESSAGES.INVALID_FALLBACK);
|
|
410
410
|
return React.createElement(React.Fragment, null);
|
|
411
411
|
};
|
|
412
|
-
|
|
413
|
-
return
|
|
412
|
+
InsightsErrorBoundary.contextType = InsightsContext;
|
|
413
|
+
return InsightsErrorBoundary;
|
|
414
414
|
}(React.Component));
|
|
415
415
|
|
|
416
416
|
var setupReactErrorHandler = function (client, callback) {
|
|
@@ -422,5 +422,5 @@ var setupReactErrorHandler = function (client, callback) {
|
|
|
422
422
|
};
|
|
423
423
|
};
|
|
424
424
|
|
|
425
|
-
export {
|
|
425
|
+
export { InsightsCaptureOnViewed, InsightsContext, InsightsErrorBoundary, InsightsFeature, InsightsProvider, captureFeatureInteraction, captureFeatureView, setupReactErrorHandler, useActiveFeatureFlags, useFeatureFlagEnabled, useFeatureFlagPayload, useFeatureFlagResult, useFeatureFlagVariantKey, useInsights };
|
|
426
426
|
//# sourceMappingURL=index.js.map
|