Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(desktop): track clicks across the spaces navigation and project menu (#99577)

Adam Leithfb14298f982b
diff --git a/products/desktop/packages/shared/src/analytics-events.ts b/products/desktop/packages/shared/src/analytics-events.ts
index bb1a739e5d12..13cd760aed48 100644
--- a/products/desktop/packages/shared/src/analytics-events.ts
+++ b/products/desktop/packages/shared/src/analytics-events.ts
@@ -313,6 +313,30 @@ export interface SidebarNavItemClickedProperties {
layout?: SidebarLayout;
}
+/** Every row of the account / project / org menu, plus opening it. */
+export type ProjectMenuAction =
+ | "open"
+ | "switch_project"
+ | "switch_organization"
+ | "create_project"
+ | "create_organization"
+ | "discord"
+ | "changelog"
+ | "website"
+ | "privacy_policy"
+ | "keyboard_shortcuts"
+ | "archived"
+ | "settings"
+ | "log_out";
+
+export interface ProjectMenuActionProperties {
+ action: ProjectMenuAction;
+ /** The rail draws the trigger as an icon, the code sidebar as a footer row. */
+ appearance: "row" | "icon";
+ /** For switch_project / switch_organization: whether the pick moved anywhere. */
+ changed?: boolean;
+}
+
export type TaskListSurface = "sidebar" | "space" | "saved_search";
export interface TaskListGroupingChangedProperties {
@@ -1149,7 +1173,13 @@ type ChannelActionType =
| "mention_member"
| "view_activity"
| "open_mention"
- | "activity_tab_change";
+ | "activity_tab_change"
+ /** Sessions ↔ Canvases in a space's sidebar list. */
+ | "space_tab_change"
+ | "expand_channel"
+ | "activity_unreads_toggle"
+ | "activity_mark_all_read"
+ | "activity_load_more";
type TaskFeedActionType = "create" | "update" | "delete" | "open";
@@ -1170,14 +1200,19 @@ export interface ChannelActionProperties {
task_id?: string;
/** For file_task: destination channel when different from `channel_id`. */
target_channel_id?: string;
- /** For nav_click: which destination ("home"|"activity"|"inbox"|"canvas"|"agents"|"files"|"settings"). */
+ /**
+ * For nav_click: which destination ("home"|"activity"|"inbox"|"canvas"|"agents"|"files"|"settings").
+ * A space's sidebar rows send their page key, where "home" is the row labelled "Feed".
+ */
nav_target?: string;
/** For mention_member: the tagged teammate's user uuid. */
mentioned_user_id?: string;
/** For new_task_suggestion: the starter-prompt card label. */
suggestion_label?: string;
- /** For activity_tab_change: the tab landed on. */
+ /** The tab landed on; space_tab_change sends the kind it lists ("task" reads "Sessions"). */
tab?: string;
+ /** For activity_unreads_toggle: the state being entered. */
+ enabled?: boolean;
/** Whether the underlying mutation resolved successfully. */
success?: boolean;
/** For auto_archive_update: the selected inactivity window. Null disables it. */
@@ -1714,6 +1749,7 @@ export const ANALYTICS_EVENTS = {
CANVAS_RENDERED: "Canvas rendered",
CANVAS_RUNTIME_ERROR: "Canvas runtime error",
CONTEXT_ACTION: "Context action",
+ PROJECT_MENU_ACTION: "Project menu action",
// Autoresearch events
AUTORESEARCH_ARMED: "Autoresearch armed",
@@ -1926,6 +1962,7 @@ export type EventPropertyMap = {
[ANALYTICS_EVENTS.CANVAS_RENDERED]: CanvasRenderedProperties;
[ANALYTICS_EVENTS.CANVAS_RUNTIME_ERROR]: CanvasRuntimeErrorProperties;
[ANALYTICS_EVENTS.CONTEXT_ACTION]: ContextActionProperties;
+ [ANALYTICS_EVENTS.PROJECT_MENU_ACTION]: ProjectMenuActionProperties;
// Autoresearch events
[ANALYTICS_EVENTS.AUTORESEARCH_ARMED]: AutoresearchArmedProperties;
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityFeedList.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityFeedList.tsx
index 7d5c784cc1df..92752d03fa0d 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityFeedList.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityFeedList.tsx
@@ -156,6 +156,10 @@ export function ActivityFeedList({
};
const markAllRead = () => {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "activity_mark_all_read",
+ surface: "activity_panel",
+ });
markTasksRead(activityReadPayload(unreadItems));
};
@@ -184,7 +188,7 @@ export function ActivityFeedList({
onClear={() => setQuery("")}
actions={
<>
- <ActivityUnreadsToggle />
+ <ActivityUnreadsToggle surface="activity_panel" />
<ActivityActionsMenu
loadedUnreadCount={unreadItems.length}
totalUnreadCount={unreadCount}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx
index 6c970d539f75..07cb82a384e8 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityUnreadsToggle.tsx
@@ -1,9 +1,18 @@
import { Label, Switch } from "@posthog/quill";
+import {
+ ANALYTICS_EVENTS,
+ type ChannelsSurface,
+} from "@posthog/shared/analytics-events";
import { useActivityFilterStore } from "@posthog/ui/features/canvas/stores/activityFilterStore";
+import { track } from "@posthog/ui/shell/analytics";
import { useId } from "react";
/** Narrows both Activity surfaces down to what hasn't been read yet. */
-export function ActivityUnreadsToggle() {
+export function ActivityUnreadsToggle({
+ surface,
+}: {
+ surface: ChannelsSurface;
+}) {
const switchId = useId();
const unreadsOnly = useActivityFilterStore((state) => state.unreadsOnly);
const setUnreadsOnly = useActivityFilterStore(
@@ -17,7 +26,14 @@ export function ActivityUnreadsToggle() {
id={switchId}
size="sm"
checked={unreadsOnly}
- onCheckedChange={setUnreadsOnly}
+ onCheckedChange={(next: boolean) => {
+ setUnreadsOnly(next);
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "activity_unreads_toggle",
+ surface,
+ enabled: next,
+ });
+ }}
/>
</div>
);
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx b/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx
index 3832ece412b0..89fe26d1e5c0 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ActivityView.tsx
@@ -105,6 +105,10 @@ export function ActivityView() {
[markTasksRead],
);
const markAllRead = useCallback(() => {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "activity_mark_all_read",
+ surface: "activity",
+ });
markTasksRead(activityReadPayload(unreadItems));
}, [markTasksRead, unreadItems]);
useEffect(() => {
@@ -122,7 +126,13 @@ export function ActivityView() {
variant="outline"
loading={taskActivity.isFetchingNextPage}
disabled={taskActivity.isFetchingNextPage}
- onClick={() => void taskActivity.fetchNextPage()}
+ onClick={() => {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "activity_load_more",
+ surface: "activity",
+ });
+ void taskActivity.fetchNextPage();
+ }}
>
Load more
</Button>
@@ -206,7 +216,7 @@ export function ActivityView() {
</p>
</div>
<div className="flex shrink-0 items-center gap-2">
- <ActivityUnreadsToggle />
+ <ActivityUnreadsToggle surface="activity" />
<ActivityActionsMenu
loadedUnreadCount={unreadItems.length}
totalUnreadCount={unreadCount}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx
index 4e7e3e5514ee..4986641e3c75 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelSidebar.tsx
@@ -15,6 +15,7 @@ import {
TabsTrigger,
} from "@posthog/quill";
import { LOOPS_FLAG } from "@posthog/shared";
+import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";
import { ChannelBackRow } from "@posthog/ui/features/canvas/components/ChannelBackRow";
import { ChannelItemsPane } from "@posthog/ui/features/canvas/components/ChannelItemsPane";
import { ChannelsFab } from "@posthog/ui/features/canvas/components/ChannelsFab";
@@ -28,6 +29,7 @@ import { SHORTCUTS } from "@posthog/ui/features/command/keyboard-shortcuts";
import { useFeatureFlag } from "@posthog/ui/features/feature-flags/useFeatureFlag";
import { SidebarKbdHint } from "@posthog/ui/features/sidebar/components/items/SidebarKbdHint";
import { SidebarItem } from "@posthog/ui/features/sidebar/components/SidebarItem";
+import { track } from "@posthog/ui/shell/analytics";
import { useNavigate, useRouterState } from "@tanstack/react-router";
import { useMemo, useState } from "react";
@@ -128,7 +130,17 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
tab: "task" as ChannelTab,
});
const tab = chosenTab.channelId === channelId ? chosenTab.tab : "task";
- const setTab = (next: ChannelTab) => setChosenTab({ channelId, tab: next });
+ const setTab = (next: ChannelTab) => {
+ setChosenTab({ channelId, tab: next });
+ // Only a real change, the way the list's own grouping control reports.
+ if (next === tab) return;
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "space_tab_change",
+ surface: "sidebar",
+ channel_id: channelId,
+ tab: next,
+ });
+ };
const { channels } = useChannels();
// By type, not by name: the list relabels the personal channel on the way in,
@@ -152,6 +164,16 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
return task ? `task:${task[1]}` : null;
}, [pathname]);
+ const navigateTo = (target: string, go: () => void) => () => {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "nav_click",
+ surface: "sidebar",
+ channel_id: channelId,
+ nav_target: target,
+ });
+ go();
+ };
+
// Label comes from the shared space-page table, so a sidebar row and the
// header breadcrumb for the same page can never disagree. No icon: this is a
// short list of words, and glyphs here only compete with the status dots
@@ -165,7 +187,8 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
depth={0}
label={channelPageLabel(page)}
isActive={pathname === to}
- onClick={onClick}
+ // The page key, not its label: renaming a row shouldn't split the series.
+ onClick={navigateTo(page, onClick)}
/>
);
@@ -180,12 +203,12 @@ export function ChannelSidebar({ channelId }: { channelId: string }) {
depth={0}
label="New session"
isActive={pathname === `${base}/new`}
- onClick={() =>
+ onClick={navigateTo("new_session", () => {
void navigate({
to: "/spaces/$channelId/new",
params: { channelId },
- })
- }
+ });
+ })}
// ⌘N inside a space lands on this same route (openTaskInput scopes to
// the channel you're in), so the row can claim the key.
endHint={<SidebarKbdHint keys={SHORTCUTS.NEW_TASK} />}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelsList.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelsList.tsx
index 54b6c0b59ca9..484515922d03 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelsList.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelsList.tsx
@@ -338,6 +338,18 @@ function SpaceAttentionDot({
);
}
+/**
+ * The caret opens a space onto its sessions without entering it, so it reports
+ * on its own rather than as a nav click.
+ */
+function trackSpaceDisclosure(channelId: string, expanded: boolean): void {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: expanded ? "collapse_channel" : "expand_channel",
+ surface: "sidebar",
+ channel_id: channelId,
+ });
+}
+
/**
* The tree's disclosure caret, in its own fixed slot ahead of the space glyph.
* Always drawn: a control that only appears on hover moves the row's contents
@@ -418,6 +430,12 @@ function useOpenSpaceTask(): (spaceId: string, taskId: string) => void {
const setCurrentChannel = useCurrentChannelStore((s) => s.setCurrentChannel);
return (spaceId, taskId) => {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "open_task",
+ surface: "sidebar",
+ channel_id: spaceId,
+ task_id: taskId,
+ });
keepListForRoute(spaceId);
// Still scoped: the space is where the session lives, so anything that then
// asks for the channel pane opens on the right one.
@@ -611,7 +629,14 @@ function ViewAllRow({
<SpaceRowSurface
asOption={asOption}
optionValue={viewAllValue(spaceId)}
- onClick={onOpenSpace}
+ onClick={() => {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "view_more_tasks",
+ surface: "sidebar",
+ channel_id: spaceId,
+ });
+ onOpenSpace();
+ }}
className={cn("pl-8 text-[13px]", ROW_LABEL_TONE)}
>
{/* The arrow takes the slot a session's status dot has, so the guide's
@@ -1218,7 +1243,10 @@ const ChannelSection = memo(
<SpaceDisclosure
expanded={expanded}
spaceName={channel.name}
- onToggle={() => onToggleExpanded(channel.id)}
+ onToggle={() => {
+ trackSpaceDisclosure(channel.id, expanded);
+ onToggleExpanded(channel.id);
+ }}
/>
)}
{glyph}
@@ -1603,7 +1631,10 @@ const PersonalChannelRow = memo(function PersonalChannelRow({
<SpaceDisclosure
expanded={expanded}
spaceName={PERSONAL_CHANNEL_LABEL}
- onToggle={() => onToggleExpanded(meChannel.id)}
+ onToggle={() => {
+ trackSpaceDisclosure(meChannel.id, expanded);
+ onToggleExpanded(meChannel.id);
+ }}
/>
)}
{glyph}
diff --git a/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx b/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx
index 491130c5e53c..2a70ffadde2b 100644
--- a/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/components/NavRail.tsx
@@ -317,7 +317,14 @@ function NavRailImpl() {
label="Search"
shortcut={formatHotkey(SHORTCUTS.COMMAND_MENU)}
isActive={false}
- onClick={toggleCommandMenu}
+ onClick={() => {
+ track(ANALYTICS_EVENTS.SIDEBAR_NAV_ITEM_CLICKED, {
+ item: "search",
+ in_more: false,
+ layout: "channels",
+ });
+ toggleCommandMenu();
+ }}
/>
<NavIcon
icon={<GearSix size={16} />}
diff --git a/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx b/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx
index 69043d749c58..a3102566ac25 100644
--- a/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx
+++ b/products/desktop/packages/ui/src/features/canvas/hooks/useChannelItems.tsx
@@ -6,6 +6,7 @@ import {
type ChannelWorkspaceFacts,
} from "@posthog/core/canvas/channelItems";
import { formatBulkResult } from "@posthog/core/sidebar/selection";
+import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";
import { useArchivedTaskIds } from "@posthog/ui/features/archive/useArchivedTaskIds";
import { useArchiveTask } from "@posthog/ui/features/archive/useArchiveTask";
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
@@ -26,6 +27,7 @@ import { useTaskViewed } from "@posthog/ui/features/sidebar/useTaskViewed";
import { useTasks } from "@posthog/ui/features/tasks/useTasks";
import { useWorkspaces } from "@posthog/ui/features/workspace/useWorkspace";
import { toast } from "@posthog/ui/primitives/toast";
+import { track } from "@posthog/ui/shell/analytics";
import { useNavigate } from "@tanstack/react-router";
import { useMemo } from "react";
@@ -160,11 +162,25 @@ export function useChannelItems(channelId: string): {
() => ({
open: (item) => {
if (item.kind === "canvas") {
+ // Canvases report as dashboard opens, the same event the canvases
+ // pane fires, so the two entry points can be compared.
+ track(ANALYTICS_EVENTS.DASHBOARD_ACTION, {
+ action_type: "open",
+ surface: "sidebar",
+ channel_id: channelId,
+ dashboard_id: item.id,
+ });
void navigate({
to: "/spaces/$channelId/dashboards/$dashboardId",
params: { channelId, dashboardId: item.id },
});
} else {
+ track(ANALYTICS_EVENTS.CHANNEL_ACTION, {
+ action_type: "open_task",
+ surface: "sidebar",
+ channel_id: channelId,
+ task_id: item.id,
+ });
void navigate({
to: "/spaces/$channelId/tasks/$taskId",
params: { channelId, taskId: item.id },
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/ProjectSwitcher.tsx b/products/desktop/packages/ui/src/features/sidebar/components/ProjectSwitcher.tsx
index 57644abbcba2..a30ad2e2c330 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/ProjectSwitcher.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/ProjectSwitcher.tsx
@@ -31,6 +31,10 @@ import {
ItemTitle,
} from "@posthog/quill";
import { EXTERNAL_LINKS } from "@posthog/shared";
+import {
+ ANALYTICS_EVENTS,
+ type ProjectMenuAction,
+} from "@posthog/shared/analytics-events";
import { useArchivedTaskIds } from "@posthog/ui/features/archive/useArchivedTaskIds";
import { useOptionalAuthenticatedClient } from "@posthog/ui/features/auth/authClient";
import { useAuthStateValue } from "@posthog/ui/features/auth/store";
@@ -52,6 +56,7 @@ import {
SearchableMenuFlyout,
} from "@posthog/ui/primitives/SearchableMenuFlyout";
import { navigateToArchived } from "@posthog/ui/router/navigationBridge";
+import { track } from "@posthog/ui/shell/analytics";
import { openExternalUrl } from "@posthog/ui/shell/openExternal";
import { isMac } from "@posthog/ui/utils/platform";
import { getPostHogUrl } from "@posthog/ui/utils/urls";
@@ -75,10 +80,23 @@ export function ProjectSwitcher({
}: ProjectSwitcherProps = {}) {
const [popoverOpen, setPopoverOpen] = useState(false);
+ const trackMenu = (
+ action: ProjectMenuAction,
+ properties?: { changed: boolean },
+ ): void => {
+ track(ANALYTICS_EVENTS.PROJECT_MENU_ACTION, {
+ action,
+ appearance,
+ ...properties,
+ });
+ };
+
const holdPeek = useHoldSidebarPeek();
const handleOpenChange = (next: boolean): void => {
setPopoverOpen(next);
holdPeek(next);
+ // Only the way in: a menu dismissed without a pick is not an action.
+ if (next) trackMenu("open");
};
const currentOrgId = useAuthStateValue((state) => state.currentOrgId);
@@ -151,6 +169,7 @@ export function ProjectSwitcher({
);
const handleProjectSelect = (projectId: number) => {
+ trackMenu("switch_project", { changed: projectId !== currentProjectId });
if (projectId !== currentProjectId) {
selectProjectMutation.mutate(projectId);
}
@@ -158,6 +177,7 @@ export function ProjectSwitcher({
};
const handleOrgSelect = (orgId: string) => {
+ trackMenu("switch_organization", { changed: orgId !== currentOrgId });
if (orgId !== currentOrgId) {
switchOrgMutation.mutate(orgId);
}
@@ -165,18 +185,21 @@ export function ProjectSwitcher({
};
const handleCreateProject = () => {
+ trackMenu("create_project");
const url = getPostHogUrl("/organization/create-project");
if (url) openExternalUrl(url);
setPopoverOpen(false);
};
const handleCreateOrg = () => {
+ trackMenu("create_organization");
const url = getPostHogUrl("/create-organization");
if (url) openExternalUrl(url);
setPopoverOpen(false);
};
const handleArchived = () => {
+ trackMenu("archived");
setPopoverOpen(false);
navigateToArchived();
};
@@ -190,26 +213,36 @@ export function ProjectSwitcher({
openSettings(category);
};
- const handleSettings = () => goToSettings("general");
+ const handleSettings = () => {
+ trackMenu("settings");
+ goToSettings("general");
+ };
- const handleKeyboardShortcuts = () => goToSettings("shortcuts");
+ const handleKeyboardShortcuts = () => {
+ trackMenu("keyboard_shortcuts");
+ goToSettings("shortcuts");
+ };
- const handleOpenExternal = (url: string) => {
+ const handleOpenExternal = (action: ProjectMenuAction, url: string) => {
+ trackMenu(action);
openExternalUrl(url);
setPopoverOpen(false);
};
const handleDiscord = () => {
+ trackMenu("discord");
openExternalUrl(EXTERNAL_LINKS.discord);
setPopoverOpen(false);
};
const handleViewChangelog = () => {
+ trackMenu("changelog");
useWhatsNewStore.getState().open();
setPopoverOpen(false);
};
const handleLogout = () => {
+ trackMenu("log_out");
setPopoverOpen(false);
logoutMutation.mutate();
};
@@ -358,14 +391,18 @@ export function ProjectSwitcher({
</DropdownMenuSubTrigger>
<DropdownMenuSubContent side="right" sideOffset={4}>
<DropdownMenuItem
- onClick={() => handleOpenExternal(EXTERNAL_LINKS.website)}
+ onClick={() =>
+ handleOpenExternal("website", EXTERNAL_LINKS.website)
+ }
>
<ArrowSquareOut size={14} className="text-gray-11" />
Website
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
- onClick={() => handleOpenExternal(EXTERNAL_LINKS.privacy)}
+ onClick={() =>
+ handleOpenExternal("privacy_policy", EXTERNAL_LINKS.privacy)
+ }
>
<ShieldCheck size={14} className="text-gray-11" />
Privacy Policy