Skip to content

Commit a375057

Browse files
committed
feat: integrate Mixpanel tracking for instruction file creation and define analytics events
1 parent 4b31e08 commit a375057

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

app/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { InstructionsWizard } from "@/components/instructions-wizard"
77
import HeroIconsRow from "@/components/HeroIconsRow"
88
import { ThemeToggle } from "@/components/theme-toggle"
99
import { getHeroIconItems, getHomeMainClasses } from "@/lib/utils"
10+
import { ANALYTICS_EVENTS } from "@/lib/analytics-events"
11+
import { track } from "@/lib/mixpanel"
1012
import { Github } from "lucide-react"
1113
import Link from "next/link"
1214

@@ -56,7 +58,10 @@ export default function Home() {
5658
<Button
5759
size="lg"
5860
className="px-8 py-6 text-lg"
59-
onClick={() => setShowWizard(true)}
61+
onClick={() => {
62+
track(ANALYTICS_EVENTS.CREATE_INSTRUCTIONS_FILE)
63+
setShowWizard(true)
64+
}}
6065
>
6166
Create My Instructions File
6267
</Button>

lib/analytics-events.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const ANALYTICS_EVENTS = {
2+
PAGE_VIEW: "Page View",
3+
CREATE_INSTRUCTIONS_FILE: "Create My Instructions File",
4+
} as const
5+
6+
export type AnalyticsEvent =
7+
(typeof ANALYTICS_EVENTS)[keyof typeof ANALYTICS_EVENTS]

lib/mixpanel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import mixpanel from "mixpanel-browser"
22

3+
import { ANALYTICS_EVENTS, type AnalyticsEvent } from "@/lib/analytics-events"
4+
35
const MIXPANEL_TOKEN = process.env.NEXT_PUBLIC_MIXPANEL_TOKEN
46

57
let isMixpanelInitialized = false
@@ -24,7 +26,7 @@ export const initMixpanel = () => {
2426
isMixpanelInitialized = true
2527
}
2628

27-
export const track = (event: string, props?: Record<string, unknown>) => {
29+
export const track = (event: AnalyticsEvent, props?: Record<string, unknown>) => {
2830
if (typeof window === "undefined" || !isMixpanelInitialized) {
2931
return
3032
}
@@ -41,7 +43,7 @@ export const identify = (userId: string) => {
4143
}
4244

4345
export const trackPageView = (path: string, search?: string) => {
44-
track("Page View", {
46+
track(ANALYTICS_EVENTS.PAGE_VIEW, {
4547
path,
4648
search: search || undefined,
4749
})

0 commit comments

Comments
 (0)