From dba0cf7005b6f0d398eeb8618616dfdf327c5c28 Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Wed, 18 Feb 2026 02:09:12 +0530 Subject: [PATCH 1/5] Update analytics package --- package.json | 2 +- pnpm-lock.yaml | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 11a3a3367f3..b54c59e366f 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@fontsource/fira-code": "^5", "@fontsource/inter": "^5", "@formatjs/intl-segmenter": "^12.0.0", - "@matrix-org/analytics-events": "^0.31.0", + "@matrix-org/analytics-events": "^0.32.0", "@matrix-org/emojibase-bindings": "^1.5.0", "@matrix-org/react-sdk-module-api": "^2.4.0", "@sentry/browser": "^10.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ad9629eb2b0..68f09d898e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -95,8 +95,8 @@ importers: specifier: ^12.0.0 version: 12.1.1 '@matrix-org/analytics-events': - specifier: ^0.31.0 - version: 0.31.0 + specifier: ^0.32.0 + version: 0.32.0 '@matrix-org/emojibase-bindings': specifier: ^1.5.0 version: 1.5.0 @@ -222,7 +222,7 @@ importers: version: 1.0.3 matrix-js-sdk: specifier: github:matrix-org/matrix-js-sdk#develop - version: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/327d2fa7c8dca5c881969ca0a4ce279c36389750 + version: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/4f0696e2a4e070325cc63e9c5cf42f41e2f5ea6e matrix-widget-api: specifier: ^1.16.1 version: 1.17.0 @@ -2627,8 +2627,8 @@ packages: '@maplibre/vt-pbf@4.2.1': resolution: {integrity: sha512-IxZBGq/+9cqf2qdWlFuQ+ZfoMhWpxDUGQZ/poPHOJBvwMUT1GuxLo6HgYTou+xxtsOsjfbcjI8PZaPCtmt97rA==} - '@matrix-org/analytics-events@0.31.0': - resolution: {integrity: sha512-rZrtHt6X1cnleWPPSp56fngYBiq2Db1jQt+bATEUlDwwiMCrG3D5ojYqOQ03MlgySLIZLBAAam//bZAqiGWOwQ==} + '@matrix-org/analytics-events@0.32.0': + resolution: {integrity: sha512-Z5hl4wJdIvskFCOzHAh/7tQKlyvJ/5/JdvfTTySuJ/v47VmkCGvkdDD6ODT9+15psj3O8Cc2Ofgh2KqDJjd6kg==} '@matrix-org/emojibase-bindings@1.5.0': resolution: {integrity: sha512-+W9/ow2Z3iQa7ZOF698PBhwNcgGkn36B5Sr8VDPx8N8CH7+Uw+7TrtbtKPZVdgf4m/THmgmfX40jS5YDBsLaYg==} @@ -7709,8 +7709,8 @@ packages: matrix-events-sdk@0.0.1: resolution: {integrity: sha512-1QEOsXO+bhyCroIe2/A5OwaxHvBm7EsSQ46DEDn8RBIfQwN5HWBpFvyWWR4QY0KHPPnnJdI99wgRiAl7Ad5qaA==} - matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/327d2fa7c8dca5c881969ca0a4ce279c36389750: - resolution: {tarball: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/327d2fa7c8dca5c881969ca0a4ce279c36389750} + matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/4f0696e2a4e070325cc63e9c5cf42f41e2f5ea6e: + resolution: {tarball: https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/4f0696e2a4e070325cc63e9c5cf42f41e2f5ea6e} version: 40.2.0 engines: {node: '>=22.0.0'} @@ -12580,7 +12580,7 @@ snapshots: pbf: 4.0.1 supercluster: 8.0.1 - '@matrix-org/analytics-events@0.31.0': {} + '@matrix-org/analytics-events@0.32.0': {} '@matrix-org/emojibase-bindings@1.5.0': dependencies: @@ -18509,7 +18509,7 @@ snapshots: matrix-events-sdk@0.0.1: {} - matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/327d2fa7c8dca5c881969ca0a4ce279c36389750: + matrix-js-sdk@https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/4f0696e2a4e070325cc63e9c5cf42f41e2f5ea6e: dependencies: '@babel/runtime': 7.28.6 '@matrix-org/matrix-sdk-crypto-wasm': 17.1.0 From 736d2ab160fc5ab90f92ae46378f361cd56f6f8d Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Wed, 18 Feb 2026 02:13:33 +0530 Subject: [PATCH 2/5] Add method for tracking event --- src/PosthogTrackers.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/PosthogTrackers.ts b/src/PosthogTrackers.ts index 2650403d3b0..dd137650d6f 100644 --- a/src/PosthogTrackers.ts +++ b/src/PosthogTrackers.ts @@ -10,10 +10,12 @@ import { PureComponent, type SyntheticEvent } from "react"; import { type WebScreen as ScreenEvent } from "@matrix-org/analytics-events/types/typescript/WebScreen"; import { type Interaction as InteractionEvent } from "@matrix-org/analytics-events/types/typescript/Interaction"; import { type PinUnpinAction } from "@matrix-org/analytics-events/types/typescript/PinUnpinAction"; +import { type RoomListSortingAlgorithmChanged } from "@matrix-org/analytics-events/types/typescript/RoomListSortingAlgorithmChanged"; import PageType from "./PageTypes"; import Views from "./Views"; import { PosthogAnalytics } from "./PosthogAnalytics"; +import { SortingAlgorithm } from "./stores/room-list-v3/skip-list/sorters"; export type ScreenName = ScreenEvent["$current_url"]; export type InteractionName = InteractionEvent["name"]; @@ -38,6 +40,12 @@ const loggedInPageTypeMap: Record = { [PageType.UserView]: "User", }; +const SortingAlgorithmMap: Record = { + [SortingAlgorithm.Recency]: "Activity", + [SortingAlgorithm.Unread]: "Unread", + [SortingAlgorithm.Alphabetic]: "Alphabetic" +} + export default class PosthogTrackers { private static internalInstance: PosthogTrackers; @@ -112,6 +120,19 @@ export default class PosthogTrackers { from, }); } + + /** + * Track when the user chooses a different sorting algorithm for the room-list. + * @param oldAlgorithm - The old algorithm. + * @param newAlgorithm - The new algorithm. + */ + public static trackRoomListSortingAlgorithmChange(oldAlgorithm: SortingAlgorithm, newAlgorithm: SortingAlgorithm): void { + PosthogAnalytics.instance.trackEvent({ + eventName: "RoomListSortingAlgorithmChanged", + oldAlgorithm: SortingAlgorithmMap[oldAlgorithm], + newAlgorithm: SortingAlgorithmMap[newAlgorithm], + }); + } } export class PosthogScreenTracker extends PureComponent<{ screenName: ScreenName }> { From 4d34299b066ac118b8a6f190e7783b1f296321a1 Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Wed, 18 Feb 2026 02:14:10 +0530 Subject: [PATCH 3/5] Track event on resort --- .../room-list/RoomListHeaderViewModel.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/viewmodels/room-list/RoomListHeaderViewModel.ts b/src/viewmodels/room-list/RoomListHeaderViewModel.ts index e99268190c8..8a5547e6e97 100644 --- a/src/viewmodels/room-list/RoomListHeaderViewModel.ts +++ b/src/viewmodels/room-list/RoomListHeaderViewModel.ts @@ -170,20 +170,26 @@ export class RoomListHeaderViewModel }; public sort = (option: SortOption): void => { - let sortingAlgorithm: SortingAlgorithm; + const oldSortingAlgorithm = RoomListStoreV3.instance.activeSortAlgorithm; + let newSortingAlgorithm: SortingAlgorithm; switch (option) { case "alphabetical": - sortingAlgorithm = SortingAlgorithm.Alphabetic; + newSortingAlgorithm = SortingAlgorithm.Alphabetic; break; case "recent": - sortingAlgorithm = SortingAlgorithm.Recency; + newSortingAlgorithm = SortingAlgorithm.Recency; break; case "unread-first": - sortingAlgorithm = SortingAlgorithm.Unread; + newSortingAlgorithm = SortingAlgorithm.Unread; break; } - RoomListStoreV3.instance.resort(sortingAlgorithm); + RoomListStoreV3.instance.resort(newSortingAlgorithm); this.snapshot.merge({ activeSortOption: option }); + + // Record analytics for this action + if (oldSortingAlgorithm) { + PosthogTrackers.trackRoomListSortingAlgorithmChange(oldSortingAlgorithm, newSortingAlgorithm); + } }; public toggleMessagePreview = (): void => { From 080b39ecb17af87e6fd70704c4e1d1f65538ad52 Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Wed, 18 Feb 2026 02:14:24 +0530 Subject: [PATCH 4/5] Add test --- .../room-list/RoomListHeaderViewModel-test.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts b/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts index 7025abe7c1a..63890c7417d 100644 --- a/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts +++ b/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts @@ -25,6 +25,7 @@ import { } from "../../../src/utils/space"; import { createTestClient, mkSpace } from "../../test-utils"; import { createRoom, hasCreateRoomRights } from "../../../src/viewmodels/room-list/utils"; +import PosthogTrackers from "../../../src/PosthogTrackers"; jest.mock("../../../src/PosthogTrackers", () => ({ trackInteraction: jest.fn(), @@ -276,10 +277,20 @@ describe("RoomListHeaderViewModel", () => { const resortSpy = jest.spyOn(RoomListStoreV3.instance, "resort").mockImplementation(jest.fn()); vm = new RoomListHeaderViewModel({ matrixClient, spaceStore: SpaceStore.instance }); vm.sort(option); - expect(resortSpy).toHaveBeenCalledWith(expectedAlgorithm); }); + it("should track analytics on resort", () => { + jest.spyOn(RoomListStoreV3.instance, "activeSortAlgorithm", "get").mockReturnValue(SortingAlgorithm.Alphabetic); + PosthogTrackers.trackRoomListSortingAlgorithmChange = jest.fn(); + + vm = new RoomListHeaderViewModel({ matrixClient, spaceStore: SpaceStore.instance }); + jest.spyOn(RoomListStoreV3.instance, "resort").mockImplementation(jest.fn()); + vm.sort("unread-first"); + + expect(PosthogTrackers.trackRoomListSortingAlgorithmChange).toHaveBeenCalledWith(SortingAlgorithm.Alphabetic, SortingAlgorithm.Unread); + }) + it("should toggle message preview from enabled to disabled", () => { jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => { if (settingName === "RoomList.showMessagePreview") return true; From c59b0085ecf5e75a9ed0e389fbcf41ba2d609bfa Mon Sep 17 00:00:00 2001 From: R Midhun Suresh Date: Wed, 18 Feb 2026 14:34:32 +0530 Subject: [PATCH 5/5] Fix lint --- src/PosthogTrackers.ts | 9 ++++++--- .../room-list/RoomListHeaderViewModel-test.ts | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/PosthogTrackers.ts b/src/PosthogTrackers.ts index dd137650d6f..a3f00e1117e 100644 --- a/src/PosthogTrackers.ts +++ b/src/PosthogTrackers.ts @@ -43,8 +43,8 @@ const loggedInPageTypeMap: Record = { const SortingAlgorithmMap: Record = { [SortingAlgorithm.Recency]: "Activity", [SortingAlgorithm.Unread]: "Unread", - [SortingAlgorithm.Alphabetic]: "Alphabetic" -} + [SortingAlgorithm.Alphabetic]: "Alphabetic", +}; export default class PosthogTrackers { private static internalInstance: PosthogTrackers; @@ -126,7 +126,10 @@ export default class PosthogTrackers { * @param oldAlgorithm - The old algorithm. * @param newAlgorithm - The new algorithm. */ - public static trackRoomListSortingAlgorithmChange(oldAlgorithm: SortingAlgorithm, newAlgorithm: SortingAlgorithm): void { + public static trackRoomListSortingAlgorithmChange( + oldAlgorithm: SortingAlgorithm, + newAlgorithm: SortingAlgorithm, + ): void { PosthogAnalytics.instance.trackEvent({ eventName: "RoomListSortingAlgorithmChanged", oldAlgorithm: SortingAlgorithmMap[oldAlgorithm], diff --git a/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts b/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts index 63890c7417d..936389603db 100644 --- a/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts +++ b/test/viewmodels/room-list/RoomListHeaderViewModel-test.ts @@ -281,15 +281,20 @@ describe("RoomListHeaderViewModel", () => { }); it("should track analytics on resort", () => { - jest.spyOn(RoomListStoreV3.instance, "activeSortAlgorithm", "get").mockReturnValue(SortingAlgorithm.Alphabetic); + jest.spyOn(RoomListStoreV3.instance, "activeSortAlgorithm", "get").mockReturnValue( + SortingAlgorithm.Alphabetic, + ); PosthogTrackers.trackRoomListSortingAlgorithmChange = jest.fn(); vm = new RoomListHeaderViewModel({ matrixClient, spaceStore: SpaceStore.instance }); jest.spyOn(RoomListStoreV3.instance, "resort").mockImplementation(jest.fn()); vm.sort("unread-first"); - expect(PosthogTrackers.trackRoomListSortingAlgorithmChange).toHaveBeenCalledWith(SortingAlgorithm.Alphabetic, SortingAlgorithm.Unread); - }) + expect(PosthogTrackers.trackRoomListSortingAlgorithmChange).toHaveBeenCalledWith( + SortingAlgorithm.Alphabetic, + SortingAlgorithm.Unread, + ); + }); it("should toggle message preview from enabled to disabled", () => { jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => {