diff --git a/package.json b/package.json index 9d65d0ae55..326567f044 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "linkifyjs": "^4.0.0-beta.4", "lodash": "^4.17.20", "maplibre-gl": "^1.15.2", - "matrix-analytics-events": "github:matrix-org/matrix-analytics-events.git#bdabdd63280f052cedeeb0c25443f3d55f7c7108", + "matrix-analytics-events": "github:matrix-org/matrix-analytics-events.git#df9c0312f51911a7364810466d041f2b79e7e080", "matrix-events-sdk": "^0.0.1-beta.6", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", "matrix-widget-api": "^0.1.0-beta.18", diff --git a/src/components/views/context_menus/SpaceContextMenu.tsx b/src/components/views/context_menus/SpaceContextMenu.tsx index f5fb09ad25..3d16884302 100644 --- a/src/components/views/context_menus/SpaceContextMenu.tsx +++ b/src/components/views/context_menus/SpaceContextMenu.tsx @@ -190,7 +190,7 @@ const SpaceContextMenu = ({ space, hideHeader, onFinished, ...props }: IProps) = onFinished(); }; - const onExploreRoomsClick = (ev: ButtonEvent) => { + const openSpace = (ev: ButtonEvent) => { ev.preventDefault(); ev.stopPropagation(); @@ -202,6 +202,16 @@ const SpaceContextMenu = ({ space, hideHeader, onFinished, ...props }: IProps) = onFinished(); }; + const onExploreRoomsClick = (ev: ButtonEvent) => { + PosthogTrackers.trackInteraction("WebSpaceContextMenuExploreRoomsItem", ev); + openSpace(ev); + }; + + const onHomeClick = (ev: ButtonEvent) => { + PosthogTrackers.trackInteraction("WebSpaceContextMenuHomeItem", ev); + openSpace(ev); + }; + return { inviteOption } { room_id: activeSpace.roomId, _trigger: undefined, // other }); + PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuExploreRoomsItem", e); }} /> { @@ -503,13 +504,14 @@ export default class RoomList extends React.PureComponent { defaultDispatcher.dispatch({ action: "view_create_chat", initialText }); }; - private onExplore = () => { + private onExplore = (ev: ButtonEvent) => { if (!isMetaSpace(this.props.activeSpace)) { defaultDispatcher.dispatch({ action: Action.ViewRoom, room_id: this.props.activeSpace, _trigger: undefined, // other }); + PosthogTrackers.trackInteraction("WebRoomListRoomsSublistPlusMenuExploreRoomsItem", ev); } else { const initialText = RoomListStore.instance.getFirstNameFilterCondition()?.search; defaultDispatcher.dispatch({ action: Action.ViewRoomDirectory, initialText }); diff --git a/src/components/views/rooms/RoomListHeader.tsx b/src/components/views/rooms/RoomListHeader.tsx index 2c42ea2cb5..a91cba17e5 100644 --- a/src/components/views/rooms/RoomListHeader.tsx +++ b/src/components/views/rooms/RoomListHeader.tsx @@ -282,6 +282,7 @@ const RoomListHeader = ({ spacePanelDisabled, onVisibilityChange }: IProps) => { _trigger: undefined, // other }); closePlusMenu(); + PosthogTrackers.trackInteraction("WebRoomListHeaderPlusMenuExploreRoomsItem", e); }} /> { private async viewRoom(payload: ViewRoomPayload): Promise { if (payload.room_id) { if (payload._trigger !== null && payload.room_id !== this.state.roomId) { + let activeSpace: ViewRoomEvent["activeSpace"]; + if (SpaceStore.instance.activeSpace === MetaSpace.Home) { + activeSpace = "Home"; + } else if (isMetaSpace(SpaceStore.instance.activeSpace)) { + activeSpace = "Meta"; + } else { + activeSpace = SpaceStore.instance.activeSpaceRoom.getJoinRule() === JoinRule.Public + ? "Public" + : "Private"; + } + PosthogAnalytics.instance.trackEvent({ eventName: "ViewRoom", trigger: payload._trigger, viaKeyboard: payload._viaKeyboard, + isDM: !!DMRoomMap.shared().getUserIdForRoomId(payload.room_id), + isSpace: MatrixClientPeg.get().getRoom(payload.room_id)?.isSpaceRoom(), + activeSpace, }); } diff --git a/test/DecryptionFailureTracker-test.js b/test/DecryptionFailureTracker-test.js index f4f42d14d7..4eedf60a0d 100644 --- a/test/DecryptionFailureTracker-test.js +++ b/test/DecryptionFailureTracker-test.js @@ -16,6 +16,7 @@ limitations under the License. import { MatrixEvent } from 'matrix-js-sdk'; +import './skinned-sdk'; // Must be first for skinning to work import { DecryptionFailureTracker } from '../src/DecryptionFailureTracker'; class MockDecryptionError extends Error { diff --git a/test/components/views/dialogs/ExportDialog-test.tsx b/test/components/views/dialogs/ExportDialog-test.tsx index c27c5e0ad4..9a41502578 100644 --- a/test/components/views/dialogs/ExportDialog-test.tsx +++ b/test/components/views/dialogs/ExportDialog-test.tsx @@ -17,10 +17,10 @@ limitations under the License. import React from 'react'; import { mount } from 'enzyme'; import { mocked } from 'jest-mock'; -import '../../../skinned-sdk'; import { act } from "react-dom/test-utils"; import { Room } from 'matrix-js-sdk'; +import '../../../skinned-sdk'; import ExportDialog from '../../../../src/components/views/dialogs/ExportDialog'; import { ExportType, ExportFormat } from '../../../../src/utils/exportUtils/exportUtils'; import { createTestClient, mkStubRoom } from '../../../test-utils'; diff --git a/test/components/views/rooms/SendMessageComposer-test.tsx b/test/components/views/rooms/SendMessageComposer-test.tsx index 5875666bf0..6b87c14f5c 100644 --- a/test/components/views/rooms/SendMessageComposer-test.tsx +++ b/test/components/views/rooms/SendMessageComposer-test.tsx @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -import '../../../skinned-sdk'; // Must be first for skinning to work import React from "react"; import { act } from "react-dom/test-utils"; import { sleep } from "matrix-js-sdk/src/utils"; import { mount } from 'enzyme'; import { RelationType } from 'matrix-js-sdk/src/@types/event'; +import '../../../skinned-sdk'; // Must be first for skinning to work import SendMessageComposer, { createMessageContent, isQuickReaction, @@ -38,8 +38,6 @@ import defaultDispatcher from "../../../../src/dispatcher/dispatcher"; import DocumentOffset from '../../../../src/editor/offset'; import { Layout } from '../../../../src/settings/enums/Layout'; -jest.mock("../../../../src/stores/RoomViewStore"); - describe('', () => { const roomContext = { roomLoading: true, diff --git a/test/stores/RoomViewStore-test.js b/test/stores/RoomViewStore-test.js index 684d757c6d..648a5617e1 100644 --- a/test/stores/RoomViewStore-test.js +++ b/test/stores/RoomViewStore-test.js @@ -1,3 +1,4 @@ +import '../skinned-sdk'; // Must be first for skinning to work import RoomViewStore from '../../src/stores/RoomViewStore'; import { Action } from '../../src/dispatcher/actions'; import { MatrixClientPeg as peg } from '../../src/MatrixClientPeg'; @@ -5,6 +6,18 @@ import * as testUtils from '../test-utils'; const dispatch = testUtils.getDispatchForStore(RoomViewStore); +jest.mock('../../src/utils/DMRoomMap', () => { + const mock = { + getUserIdForRoomId: jest.fn(), + getDMRoomsForUserId: jest.fn(), + }; + + return { + shared: jest.fn().mockReturnValue(mock), + sharedInstance: mock, + }; +}); + describe('RoomViewStore', function() { beforeEach(function() { testUtils.stubClient(); diff --git a/yarn.lock b/yarn.lock index 241cb300bf..ce8543a251 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6249,9 +6249,9 @@ mathml-tag-names@^2.1.3: resolved "https://registry.yarnpkg.com/mathml-tag-names/-/mathml-tag-names-2.1.3.tgz#4ddadd67308e780cf16a47685878ee27b736a0a3" integrity sha512-APMBEanjybaPzUrfqU0IMU5I0AswKMH7k8OTLs0vvV4KZpExkTkY87nR/zpbuTPj+gARop7aGUbl11pnDfW6xg== -"matrix-analytics-events@github:matrix-org/matrix-analytics-events.git#bdabdd63280f052cedeeb0c25443f3d55f7c7108": +"matrix-analytics-events@github:matrix-org/matrix-analytics-events.git#df9c0312f51911a7364810466d041f2b79e7e080": version "0.0.1" - resolved "https://codeload.github.com/matrix-org/matrix-analytics-events/tar.gz/bdabdd63280f052cedeeb0c25443f3d55f7c7108" + resolved "https://codeload.github.com/matrix-org/matrix-analytics-events/tar.gz/df9c0312f51911a7364810466d041f2b79e7e080" matrix-events-sdk@^0.0.1-beta.6: version "0.0.1-beta.6"