Skip to content

Commit 79debaf

Browse files
Add analytics tracking for downloads, sign-ups, and tab openings
- Add download tracking to DownloadCard component on website download page with platform specification (macos-apple-silicon, macos-intel, linux-appimage, linux-deb, etc.) - Add sign-up tracking in desktop app auth flow (user_signed_up event on SIGNED_IN) - Add tab opening tracking with view specification in desktop app (tab_opened event with view type) Co-Authored-By: [email protected] <[email protected]>
1 parent e02291f commit 79debaf

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

apps/desktop/src/auth.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
useState,
2121
} from "react";
2222

23+
import { commands as analyticsCommands } from "@hypr/plugin-analytics";
2324
import { commands } from "@hypr/plugin-auth";
2425

2526
import { env } from "./env";
@@ -238,6 +239,11 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
238239
setServerReachable(false);
239240
}
240241
}
242+
if (event === "SIGNED_IN" && session) {
243+
void analyticsCommands.event({
244+
event: "user_signed_up",
245+
});
246+
}
241247
setSession(session);
242248
});
243249

apps/desktop/src/store/zustand/tabs/basic.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { StoreApi } from "zustand";
22

3+
import { commands as analyticsCommands } from "@hypr/plugin-analytics";
4+
35
import { id } from "../../../utils";
46
import type { LifecycleState } from "./lifecycle";
57
import type { NavigationState, TabHistory } from "./navigation";
@@ -34,10 +36,18 @@ export const createBasicSlice = <
3436
openCurrent: (tab) => {
3537
const { tabs, history } = get();
3638
set(openTab(tabs, tab, history, true));
39+
void analyticsCommands.event({
40+
event: "tab_opened",
41+
view: tab.type,
42+
});
3743
},
3844
openNew: (tab) => {
3945
const { tabs, history } = get();
4046
set(openTab(tabs, tab, history, false));
47+
void analyticsCommands.event({
48+
event: "tab_opened",
49+
view: tab.type,
50+
});
4151
},
4252
select: (tab) => {
4353
const { tabs } = get();

apps/web/src/routes/_view/download/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { cn } from "@hypr/utils";
88
import { Image } from "@/components/image";
99
import { SlashSeparator } from "@/components/slash-separator";
1010
import { usePlatform } from "@/hooks/use-platform";
11+
import { useAnalytics } from "@/hooks/use-posthog";
1112

1213
export const Route = createFileRoute("/_view/download/")({
1314
component: Component,
@@ -60,18 +61,21 @@ function Component() {
6061
spec="macOS 14.2+ (Apple Silicon)"
6162
downloadUrl="/download/apple-silicon"
6263
available={true}
64+
platform="macos-apple-silicon"
6365
/>
6466
<DownloadCard
6567
iconName="simple-icons:apple"
6668
spec="macOS 14.2+ (Intel)"
6769
downloadUrl="/download/apple-intel"
6870
available={true}
71+
platform="macos-intel"
6972
/>
7073
<DownloadCard
7174
iconName="simple-icons:windows"
7275
spec="Windows"
7376
downloadUrl="#"
7477
available={false}
78+
platform="windows"
7579
/>
7680
</div>
7781

@@ -84,12 +88,14 @@ function Component() {
8488
spec="Linux (AppImage)"
8589
downloadUrl="/download/linux-appimage"
8690
available={true}
91+
platform="linux-appimage"
8792
/>
8893
<DownloadCard
8994
iconName="simple-icons:linux"
9095
spec="Linux (.deb)"
9196
downloadUrl="/download/linux-deb"
9297
available={true}
98+
platform="linux-deb"
9399
/>
94100
</div>
95101
</div>
@@ -115,12 +121,14 @@ function Component() {
115121
spec="iOS 15+"
116122
downloadUrl="#"
117123
available={false}
124+
platform="ios"
118125
/>
119126
<DownloadCard
120127
iconName="simple-icons:android"
121128
spec="Android 10+"
122129
downloadUrl="#"
123130
available={false}
131+
platform="android"
124132
/>
125133
</div>
126134
</div>
@@ -191,12 +199,24 @@ function DownloadCard({
191199
spec,
192200
downloadUrl,
193201
available,
202+
platform,
194203
}: {
195204
iconName: string;
196205
spec: string;
197206
downloadUrl: string;
198207
available: boolean;
208+
platform: string;
199209
}) {
210+
const { track } = useAnalytics();
211+
212+
const handleClick = () => {
213+
track("download_clicked", {
214+
platform,
215+
spec,
216+
source: "download_page",
217+
});
218+
};
219+
200220
return (
201221
<div className="flex flex-col items-center p-6 rounded-sm border border-neutral-100 bg-white hover:bg-stone-50 transition-all duration-200">
202222
<Icon icon={iconName} className="text-5xl text-neutral-700 mb-4" />
@@ -206,6 +226,7 @@ function DownloadCard({
206226
<a
207227
href={downloadUrl}
208228
download
229+
onClick={handleClick}
209230
className="group w-full px-4 h-11 flex items-center justify-center bg-linear-to-t from-stone-600 to-stone-500 text-white rounded-full shadow-md hover:shadow-lg hover:scale-[102%] active:scale-[98%] transition-all text-base font-medium"
210231
>
211232
Download

0 commit comments

Comments
 (0)