Skip to content

Commit 40c29d5

Browse files
chore: Replace old onboarding metrics with Amplitude events (#3769)
1 parent 88989bb commit 40c29d5

File tree

17 files changed

+147
-487
lines changed

17 files changed

+147
-487
lines changed

src/pages/RepoPage/BundlesTab/BundleOnboarding/BundleOnboarding.test.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ describe('BundleOnboarding', () => {
123123
mocks.useRedirect.mockImplementation((data) => ({
124124
hardRedirect: () => hardRedirect(data),
125125
}))
126-
const mockMetricMutationVariables = vi.fn()
127-
const mockGetItem = vi.spyOn(window.localStorage.__proto__, 'getItem')
128-
mockGetItem.mockReturnValue(null)
129126

130127
server.use(
131128
graphql.query('GetRepo', () => {
@@ -135,14 +132,10 @@ describe('BundleOnboarding', () => {
135132
}),
136133
graphql.query('GetOrgUploadToken', () => {
137134
return HttpResponse.json({ data: mockGetOrgUploadToken })
138-
}),
139-
graphql.mutation('storeEventMetric', (info) => {
140-
mockMetricMutationVariables(info.variables)
141-
return HttpResponse.json({ data: { storeEventMetric: null } })
142135
})
143136
)
144137

145-
return { hardRedirect, mockMetricMutationVariables, user }
138+
return { hardRedirect, user }
146139
}
147140

148141
it('renders intro', async () => {
@@ -163,7 +156,7 @@ describe('BundleOnboarding', () => {
163156
describe('navigation', () => {
164157
describe('when Vite is selected', () => {
165158
it('should navigate to /new', async () => {
166-
const { user, mockMetricMutationVariables } = setup({})
159+
const { user } = setup({})
167160
render(<BundleOnboarding />, {
168161
wrapper: wrapper('/gh/codecov/test-repo/bundles/new/rollup'),
169162
})
@@ -173,7 +166,6 @@ describe('BundleOnboarding', () => {
173166
expect(vite).toHaveAttribute('data-state', 'unchecked')
174167

175168
await user.click(vite)
176-
expect(mockMetricMutationVariables).toHaveBeenCalled()
177169

178170
expect(vite).toBeInTheDocument()
179171
expect(vite).toHaveAttribute('data-state', 'checked')

src/pages/RepoPage/BundlesTab/BundleOnboarding/BundleOnboarding.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { Suspense, useEffect } from 'react'
1+
import { Suspense } from 'react'
22
import { Switch, useHistory, useLocation, useParams } from 'react-router-dom'
33

44
import { SentryRoute } from 'sentry'
55

66
import NotFound from 'pages/NotFound'
7-
import {
8-
EVENT_METRICS,
9-
useStoreCodecovEventMetric,
10-
} from 'services/codecovEventMetrics/useStoreCodecovEventMetric'
117
import { useNavLinks } from 'services/navigation/useNavLinks'
128
import { useRepo } from 'services/repo'
139
import { Provider } from 'shared/api/helpers'
@@ -200,15 +196,6 @@ const BundleOnboarding: React.FC = () => {
200196
const { provider, owner, repo } = useParams<URLParams>()
201197
const { data } = useRepo({ provider, owner, repo })
202198
const { hardRedirect } = useRedirect({ href: `/${provider}` })
203-
const { mutate: storeEventMetric } = useStoreCodecovEventMetric()
204-
205-
useEffect(() => {
206-
storeEventMetric({
207-
owner,
208-
event: EVENT_METRICS.VISITED_PAGE,
209-
jsonPayload: { page: 'Bundle Onboarding' },
210-
})
211-
}, [storeEventMetric, owner])
212199

213200
// if no upload token redirect
214201
if (!data?.repository?.uploadToken) {

src/pages/RepoPage/CoverageOnboarding/CircleCI/CircleCI.test.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import { setupServer } from 'msw/node'
66
import { Suspense } from 'react'
77
import { MemoryRouter, Route } from 'react-router-dom'
88

9+
import { eventTracker } from 'services/events/events'
10+
911
import CircleCI from './CircleCI'
1012

13+
vi.mock('services/events/events')
14+
1115
const mockGetRepo = {
1216
owner: {
1317
isAdmin: null,
@@ -79,10 +83,6 @@ interface SetupArgs {
7983

8084
describe('CircleCI', () => {
8185
function setup({ hasOrgUploadToken = false }: SetupArgs) {
82-
const mockMetricMutationVariables = vi.fn()
83-
const mockGetItem = vi.spyOn(window.localStorage.__proto__, 'getItem')
84-
mockGetItem.mockReturnValue(null)
85-
8686
server.use(
8787
graphql.query('GetRepo', () => {
8888
return HttpResponse.json({ data: mockGetRepo })
@@ -91,14 +91,10 @@ describe('CircleCI', () => {
9191
return HttpResponse.json({
9292
data: hasOrgUploadToken ? mockGetOrgUploadToken : mockNoUploadToken,
9393
})
94-
}),
95-
graphql.mutation('storeEventMetric', (info) => {
96-
mockMetricMutationVariables(info?.variables)
97-
return HttpResponse.json({ data: { storeEventMetric: null } })
9894
})
9995
)
10096
const user = userEvent.setup()
101-
return { mockMetricMutationVariables, user }
97+
return { user }
10298
}
10399

104100
describe('output coverage step', () => {
@@ -329,8 +325,7 @@ describe('CircleCI', () => {
329325

330326
describe('user copies text', () => {
331327
it('stores codecov metric', async () => {
332-
// will be removing this stuff soon, backend for this doesn't exist anymore
333-
const { mockMetricMutationVariables } = setup({})
328+
setup({})
334329
const user = userEvent.setup()
335330
render(<CircleCI />, { wrapper })
336331

@@ -339,12 +334,11 @@ describe('CircleCI', () => {
339334
)
340335
expect(copyCommands.length).toEqual(5)
341336

342-
await user.click(copyCommands[1] as HTMLElement)
337+
const promises: Promise<void>[] = []
338+
copyCommands.forEach((copy) => promises.push(user.click(copy)))
339+
await Promise.all(promises)
343340

344-
await user.click(copyCommands[2] as HTMLElement)
345-
await waitFor(() =>
346-
expect(mockMetricMutationVariables).toHaveBeenCalledTimes(1)
347-
)
341+
await waitFor(() => expect(eventTracker().track).toHaveBeenCalledTimes(4))
348342
})
349343
})
350344
})

src/pages/RepoPage/CoverageOnboarding/CircleCI/CircleCI.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { useState } from 'react'
22
import { useParams } from 'react-router-dom'
33

44
import envVarScreenshot from 'assets/onboarding/env_variable_screenshot.png'
5-
import {
6-
EVENT_METRICS,
7-
useStoreCodecovEventMetric,
8-
} from 'services/codecovEventMetrics/useStoreCodecovEventMetric'
5+
import { eventTracker } from 'services/events/events'
96
import { useOrgUploadToken } from 'services/orgUploadToken/useOrgUploadToken'
107
import { useRepo } from 'services/repo'
118
import { Provider } from 'shared/api/helpers'
@@ -62,7 +59,7 @@ function CircleCI() {
6259
<OutputCoverageStep
6360
framework={framework}
6461
frameworkInstructions={frameworkInstructions}
65-
owner={owner}
62+
ciProvider="CircleCI"
6663
setFramework={setFramework}
6764
/>
6865
<TokenStep
@@ -87,8 +84,6 @@ interface TokenStepProps {
8784
}
8885

8986
function TokenStep({ tokenCopy, uploadToken, providerName }: TokenStepProps) {
90-
const { mutate: storeEventMetric } = useStoreCodecovEventMetric()
91-
const { owner } = useParams<URLParams>()
9287
return (
9388
<Card>
9489
<Card.Header>
@@ -118,10 +113,14 @@ function TokenStep({ tokenCopy, uploadToken, providerName }: TokenStepProps) {
118113
className="basis-2/3"
119114
clipboard={uploadToken}
120115
clipboardOnClick={() =>
121-
storeEventMetric({
122-
owner,
123-
event: EVENT_METRICS.COPIED_TEXT,
124-
jsonPayload: { text: 'Step 1 CircleCI' },
116+
eventTracker().track({
117+
type: 'Button Clicked',
118+
properties: {
119+
buttonName: 'Copy',
120+
buttonLocation: 'Coverage onboarding',
121+
ciProvider: 'CircleCI',
122+
copied: 'Upload token',
123+
},
125124
})
126125
}
127126
>
@@ -152,8 +151,6 @@ interface OrbYAMLStepProps {
152151
}
153152

154153
function OrbYAMLStep({ defaultBranch }: OrbYAMLStepProps) {
155-
const { mutate: storeEventMetric } = useStoreCodecovEventMetric()
156-
const { owner } = useParams<URLParams>()
157154
return (
158155
<Card>
159156
<Card.Header>
@@ -179,10 +176,14 @@ function OrbYAMLStep({ defaultBranch }: OrbYAMLStepProps) {
179176
<CodeSnippet
180177
clipboard={orbsString}
181178
clipboardOnClick={() =>
182-
storeEventMetric({
183-
owner,
184-
event: EVENT_METRICS.COPIED_TEXT,
185-
jsonPayload: { text: 'Step 2 CircleCI' },
179+
eventTracker().track({
180+
type: 'Button Clicked',
181+
properties: {
182+
buttonName: 'Copy',
183+
buttonLocation: 'Coverage onboarding',
184+
ciProvider: 'CircleCI',
185+
copied: 'YAML snippet',
186+
},
186187
})
187188
}
188189
>

src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.test.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { setupServer } from 'msw/node'
66
import { Suspense } from 'react'
77
import { MemoryRouter, Route } from 'react-router-dom'
88

9+
import { eventTracker } from 'services/events/events'
910
import { ThemeContextProvider } from 'shared/ThemeContext'
1011

1112
import GitHubActions from './GitHubActions'
@@ -14,6 +15,7 @@ const mocks = vi.hoisted(() => ({
1415
useFlags: vi.fn(),
1516
}))
1617

18+
vi.mock('services/events/events')
1719
vi.mock('shared/featureFlags', async () => {
1820
const actual = await vi.importActual('shared/featureFlags')
1921
return {
@@ -119,21 +121,13 @@ describe('GitHubActions', () => {
119121
newRepoFlag: hasOrgUploadToken,
120122
})
121123

122-
const mockMetricMutationVariables = vi.fn()
123-
const mockGetItem = vi.spyOn(window.localStorage.__proto__, 'getItem')
124-
mockGetItem.mockReturnValue(null)
125-
126124
server.use(
127125
graphql.query('GetRepo', () => {
128126
return HttpResponse.json({ data: mockGetRepo })
129127
}),
130128
graphql.query('GetOrgUploadToken', () => {
131129
return HttpResponse.json({ data: mockGetOrgUploadToken })
132130
}),
133-
graphql.mutation('storeEventMetric', (info) => {
134-
mockMetricMutationVariables(info?.variables)
135-
return HttpResponse.json({ data: { storeEventMetric: null } })
136-
}),
137131
graphql.query('GetUploadTokenRequired', () => {
138132
return HttpResponse.json({ data: mockGetUploadTokenRequired })
139133
}),
@@ -146,7 +140,7 @@ describe('GitHubActions', () => {
146140
)
147141
const user = userEvent.setup()
148142

149-
return { mockMetricMutationVariables, user }
143+
return { user }
150144
}
151145

152146
describe('when Go is selected', () => {
@@ -210,22 +204,31 @@ describe('GitHubActions', () => {
210204
})
211205

212206
describe('user copies text', () => {
213-
it('stores codecov metric', async () => {
214-
const { mockMetricMutationVariables } = setup({ hasOrgUploadToken: true })
207+
it('tracks an event', async () => {
208+
setup({ hasOrgUploadToken: true })
215209
const user = userEvent.setup()
216210
render(<GitHubActions />, { wrapper })
211+
212+
// Need to expand the example blurb dropdown
213+
const trigger = await screen.findByText((content) =>
214+
content.startsWith('Your final GitHub Actions workflow')
215+
)
216+
expect(trigger).toBeInTheDocument()
217+
218+
await user.click(trigger)
219+
217220
const copyCommands = await screen.findAllByTestId(
218221
'clipboard-code-snippet'
219222
)
220223

221-
expect(copyCommands.length).toEqual(5)
224+
expect(copyCommands.length).toEqual(6)
222225

223226
const promises: Promise<void>[] = []
224227
copyCommands.forEach((copy) => promises.push(user.click(copy)))
225228
await Promise.all(promises)
226229

227230
// One of the code-snippets does not have a metric associated with it
228-
expect(mockMetricMutationVariables).toHaveBeenCalledTimes(4)
231+
expect(eventTracker().track).toHaveBeenCalledTimes(5)
229232
})
230233
})
231234
})

src/pages/RepoPage/CoverageOnboarding/GitHubActions/GitHubActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function GitHubActions() {
7070
<OutputCoverageStep
7171
framework={framework}
7272
frameworkInstructions={frameworkInstructions}
73-
owner={owner}
73+
ciProvider="GitHub Actions"
7474
setFramework={setFramework}
7575
/>
7676
<TokenStep

src/pages/RepoPage/CoverageOnboarding/GitHubActions/TokenStep.tsx

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import { UseMutateFunction } from '@tanstack/react-query'
21
import { useParams } from 'react-router-dom'
32

43
import orgSecretDark from 'assets/onboarding/org_secret_dark.png'
54
import orgSecretLight from 'assets/onboarding/org_secret_light.png'
65
import repoSecretDark from 'assets/onboarding/repo_secret_dark.png'
76
import repoSecretLight from 'assets/onboarding/repo_secret_light.png'
87
import useGenerateOrgUploadToken from 'pages/AccountSettings/tabs/OrgUploadToken/useGenerateOrgUploadToken'
9-
import {
10-
EVENT_METRICS,
11-
StoreEventMetricMutationArgs,
12-
useStoreCodecovEventMetric,
13-
} from 'services/codecovEventMetrics/useStoreCodecovEventMetric'
8+
import { eventTracker } from 'services/events/events'
149
import { useOrgUploadToken } from 'services/orgUploadToken/useOrgUploadToken'
1510
import { useRepo } from 'services/repo'
1611
import { useUploadTokenRequired } from 'services/uploadTokenRequired'
@@ -37,21 +32,12 @@ interface URLParams {
3732

3833
interface SecretGHExampleProps {
3934
isUsingGlobalToken: boolean
40-
owner: string
41-
storeEventMetric: UseMutateFunction<
42-
any,
43-
unknown,
44-
StoreEventMetricMutationArgs,
45-
unknown
46-
>
4735
uploadToken: string
4836
}
4937

5038
function GitHubOrgSecretExample({
5139
isUsingGlobalToken,
52-
storeEventMetric,
5340
uploadToken,
54-
owner,
5541
}: SecretGHExampleProps) {
5642
return (
5743
<>
@@ -72,10 +58,14 @@ function GitHubOrgSecretExample({
7258
className="basis-2/3"
7359
clipboard={uploadToken}
7460
clipboardOnClick={() =>
75-
storeEventMetric({
76-
owner,
77-
event: EVENT_METRICS.COPIED_TEXT,
78-
jsonPayload: { text: 'GHA token copied' },
61+
eventTracker().track({
62+
type: 'Button Clicked',
63+
properties: {
64+
buttonName: 'Copy',
65+
buttonLocation: 'Coverage onboarding',
66+
ciProvider: 'GitHub Actions',
67+
copied: 'Upload token',
68+
},
7969
})
8070
}
8171
>
@@ -197,7 +187,6 @@ const AddTokenStep = ({
197187
})
198188
const { data } = useRepo({ provider, owner, repo })
199189
const repoUploadToken = data?.repository?.uploadToken ?? ''
200-
const { mutate: storeEventMetric } = useStoreCodecovEventMetric()
201190
return (
202191
<Card>
203192
<Card.Header>
@@ -225,8 +214,6 @@ const AddTokenStep = ({
225214
<Card.Content className="flex flex-col gap-4">
226215
<GitHubOrgSecretExample
227216
isUsingGlobalToken={isUsingGlobalToken}
228-
owner={owner}
229-
storeEventMetric={storeEventMetric}
230217
uploadToken={
231218
isUsingGlobalToken ? (orgUploadToken ?? '') : repoUploadToken
232219
}

0 commit comments

Comments
 (0)