Skip to content

Commit 2d8f484

Browse files
committed
Centralize PostHog analytics event strings into a common constants file and migrate all web components to use them for consistent event naming.\n\n🤖 Generated with Codebuff\nCo-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 975ee1f commit 2d8f484

File tree

18 files changed

+98
-33
lines changed

18 files changed

+98
-33
lines changed

common/src/constants/analytics-events.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,52 @@ export enum AnalyticsEvent {
3737
// Web
3838
SIGNUP = 'web.signup',
3939

40+
// Web - Authentication
41+
AUTH_LOGIN_STARTED = 'auth.login_started',
42+
AUTH_REFERRAL_GITHUB_LOGIN_STARTED = 'auth.referral_github_login_started',
43+
AUTH_LOGOUT_COMPLETED = 'auth.logout_completed',
44+
45+
// Web - Cookie Consent
46+
COOKIE_CONSENT_ACCEPTED = 'cookie_consent.accepted',
47+
COOKIE_CONSENT_DECLINED = 'cookie_consent.declined',
48+
49+
// Web - Onboarding
50+
ONBOARDING_STEP_COMPLETED = 'onboarding_step_completed',
51+
ONBOARDING_STEP_VIEWED = 'onboarding_step_viewed',
52+
ONBOARDING_PM_SELECTED = 'onboarding_pm_selected',
53+
ONBOARDING_EDITOR_OPENED = 'onboarding_editor_opened',
54+
55+
// Web - Onboard Page
56+
ONBOARD_PAGE_CD_COMMAND_COPIED = 'onboard_page.cd_command_copied',
57+
ONBOARD_PAGE_RUN_COMMAND_COPIED = 'onboard_page.run_command_copied',
58+
ONBOARD_PAGE_INSTALL_COMMAND_COPIED = 'onboard_page.install_command_copied',
59+
60+
// Web - Install Dialog
61+
INSTALL_DIALOG_CD_COMMAND_COPIED = 'install_dialog.cd_command_copied',
62+
INSTALL_DIALOG_RUN_COMMAND_COPIED = 'install_dialog.run_command_copied',
63+
INSTALL_DIALOG_INSTALL_COMMAND_COPIED = 'install_dialog.install_command_copied',
64+
65+
// Web - Home Page
66+
HOME_FEATURE_LEARN_MORE_CLICKED = 'home.feature_learn_more_clicked',
67+
HOME_INSTALL_COMMAND_COPIED = 'home.install_command_copied',
68+
HOME_TRY_FREE_CLICKED = 'home.try_free_clicked',
69+
HOME_TESTIMONIAL_CLICKED = 'home.testimonial_clicked',
70+
HOME_CTA_INSTALL_GUIDE_CLICKED = 'home.cta_install_guide_clicked',
71+
HOME_COMPETITION_TAB_CHANGED = 'home.competition_tab_changed',
72+
73+
// Web - Demo Terminal
74+
DEMO_TERMINAL_COMMAND_EXECUTED = 'demo_terminal.command_executed',
75+
DEMO_TERMINAL_HELP_VIEWED = 'demo_terminal.help_viewed',
76+
DEMO_TERMINAL_OPTIMIZE_REQUESTED = 'demo_terminal.optimize_requested',
77+
DEMO_TERMINAL_FIX_MEMORY_LEAK = 'demo_terminal.fix_memory_leak',
78+
DEMO_TERMINAL_REFACTOR_REQUESTED = 'demo_terminal.refactor_requested',
79+
DEMO_TERMINAL_FEATURE_REQUESTED = 'demo_terminal.feature_requested',
80+
DEMO_TERMINAL_THEME_CHANGED = 'demo_terminal.theme_changed',
81+
82+
// Web - UI Components
83+
TOAST_SHOWN = 'toast.shown',
84+
REFERRAL_BANNER_CLICKED = 'referral_banner.clicked',
85+
4086
// Common
4187
FLUSH_FAILED = 'common.flush_failed',
4288
}

web/src/app/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Image from 'next/image'
66
import { motion } from 'framer-motion'
77
import posthog from 'posthog-js'
88
import { useEffect, useState, Suspense } from 'react'
9+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
910

1011
import IDEDemo from '@/components/IDEDemo'
1112
import { BlockColor, DecorativeBlocks } from '@/components/ui/decorative-blocks'
@@ -89,7 +90,7 @@ export default function Home() {
8990
}, [session?.user?.id])
9091

