-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.ts
More file actions
66 lines (58 loc) · 1.71 KB
/
Copy pathanalytics.ts
File metadata and controls
66 lines (58 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Track a custom event in Plausible Analytics.
*
* @param eventName - Name of the event (e.g., "signup", "analyze_repo")
* @param props - Optional custom properties to attach to the event
* @param options - Optional tracking options (interactive, revenue)
*/
export function trackEvent(
eventName: string,
props?: Record<string, string>,
options?: {
interactive?: boolean;
revenue?: { amount: number; currency: string };
}
) {
// Only track if domain is configured
if (!process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN) {
return;
}
if (typeof window === "undefined") {
return;
}
void import("@plausible-analytics/tracker").then(({ track }) => {
track(eventName, {
props,
interactive: options?.interactive,
revenue: options?.revenue,
});
});
}
/**
* Pre-defined event names for type safety and consistency.
*/
export const AnalyticsEvents = {
// Auth events
SIGN_IN: "sign_in",
SIGN_OUT: "sign_out",
// Repo events
REPO_CONNECT: "repo_connect",
REPO_DISCONNECT: "repo_disconnect",
REPO_ANALYZE: "repo_analyze",
REPO_REANALYZE: "repo_reanalyze",
// Profile events
PROFILE_VIEW: "profile_view",
PROFILE_SHARE: "profile_share",
PROFILE_DOWNLOAD_IMAGE: "profile_download_image",
// Analysis events
ANALYSIS_VIEW: "analysis_view",
ANALYSIS_SHARE: "analysis_share",
// Settings events
PUBLIC_PROFILE_ENABLED: "public_profile_enabled",
PUBLIC_PROFILE_DISABLED: "public_profile_disabled",
LLM_KEY_ADDED: "llm_key_added",
LLM_KEY_REMOVED: "llm_key_removed",
LLM_OPT_IN_ENABLED: "llm_opt_in_enabled",
LLM_OPT_IN_DISABLED: "llm_opt_in_disabled",
} as const;
export type AnalyticsEvent = (typeof AnalyticsEvents)[keyof typeof AnalyticsEvents];