-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathOnboarding.tsx
421 lines (383 loc) · 17.6 KB
/
Onboarding.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
import { Spinner } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { FEATURE_FLAGS, SESSION_REPLAY_MINIMUM_DURATION_OPTIONS } from 'lib/constants'
import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { useEffect, useState } from 'react'
import { billingLogic } from 'scenes/billing/billingLogic'
import { newDashboardLogic } from 'scenes/dashboard/newDashboardLogic'
import { WebAnalyticsSDKInstructions } from 'scenes/onboarding/sdks/web-analytics/WebAnalyticsSDKInstructions'
import { productsLogic } from 'scenes/products/productsLogic'
import { SceneExport } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
import { AvailableFeature, ProductKey } from '~/types'
import { OnboardingUpgradeStep } from './billing/OnboardingUpgradeStep'
import { OnboardingDataWarehouseSourcesStep } from './data-warehouse/OnboardingDataWarehouseSourcesStep'
import { OnboardingInviteTeammates } from './OnboardingInviteTeammates'
import { onboardingLogic, OnboardingStepKey } from './onboardingLogic'
import { OnboardingProductConfiguration } from './OnboardingProductConfiguration'
import { ProductConfigOption } from './onboardingProductConfigurationLogic'
import { OnboardingReverseProxy } from './OnboardingReverseProxy'
import { OnboardingSessionReplayConfiguration } from './OnboardingSessionReplayConfiguration'
import { OnboardingDashboardTemplateConfigureStep } from './productAnalyticsSteps/DashboardTemplateConfigureStep'
import { OnboardingDashboardTemplateSelectStep } from './productAnalyticsSteps/DashboardTemplateSelectStep'
import { ExperimentsSDKInstructions } from './sdks/experiments/ExperimentsSDKInstructions'
import { FeatureFlagsSDKInstructions } from './sdks/feature-flags/FeatureFlagsSDKInstructions'
import { OnboardingInstallStep } from './sdks/OnboardingInstallStep'
import { ProductAnalyticsSDKInstructions } from './sdks/product-analytics/ProductAnalyticsSDKInstructions'
import { sdksLogic } from './sdks/sdksLogic'
import { SessionReplaySDKInstructions } from './sdks/session-replay/SessionReplaySDKInstructions'
import { SurveysSDKInstructions } from './sdks/surveys/SurveysSDKInstructions'
import { OnboardingWebAnalyticsAuthorizedDomainsStep } from './web-analytics/OnboardingWebAnalyticsAuthorizedDomainsStep'
export const scene: SceneExport = {
component: Onboarding,
logic: onboardingLogic,
}
/**
* Wrapper for custom onboarding content. This automatically includes billing, other products, and invite steps.
*/
const OnboardingWrapper = ({ children }: { children: React.ReactNode }): JSX.Element => {
const {
productKey,
currentOnboardingStep,
shouldShowBillingStep,
shouldShowReverseProxyStep,
shouldShowDataWarehouseStep,
product,
waitForBilling,
} = useValues(onboardingLogic)
const { billing, billingLoading } = useValues(billingLogic)
const { setAllOnboardingSteps } = useActions(onboardingLogic)
const [allSteps, setAllSteps] = useState<JSX.Element[]>([])
useEffect(() => {
let steps = []
if (Array.isArray(children)) {
steps = [...children]
} else {
steps = [children as JSX.Element]
}
if (shouldShowDataWarehouseStep) {
const DataWarehouseStep = (
<OnboardingDataWarehouseSourcesStep
usersAction="Data Warehouse"
stepKey={OnboardingStepKey.LINK_DATA}
/>
)
steps = [...steps, DataWarehouseStep]
}
if (shouldShowReverseProxyStep) {
const ReverseProxyStep = <OnboardingReverseProxy stepKey={OnboardingStepKey.REVERSE_PROXY} />
steps = [...steps, ReverseProxyStep]
}
const billingProduct = billing?.products.find((p) => p.type === productKey)
if (shouldShowBillingStep && billingProduct) {
const BillingStep = <OnboardingUpgradeStep product={billingProduct} stepKey={OnboardingStepKey.PLANS} />
steps = [...steps, BillingStep]
}
const inviteTeammatesStep = <OnboardingInviteTeammates stepKey={OnboardingStepKey.INVITE_TEAMMATES} />
steps = [...steps, inviteTeammatesStep].filter(Boolean)
setAllSteps(steps)
}, [children, billingLoading])
useEffect(() => {
if (!allSteps.length || (billingLoading && waitForBilling)) {
return
}
setAllOnboardingSteps(allSteps)
}, [allSteps])
if (!product || !children) {
return <></>
}
if (!currentOnboardingStep) {
return (
<div className="flex items-center justify-center my-20">
<Spinner className="text-2xl text-secondary w-10 h-10" />
</div>
)
}
return currentOnboardingStep
}
const ProductAnalyticsOnboarding = (): JSX.Element => {
const { currentTeam } = useValues(teamLogic)
const { featureFlags } = useValues(featureFlagLogic)
const { combinedSnippetAndLiveEventsHosts } = useValues(sdksLogic)
const { selectedProducts } = useValues(productsLogic)
// mount the logic here so that it stays mounted for the entire onboarding flow
// not sure if there is a better way to do this
useValues(newDashboardLogic)
const showTemplateSteps =
featureFlags[FEATURE_FLAGS.ONBOARDING_DASHBOARD_TEMPLATES] == 'test' &&
window.innerWidth > 1000 &&
combinedSnippetAndLiveEventsHosts.length > 0
const showSessionReplayStep =
useFeatureFlag('ONBOARDING_SESSION_REPLAY_SEPARATE_STEP', 'test') &&
!selectedProducts.includes(ProductKey.SESSION_REPLAY)
const options: ProductConfigOption[] = [
{
title: 'Autocapture frontend interactions',
description: `If you use our JavaScript, React Native or iOS libraries, we'll automagically
capture frontend interactions like clicks, submits, and more. Fine-tune what you
capture directly in your code snippet.`,
teamProperty: 'autocapture_opt_out',
value: !currentTeam?.autocapture_opt_out,
type: 'toggle',
inverseToggle: true,
visible: true,
},
{
title: 'Enable heatmaps',
description: `If you use our JavaScript libraries, we can capture general clicks, mouse movements,
and scrolling to create heatmaps.
No additional events are created, and you can disable this at any time.`,
teamProperty: 'heatmaps_opt_in',
value: currentTeam?.heatmaps_opt_in ?? true,
type: 'toggle',
visible: true,
},
{
title: 'Enable web vitals autocapture',
description: `Uses Google's web vitals library to automagically capture performance information.`,
teamProperty: 'autocapture_web_vitals_opt_in',
value: currentTeam?.autocapture_web_vitals_opt_in ?? true,
type: 'toggle',
visible: true,
},
{
title: 'Enable session recordings',
description: `Turn on session recordings and watch how users experience your app. We will also turn on console log and network performance recording. You can change these settings any time in the settings panel.`,
teamProperty: 'session_recording_opt_in',
// TRICKY: if someone has shown secondary product intent for replay we want to include it as enabled
// particularly while we're not taking people through every product onboarding they showed interest in
value:
(currentTeam?.session_recording_opt_in || selectedProducts.includes(ProductKey.SESSION_REPLAY)) ?? true,
type: 'toggle',
visible: true,
},
{
title: 'Capture console logs',
description: `Automatically enable console log capture`,
teamProperty: 'capture_console_log_opt_in',
value: true,
type: 'toggle',
visible: false,
},
{
title: 'Capture network performance',
description: `Automatically enable network performance capture`,
teamProperty: 'capture_performance_opt_in',
value: true,
type: 'toggle',
visible: false,
},
]
const filteredOptions = showSessionReplayStep
? options.filter((option) => option.teamProperty !== 'session_recording_opt_in')
: options
return (
<OnboardingWrapper>
<OnboardingInstallStep
usersAction="collecting events"
sdkInstructionMap={ProductAnalyticsSDKInstructions}
stepKey={OnboardingStepKey.INSTALL}
/>
<OnboardingProductConfiguration
stepKey={OnboardingStepKey.PRODUCT_CONFIGURATION}
options={filteredOptions}
/>
{showSessionReplayStep && (
<OnboardingSessionReplayConfiguration stepKey={OnboardingStepKey.SESSION_REPLAY} />
)}
{/* this is two conditionals because they need to be direct children of the wrapper */}
{showTemplateSteps ? (
<OnboardingDashboardTemplateSelectStep stepKey={OnboardingStepKey.DASHBOARD_TEMPLATE} />
) : null}
{showTemplateSteps ? (
<OnboardingDashboardTemplateConfigureStep stepKey={OnboardingStepKey.DASHBOARD_TEMPLATE_CONFIGURE} />
) : null}
</OnboardingWrapper>
)
}
const WebAnalyticsOnboarding = (): JSX.Element => {
const { currentTeam } = useValues(teamLogic)
const options: ProductConfigOption[] = [
{
title: 'Autocapture frontend interactions',
description: `If you use our JavaScript, React Native or iOS libraries, we'll automagically
capture frontend interactions like clicks, submits, and more. Fine-tune what you
capture directly in your code snippet.`,
teamProperty: 'autocapture_opt_out',
value: !currentTeam?.autocapture_opt_out,
type: 'toggle',
inverseToggle: true,
visible: true,
},
{
title: 'Enable heatmaps',
description: `If you use our JavaScript libraries, we can capture general clicks, mouse movements,
and scrolling to create heatmaps.
No additional events are created, and you can disable this at any time.`,
teamProperty: 'heatmaps_opt_in',
value: currentTeam?.heatmaps_opt_in ?? true,
type: 'toggle',
visible: true,
},
{
title: 'Enable web vitals autocapture',
description: `Uses Google's web vitals library to automagically capture performance information.`,
teamProperty: 'autocapture_web_vitals_opt_in',
value: currentTeam?.autocapture_web_vitals_opt_in ?? true,
type: 'toggle',
visible: true,
},
{
title: 'Enable session recordings',
description: `Turn on session recordings and watch how users experience your app. We will also turn on console log and network performance recording. You can change these settings any time in the settings panel.`,
teamProperty: 'session_recording_opt_in',
value: currentTeam?.session_recording_opt_in ?? true,
type: 'toggle',
visible: true,
},
{
title: 'Capture network performance',
description: `Automatically enable network performance capture`,
teamProperty: 'capture_performance_opt_in',
value: true,
type: 'toggle',
visible: false,
},
]
return (
<OnboardingWrapper>
<OnboardingInstallStep
usersAction="collecting events"
sdkInstructionMap={WebAnalyticsSDKInstructions}
stepKey={OnboardingStepKey.INSTALL}
/>
<OnboardingWebAnalyticsAuthorizedDomainsStep stepKey={OnboardingStepKey.AUTHORIZED_DOMAINS} />
<OnboardingProductConfiguration stepKey={OnboardingStepKey.PRODUCT_CONFIGURATION} options={options} />
</OnboardingWrapper>
)
}
const SessionReplayOnboarding = (): JSX.Element => {
const { hasAvailableFeature } = useValues(userLogic)
const { currentTeam } = useValues(teamLogic)
const configOptions: ProductConfigOption[] = [
{
type: 'toggle',
title: 'Capture console logs',
description: `Capture console logs as a part of user session recordings.
Use the console logs alongside recordings to debug any issues with your app.`,
teamProperty: 'capture_console_log_opt_in',
value: currentTeam?.capture_console_log_opt_in ?? true,
visible: true,
},
{
type: 'toggle',
title: 'Capture network performance',
description: `Capture performance and network information alongside recordings. Use the
network requests and timings in the recording player to help you debug issues with your app.`,
teamProperty: 'capture_performance_opt_in',
value: currentTeam?.capture_performance_opt_in ?? true,
visible: true,
},
{
type: 'toggle',
title: 'Record user sessions',
description: 'Watch recordings of how users interact with your web app to see what can be improved.',
teamProperty: 'session_recording_opt_in',
value: true,
visible: false,
},
]
if (hasAvailableFeature(AvailableFeature.REPLAY_RECORDING_DURATION_MINIMUM)) {
configOptions.push({
type: 'select',
title: 'Minimum session duration (seconds)',
description: `Only record sessions that are longer than the specified duration.
Start with it low and increase it later if you're getting too many short sessions.`,
teamProperty: 'session_recording_minimum_duration_milliseconds',
value: currentTeam?.session_recording_minimum_duration_milliseconds || null,
selectOptions: SESSION_REPLAY_MINIMUM_DURATION_OPTIONS,
visible: true,
})
}
return (
<OnboardingWrapper>
<OnboardingInstallStep
usersAction="recording sessions"
sdkInstructionMap={SessionReplaySDKInstructions}
subtitle="Choose the framework your frontend is built on, or use our all-purpose JavaScript library. If you already have the snippet installed, you can skip this step!"
stepKey={OnboardingStepKey.INSTALL}
/>
<OnboardingProductConfiguration
stepKey={OnboardingStepKey.PRODUCT_CONFIGURATION}
options={configOptions}
product={ProductKey.SESSION_REPLAY}
/>
</OnboardingWrapper>
)
}
const FeatureFlagsOnboarding = (): JSX.Element => {
return (
<OnboardingWrapper>
<OnboardingInstallStep
usersAction="loading flags"
sdkInstructionMap={FeatureFlagsSDKInstructions}
subtitle="Choose the framework where you want to use feature flags, or use our all-purpose JavaScript library. If you already have the snippet installed, you can skip this step!"
stepKey={OnboardingStepKey.INSTALL}
/>
</OnboardingWrapper>
)
}
const ExperimentsOnboarding = (): JSX.Element => {
return (
<OnboardingWrapper>
<OnboardingInstallStep
usersAction="loading experiments"
sdkInstructionMap={ExperimentsSDKInstructions}
subtitle="Choose the framework where you want to run experiments, or use our all-purpose JavaScript library. If you already have the snippet installed, you can skip this step!"
stepKey={OnboardingStepKey.INSTALL}
/>
</OnboardingWrapper>
)
}
const SurveysOnboarding = (): JSX.Element => {
return (
<OnboardingWrapper>
<OnboardingInstallStep
usersAction="taking surveys"
sdkInstructionMap={SurveysSDKInstructions}
subtitle="Choose the framework your frontend is built on, or use our all-purpose JavaScript library. If you already have the snippet installed, you can skip this step!"
stepKey={OnboardingStepKey.INSTALL}
/>
</OnboardingWrapper>
)
}
const DataWarehouseOnboarding = (): JSX.Element => {
return (
<OnboardingWrapper>
<OnboardingDataWarehouseSourcesStep usersAction="Data Warehouse" stepKey={OnboardingStepKey.LINK_DATA} />
</OnboardingWrapper>
)
}
export const onboardingViews = {
[ProductKey.PRODUCT_ANALYTICS]: ProductAnalyticsOnboarding,
[ProductKey.WEB_ANALYTICS]: WebAnalyticsOnboarding,
[ProductKey.SESSION_REPLAY]: SessionReplayOnboarding,
[ProductKey.FEATURE_FLAGS]: FeatureFlagsOnboarding,
[ProductKey.EXPERIMENTS]: ExperimentsOnboarding,
[ProductKey.SURVEYS]: SurveysOnboarding,
[ProductKey.DATA_WAREHOUSE]: DataWarehouseOnboarding,
}
export function Onboarding(): JSX.Element | null {
const { product, productKey } = useValues(onboardingLogic)
if (!product || !productKey) {
return <></>
}
const OnboardingView = onboardingViews[productKey as keyof typeof onboardingViews]
return (
<div className="pt-4 pb-10">
<OnboardingView />
</div>
)
}