9192
const handleFeatureLearnMoreClick = (featureName: string, link: string) => {
92-
posthog.capture('home.feature_learn_more_clicked', {
93+
posthog.capture(AnalyticsEvent.HOME_FEATURE_LEARN_MORE_CLICKED, {
9394
feature: featureName,
9495
link,
9596
})
@@ -167,8 +168,8 @@ export default function Home() {
167168
BuffBench Results
168169
</h2>
169170
<p className="text-xl text-white/70 max-w-2xl mx-auto">
170-
State of the art coding agent evaluation using generated workflows and judging from open
171-
source repositories
171+
State of the art coding agent evaluation using generated
172+
workflows and judging from open source repositories
172173
</p>
173174
</div>
174175

web/src/components/CookieConsentCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import posthog from 'posthog-js'
44
import { useState, useEffect } from 'react'
5+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
56

67
import { Button } from '@/components/ui/button'
78
import { Card, CardContent } from '@/components/ui/card'
@@ -36,13 +37,13 @@ export function CookieConsentCard() {
3637
localStorage.setItem('cookieConsent', 'true')
3738
setVisible(false)
3839
reinitialize()
39-
posthog.capture('cookie_consent.accepted')
40+
posthog.capture(AnalyticsEvent.COOKIE_CONSENT_ACCEPTED)
4041
}
4142

4243
const handleDecline = () => {
4344
localStorage.setItem('cookieConsent', 'false')
4445
setVisible(false)
45-
posthog.capture('cookie_consent.declined')
46+
posthog.capture(AnalyticsEvent.COOKIE_CONSENT_DECLINED)
4647
}
4748

4849
if (!visible || !opacity) {

web/src/components/TerminalDemo.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { motion } from 'framer-motion'
44
import { useTheme } from 'next-themes'
55
import posthog from 'posthog-js'
66
import React, { useState, useEffect, useRef } from 'react'
7+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
78
import { match, P } from 'ts-pattern'
89

910
import Terminal, { ColorMode, TerminalOutput } from './ui/terminal'
@@ -398,7 +399,7 @@ const TerminalDemo = () => {
398399
},
399400
onMutate: (input) => {
400401
// Track terminal input event
401-
posthog.capture('demo_terminal.command_executed', {
402+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_COMMAND_EXECUTED, {
402403
command: input,
403404
})
404405

@@ -495,7 +496,7 @@ const TerminalDemo = () => {
495496

496497
match(cleanInput)
497498
.with('help', () => {
498-
posthog.capture('demo_terminal.help_viewed')
499+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_HELP_VIEWED)
499500
setTerminalLines((prev) => [
500501
...prev,
501502
<TerminalOutput key={`help-${Date.now()}`}>
@@ -538,7 +539,7 @@ const TerminalDemo = () => {
538539
P.string.includes('optimize'),
539540
P.string.includes('performance'),
540541
() => {
541-
posthog.capture('demo_terminal.optimize_requested')
542+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_OPTIMIZE_REQUESTED)
542543
const response = SAMPLE_RESPONSES.optimize
543544

544545
setTerminalLines((prev) => [
@@ -624,7 +625,7 @@ const TerminalDemo = () => {
624625
s.includes('fix') && (s.includes('memory') || s.includes('leak'))
625626
),
626627
() => {
627-
posthog.capture('demo_terminal.fix_memory_leak')
628+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_FIX_MEMORY_LEAK)
628629
setShowError(false)
629630
const response = SAMPLE_RESPONSES.fix
630631

@@ -712,7 +713,7 @@ const TerminalDemo = () => {
712713
.with(
713714
P.when((s: string) => s.includes('refactor') && s.includes('auth')),
714715
() => {
715-
posthog.capture('demo_terminal.refactor_requested')
716+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_REFACTOR_REQUESTED)
716717
const response = SAMPLE_RESPONSES.refactor
717718

718719
setTerminalLines((prev) => [
@@ -815,7 +816,7 @@ const TerminalDemo = () => {
815816
(s.includes('dark') || s.includes('light')) && s.includes('mode')
816817
),
817818
() => {
818-
posthog.capture('demo_terminal.feature_requested')
819+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_FEATURE_REQUESTED)
819820
const response = SAMPLE_RESPONSES.feature
820821

821822
setTerminalLines((prev) => [
@@ -905,7 +906,7 @@ const TerminalDemo = () => {
905906
const currentIndex = themes.indexOf(previewTheme)
906907
const nextTheme = themes[(currentIndex + 1) % themes.length]
907908

908-
posthog.capture('demo_terminal.theme_changed', {
909+
posthog.capture(AnalyticsEvent.DEMO_TERMINAL_THEME_CHANGED, {
909910
from: previewTheme,
910911
to: nextTheme,
911912
})

web/src/components/navbar/user-dropdown.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Image from 'next/image'
55
import { useRouter } from 'next/navigation'
66
import { signOut } from 'next-auth/react'
77
import posthog from 'posthog-js'
8+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
89

910
import type { Session } from 'next-auth'
1011

@@ -54,7 +55,7 @@ export const UserDropdown = ({ session: { user } }: { session: Session }) => {
5455
<DropdownMenuSeparator />
5556
<DropdownMenuItem
5657
onClick={() => {
57-
posthog.capture('auth.logout_completed')
58+
posthog.capture(AnalyticsEvent.AUTH_LOGOUT_COMPLETED)
5859
signOut()
5960
}}
6061
>

web/src/components/onboard/onboarding-flow.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'lucide-react'
1212
import Image from 'next/image'
1313
import posthog from 'posthog-js'
14+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
1415

1516
import { Button } from '@/components/ui/button'
1617
import { EnhancedCopyButton } from '@/components/ui/enhanced-copy-button'
@@ -156,7 +157,7 @@ export function OnboardingFlow({
156157
...prev,
157158
completedSteps: new Set([...prev.completedSteps, step]),
158159
}))
159-
posthog.capture('onboarding_step_completed', { step })
160+
posthog.capture(AnalyticsEvent.ONBOARDING_STEP_COMPLETED, { step })
160161
}
161162

162163
const getTotalSteps = () =>
@@ -166,7 +167,7 @@ export function OnboardingFlow({
166167
const totalSteps = getTotalSteps()
167168
if (progress.currentStep < totalSteps) {
168169
setProgress((prev) => ({ ...prev, currentStep: prev.currentStep + 1 }))
169-
posthog.capture('onboarding_step_viewed', {
170+
posthog.capture(AnalyticsEvent.ONBOARDING_STEP_VIEWED, {
170171
step: progress.currentStep + 1,
171172
})
172173
} else if (onComplete) {
@@ -182,7 +183,9 @@ export function OnboardingFlow({
182183

183184
const handlePMChange = (pm: PackageManager) => {
184185
setProgress((prev) => ({ ...prev, packageManager: pm }))
185-
posthog.capture('onboarding_pm_selected', { packageManager: pm })
186+
posthog.capture(AnalyticsEvent.ONBOARDING_PM_SELECTED, {
187+
packageManager: pm,
188+
})
186189
}
187190

188191
const renderRunCodebuffStep = () => (
@@ -403,7 +406,7 @@ export function OnboardingFlow({
403406
} else {
404407
window.open(editor.href, '_blank', 'noopener,noreferrer')
405408
}
406-
posthog.capture('onboarding_editor_opened', {
409+
posthog.capture(AnalyticsEvent.ONBOARDING_EDITOR_OPENED, {
407410
editor: editor.name,
408411
})
409412
}}

web/src/components/referral/github-signin-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { signIn } from 'next-auth/react'
44
import { useTransition } from 'react'
55
import posthog from 'posthog-js'
6+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
67

78
import { Button } from '@/components/ui/button'
89
import { Icons } from '@/components/icons'
@@ -37,7 +38,7 @@ export const GitHubSignInButton = ({
3738
callbackUrl,
3839
})
3940

40-
posthog.capture('auth.referral_github_login_started', {
41+
posthog.capture(AnalyticsEvent.AUTH_REFERRAL_GITHUB_LOGIN_STARTED, {
4142
referralCode,
4243
referrerName,
4344
callbackUrl,

web/src/components/sign-in/sign-in-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { sleep } from '@codebuff/common/util/promise'
44
import { usePathname, useSearchParams } from 'next/navigation'
55
import { signIn } from 'next-auth/react'
66
import posthog from 'posthog-js'
7+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
78
import { useTransition } from 'react'
89

910
import { toast } from '../ui/use-toast'
@@ -85,7 +86,7 @@ export const SignInButton = ({
8586
}
8687
}
8788

88-
posthog.capture('auth.login_started', {
89+
posthog.capture(AnalyticsEvent.AUTH_LOGIN_STARTED, {
8990
provider: providerName,
9091
callbackUrl: callbackUrl,
9192
})

web/src/components/ui/banner.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useSearchParams } from 'next/navigation'
88
import { useSession } from 'next-auth/react'
99
import posthog from 'posthog-js'
1010
import { Suspense, useState } from 'react'
11+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
1112

1213
import { Button } from './button'
1314
import { useUserProfile } from '@/hooks/use-user-profile'
@@ -55,7 +56,7 @@ function BannerContent() {
5556
href={'/referrals'}
5657
className="underline hover:text-black/80"
5758
onClick={() => {
58-
posthog.capture('referral_banner.clicked', {
59+
posthog.capture(AnalyticsEvent.REFERRAL_BANNER_CLICKED, {
5960
type: isPersonalReferral ? 'personal_referral' : 'general',
6061
source: referrer || undefined,
6162
})

web/src/components/ui/enhanced-copy-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { motion } from 'framer-motion'
44
import { Check, Copy, Terminal } from 'lucide-react'
55
import posthog from 'posthog-js'
66
import { forwardRef, useState } from 'react'
7+
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
78

89
import { BlockColor } from './decorative-blocks'
910

@@ -81,7 +82,7 @@ export function TerminalCopyButton({
8182
pulseBorder?: boolean
8283
}) {
8384
const handleClick = () => {
84-
posthog.capture('home.install_command_copied')
85+
posthog.capture(AnalyticsEvent.HOME_INSTALL_COMMAND_COPIED)
8586
}
8687

8788
return (

0 commit comments

Comments
 (0)