aboutsummaryrefslogtreecommitdiff
path: root/apps/web/lib/analytics.ts
blob: 84eda62b9d3ab99298a098b2e0476563e68afa77 (plain) (blame)
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
import posthog from "posthog-js"

// Helper function to safely capture events
const safeCapture = (
	eventName: string,
	properties?: Record<string, unknown>,
) => {
	if (posthog.__loaded) {
		posthog.capture(eventName, properties)
	}
}

export const analytics = {
	userSignedOut: () => safeCapture("user_signed_out"),

	memoryAdded: (props: {
		type: "note" | "link" | "file"
		project_id?: string
		content_length?: number
		file_size?: number
		file_type?: string
	}) => safeCapture("memory_added", props),

	memoryDetailOpened: () => safeCapture("memory_detail_opened"),

	projectCreated: () => safeCapture("project_created"),

	newChatStarted: () => safeCapture("new_chat_started"),
	chatHistoryViewed: () => safeCapture("chat_history_viewed"),
	chatDeleted: () => safeCapture("chat_deleted"),

	viewModeChanged: (mode: "graph" | "list") =>
		safeCapture("view_mode_changed", { mode }),

	documentCardClicked: () => safeCapture("document_card_clicked"),

	billingViewed: () => safeCapture("billing_viewed"),
	upgradeInitiated: () => safeCapture("upgrade_initiated"),
	upgradeCompleted: () => safeCapture("upgrade_completed"),
	billingPortalOpened: () => safeCapture("billing_portal_opened"),

	connectionAdded: (provider: string) =>
		safeCapture("connection_added", { provider }),
	connectionDeleted: () => safeCapture("connection_deleted"),
	connectionAuthStarted: () => safeCapture("connection_auth_started"),
	connectionAuthCompleted: () => safeCapture("connection_auth_completed"),
	connectionAuthFailed: () => safeCapture("connection_auth_failed"),

	mcpViewOpened: () => safeCapture("mcp_view_opened"),
	mcpInstallCmdCopied: () => safeCapture("mcp_install_cmd_copied"),

	extensionInstallClicked: () => safeCapture("extension_install_clicked"),

	// nova analytics
	documentAdded: (props: {
		type: "note" | "link" | "file" | "connect"
		project_id?: string
	}) => safeCapture("document_added", props),

	newChatCreated: () => safeCapture("new_chat_created"),

	mcpModalOpened: () => safeCapture("mcp_modal_opened"),

	addDocumentModalOpened: () => safeCapture("add_document_modal_opened"),
}