Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 0294b63

Browse files
dadlerjerzhtor
andauthored
Add event logging to signup Cody toast and email verification toast (#52278)
## Test plan - sign up for a new account on dotcom --------- Co-authored-by: Erzhan Torokulov <erzhan.torokulov@gmail.com>
1 parent 35c3b8f commit 0294b63

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

client/web/src/LegacyLayout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ export const LegacyLayout: FC<LegacyLayoutProps> = props => {
237237
!disableFeedbackSurvey &&
238238
!isCodyStandalonePage && <SurveyToast authenticatedUser={props.authenticatedUser} />}
239239
{props.isSourcegraphDotCom && props.authenticatedUser && (
240-
<CodySurveyToast authenticatedUser={props.authenticatedUser} />
240+
<CodySurveyToast
241+
authenticatedUser={props.authenticatedUser}
242+
telemetryService={props.telemetryService}
243+
/>
241244
)}
242245
{!isSiteInit && !isSignInOrUp && !isCodyStandalonePage && (
243246
<GlobalNavbar

client/web/src/marketing/toast/CodySurveyToast.tsx

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { mdiEmail } from '@mdi/js'
55
import { asError, ErrorLike } from '@sourcegraph/common'
66
import { gql, useMutation } from '@sourcegraph/http-client'
77
import { useTemporarySetting } from '@sourcegraph/shared/src/settings/temporary'
8+
import { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService'
89
import { Checkbox, Form, H3, Modal, Text, Button, Icon, useLocalStorage } from '@sourcegraph/wildcard'
910

1011
import { AuthenticatedUser } from '../../auth'
@@ -22,7 +23,10 @@ const SUBMIT_CODY_SURVEY = gql`
2223
}
2324
`
2425

25-
const CodySurveyToastInner: React.FC<{ onSubmitEnd: () => void }> = ({ onSubmitEnd }) => {
26+
const CodySurveyToastInner: React.FC<{ onSubmitEnd: () => void } & TelemetryProps> = ({
27+
onSubmitEnd,
28+
telemetryService,
29+
}) => {
2630
const [isCodyForWork, setIsCodyForWork] = useState(false)
2731
const [isCodyForPersonalStuff, setIsCodyForPersonalStuff] = useState(false)
2832

@@ -45,13 +49,19 @@ const CodySurveyToastInner: React.FC<{ onSubmitEnd: () => void }> = ({ onSubmitE
4549

4650
const handleSubmit = useCallback(
4751
(event: React.FormEvent<HTMLFormElement>) => {
52+
const eventParams = { isCodyForPersonalStuff, isCodyForWork }
53+
telemetryService.log('CodyUsageToastSubmitted', eventParams, eventParams)
4854
event.preventDefault()
4955
// eslint-disable-next-line no-console
5056
submitCodySurvey().catch(console.error).finally(onSubmitEnd)
5157
},
52-
[onSubmitEnd, submitCodySurvey]
58+
[isCodyForPersonalStuff, isCodyForWork, onSubmitEnd, submitCodySurvey, telemetryService]
5359
)
5460

61+
useEffect(() => {
62+
telemetryService.log('CodySurveyToastViewed')
63+
}, [telemetryService])
64+
5565
return (
5666
<Modal position="center" aria-label="Welcome message">
5767
<H3 className="mb-4 d-flex align-items-center">
@@ -84,9 +94,10 @@ const CodySurveyToastInner: React.FC<{ onSubmitEnd: () => void }> = ({ onSubmitE
8494
)
8595
}
8696

87-
const CodyVerifyEmailToast: React.FC<{ onNext: () => void; authenticatedUser: AuthenticatedUser }> = ({
97+
const CodyVerifyEmailToast: React.FC<{ onNext: () => void; authenticatedUser: AuthenticatedUser } & TelemetryProps> = ({
8898
onNext,
8999
authenticatedUser,
100+
telemetryService,
90101
}) => {
91102
const [sending, setSending] = useState(false)
92103
const [resentEmailTo, setResentEmailTo] = useState<string | null>(null)
@@ -110,6 +121,10 @@ const CodyVerifyEmailToast: React.FC<{ onNext: () => void; authenticatedUser: Au
110121
}
111122
}, [authenticatedUser])
112123

124+
useEffect(() => {
125+
telemetryService.log('VerifyEmailToastViewed')
126+
}, [telemetryService])
127+
113128
return (
114129
<Modal position="center" aria-label="Welcome message">
115130
<H3 className="mb-4">
@@ -174,21 +189,32 @@ export const useCodySurveyToast = (): {
174189
}
175190
}
176191

177-
export const CodySurveyToast: React.FC<{
178-
authenticatedUser?: AuthenticatedUser
179-
}> = ({ authenticatedUser }) => {
192+
export const CodySurveyToast: React.FC<
193+
{
194+
authenticatedUser?: AuthenticatedUser
195+
} & TelemetryProps
196+
> = ({ authenticatedUser, telemetryService }) => {
180197
const { show, dismiss } = useCodySurveyToast()
181198
const codyEnabled = useIsCodyEnabled()
182199
const [showVerifyEmail, setShowVerifyEmail] = useState(show && codyEnabled.needsEmailVerification)
183-
const dismissVerifyEmail = useCallback(() => setShowVerifyEmail(false), [setShowVerifyEmail])
200+
const dismissVerifyEmail = useCallback(() => {
201+
telemetryService.log('VerifyEmailToastDismissed')
202+
setShowVerifyEmail(false)
203+
}, [telemetryService])
184204

185205
if (!show) {
186206
return null
187207
}
188208

189209
if (showVerifyEmail && authenticatedUser) {
190-
return <CodyVerifyEmailToast onNext={dismissVerifyEmail} authenticatedUser={authenticatedUser} />
210+
return (
211+
<CodyVerifyEmailToast
212+
onNext={dismissVerifyEmail}
213+
authenticatedUser={authenticatedUser}
214+
telemetryService={telemetryService}
215+
/>
216+
)
191217
}
192218

193-
return <CodySurveyToastInner onSubmitEnd={dismiss} />
219+
return <CodySurveyToastInner onSubmitEnd={dismiss} telemetryService={telemetryService} />
194220
}

client/web/src/storm/pages/LayoutPage/LayoutPage.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ export const Layout: React.FC<LegacyLayoutProps> = props => {
197197
{!isSiteInit && !isSignInOrUp && !props.isSourcegraphDotCom && !disableFeedbackSurvey && (
198198
<SurveyToast authenticatedUser={props.authenticatedUser} />
199199
)}
200-
{!isSiteInit && !props.isSourcegraphDotCom && <CodySurveyToast />}
200+
{!isSiteInit && props.isSourcegraphDotCom && props.authenticatedUser && (
201+
<CodySurveyToast
202+
telemetryService={props.telemetryService}
203+
authenticatedUser={props.authenticatedUser}
204+
/>
205+
)}
201206
{!isSiteInit && !isSignInOrUp && (
202207
<GlobalNavbar
203208
{...props}

0 commit comments

Comments
 (0)