: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): report the real tile count on the tab tiled event (#104642)
Shy Alterb7f43840a9c6
diff --git a/products/desktop/packages/ui/src/features/tab-tiling/tileActions.test.ts b/products/desktop/packages/ui/src/features/tab-tiling/tileActions.test.tsnew file mode 100644index 000000000000..34d128eda1ee--- /dev/null+++ b/products/desktop/packages/ui/src/features/tab-tiling/tileActions.test.ts@@ -0,0 +1,41 @@+import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";+import { track } from "@posthog/ui/shell/analytics";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { tileBeside, untileTracked } from "./tileActions";+import { useTileLayoutStore } from "./tileLayoutStore";++vi.mock("@posthog/ui/shell/analytics", () => ({ track: vi.fn() }));++describe("tile analytics", () => {+ beforeEach(() => {+ vi.mocked(track).mockClear();+ useTileLayoutStore.setState({+ groups: [],+ activeByGroup: {},+ names: {},+ nextSplitNumber: 1,+ });+ });++ it("reports how many tabs the tile group holds", () => {+ tileBeside("b", "a", "right", "strip");+ expect(track).toHaveBeenLastCalledWith(ANALYTICS_EVENTS.BROWSER_TAB_TILED, {+ edge: "right",+ source: "strip",+ tile_count: 2,+ });++ tileBeside("c", "a", "bottom", "tile");+ expect(track).toHaveBeenLastCalledWith(ANALYTICS_EVENTS.BROWSER_TAB_TILED, {+ edge: "bottom",+ source: "tile",+ tile_count: 3,+ });++ untileTracked("c");+ expect(track).toHaveBeenLastCalledWith(+ ANALYTICS_EVENTS.BROWSER_TAB_UNTILED,+ { tile_count: 2 },+ );+ });+});diff --git a/products/desktop/packages/ui/src/features/tab-tiling/tileActions.ts b/products/desktop/packages/ui/src/features/tab-tiling/tileActions.tsindex 5c05e883f8e5..5eb326804a8f 100644--- a/products/desktop/packages/ui/src/features/tab-tiling/tileActions.ts+++ b/products/desktop/packages/ui/src/features/tab-tiling/tileActions.ts@@ -11,9 +11,9 @@ export function tileBeside(edge: TileEdge,source: TileSource,): void {- const store = useTileLayoutStore.getState();- store.tileTab(tabId, targetTabId, edge);- const group = groupForTab(store.groups, tabId);+ useTileLayoutStore.getState().tileTab(tabId, targetTabId, edge);+ // The group only exists after the write, so read the state again.+ const group = groupForTab(useTileLayoutStore.getState().groups, tabId);track(ANALYTICS_EVENTS.BROWSER_TAB_TILED, {edge,source,diff --git a/products/desktop/packages/ui/src/features/tab-tiling/useFocusTab.ts b/products/desktop/packages/ui/src/features/tab-tiling/useFocusTab.tsindex 40223b910eb3..f08439fdabaa 100644--- a/products/desktop/packages/ui/src/features/tab-tiling/useFocusTab.ts+++ b/products/desktop/packages/ui/src/features/tab-tiling/useFocusTab.ts@@ -2,17 +2,15 @@ import { ANALYTICS_EVENTS } from "@posthog/shared/analytics-events";import type { TabRef } from "@posthog/ui/features/browser-tabs/useGoToTab";import { useGoToTab } from "@posthog/ui/features/browser-tabs/useGoToTab";import { track } from "@posthog/ui/shell/analytics";-import { useCallback, useRef } from "react";+import { useCallback } from "react";import { useTileLayoutStore } from "./tileLayoutStore";import { groupForTab, tabIdsIn } from "./tileTree";export function useFocusTab(activeTabId: string | null): (tab: TabRef) => void {const goToTab = useGoToTab();- const activeRef = useRef(activeTabId);- activeRef.current = activeTabId;return useCallback((tab: TabRef) => {- const active = activeRef.current;+ const active = activeTabId;const { groups, noteActive } = useTileLayoutStore.getState();const target = groupForTab(groups, tab.id);const shown = active ? groupForTab(groups, active) : null;@@ -27,6 +25,6 @@ export function useFocusTab(activeTabId: string | null): (tab: TabRef) => void {}goToTab(tab);},- [goToTab],+ [goToTab, activeTabId],);}