Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 33791ca

Browse files
authored
Merge pull request #12965 from matrix-org/florianduros/pinned-messages/analytics-event
Add analytics event for pinned messages
2 parents 5bfbca9 + 08d1b6c commit 33791ca

File tree

10 files changed

+53
-13
lines changed

10 files changed

+53
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
},
7373
"dependencies": {
7474
"@babel/runtime": "^7.12.5",
75-
"@matrix-org/analytics-events": "^0.24.0",
75+
"@matrix-org/analytics-events": "^0.25.0",
7676
"@matrix-org/emojibase-bindings": "^1.1.2",
7777
"@matrix-org/matrix-wysiwyg": "2.37.9",
7878
"@matrix-org/react-sdk-module-api": "^2.4.0",

src/PosthogTrackers.ts

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
import { PureComponent, SyntheticEvent } from "react";
1818
import { WebScreen as ScreenEvent } from "@matrix-org/analytics-events/types/typescript/WebScreen";
1919
import { Interaction as InteractionEvent } from "@matrix-org/analytics-events/types/typescript/Interaction";
20+
import { PinUnpinAction } from "@matrix-org/analytics-events/types/typescript/PinUnpinAction";
2021

2122
import PageType from "./PageTypes";
2223
import Views from "./Views";
@@ -106,6 +107,19 @@ export default class PosthogTrackers {
106107
name,
107108
});
108109
}
110+
111+
/**
112+
* Track a pin or unpin action on a message.
113+
* @param kind - Is pin or unpin.
114+
* @param from - From where the action is triggered.
115+
*/
116+
public static trackPinUnpinMessage(kind: PinUnpinAction["kind"], from: PinUnpinAction["from"]): void {
117+
PosthogAnalytics.instance.trackEvent<PinUnpinAction>({
118+
eventName: "PinUnpinAction",
119+
kind,
120+
from,
121+
});
122+
}
109123
}
110124

111125
export class PosthogScreenTracker extends PureComponent<{ screenName: ScreenName }> {

src/TextForEvent.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ import { WIDGET_LAYOUT_EVENT_TYPE } from "./stores/widgets/WidgetLayoutStore";
4040
import { RightPanelPhases } from "./stores/right-panel/RightPanelStorePhases";
4141
import defaultDispatcher from "./dispatcher/dispatcher";
4242
import { RoomSettingsTab } from "./components/views/dialogs/RoomSettingsDialog";
43-
import AccessibleButton, { ButtonEvent } from "./components/views/elements/AccessibleButton";
43+
import AccessibleButton from "./components/views/elements/AccessibleButton";
4444
import RightPanelStore from "./stores/right-panel/RightPanelStore";
4545
import { highlightEvent, isLocationEvent } from "./utils/EventUtils";
4646
import { ElementCall } from "./models/Call";
4747
import { textForVoiceBroadcastStoppedEvent, VoiceBroadcastInfoEventType } from "./voice-broadcast";
4848
import { getSenderName } from "./utils/event/getSenderName";
49+
import PosthogTrackers from "./PosthogTrackers.ts";
4950

5051
function getRoomMemberDisplayname(client: MatrixClient, event: MatrixEvent, userId = event.getSender()): string {
5152
const roomId = event.getRoomId();
@@ -563,6 +564,7 @@ function textForPowerEvent(event: MatrixEvent, client: MatrixClient): (() => str
563564
}
564565

565566
const onPinnedMessagesClick = (): void => {
567+
PosthogTrackers.trackInteraction("PinnedMessageStateEventClick");
566568
RightPanelStore.instance.setCard({ phase: RightPanelPhases.PinnedMessages }, false);
567569
};
568570

@@ -590,7 +592,10 @@ function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX:
590592
a: (sub) => (
591593
<AccessibleButton
592594
kind="link_inline"
593-
onClick={(e: ButtonEvent) => highlightEvent(roomId, messageId)}
595+
onClick={() => {
596+
PosthogTrackers.trackInteraction("PinnedMessageStateEventClick");
597+
highlightEvent(roomId, messageId);
598+
}}
594599
>
595600
{sub}
596601
</AccessibleButton>
@@ -623,7 +628,10 @@ function textForPinnedEvent(event: MatrixEvent, client: MatrixClient, allowJSX:
623628
a: (sub) => (
624629
<AccessibleButton
625630
kind="link_inline"
626-
onClick={(e: ButtonEvent) => highlightEvent(roomId, messageId)}
631+
onClick={() => {
632+
PosthogTrackers.trackInteraction("PinnedMessageStateEventClick");
633+
highlightEvent(roomId, messageId);
634+
}}
627635
>
628636
{sub}
629637
</AccessibleButton>

src/components/views/context_menus/MessageContextMenu.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import { getShareableLocationEvent } from "../../../events/location/getShareable
6060
import { ShowThreadPayload } from "../../../dispatcher/payloads/ShowThreadPayload";
6161
import { CardContext } from "../right_panel/context";
6262
import PinningUtils from "../../../utils/PinningUtils";
63+
import PosthogTrackers from "../../../PosthogTrackers.ts";
6364

6465
interface IReplyInThreadButton {
6566
mxEvent: MatrixEvent;
@@ -243,9 +244,11 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
243244
this.closeMenu();
244245
};
245246

246-
private onPinClick = (): void => {
247+
private onPinClick = (isPinned: boolean): void => {
247248
// Pin or unpin in background
248249
PinningUtils.pinOrUnpinEvent(MatrixClientPeg.safeGet(), this.props.mxEvent);
250+
PosthogTrackers.trackPinUnpinMessage(isPinned ? "Pin" : "Unpin", "Timeline");
251+
249252
this.closeMenu();
250253
};
251254

@@ -618,7 +621,7 @@ export default class MessageContextMenu extends React.Component<IProps, IState>
618621
<IconizedContextMenuOption
619622
iconClassName={isPinned ? "mx_MessageContextMenu_iconUnpin" : "mx_MessageContextMenu_iconPin"}
620623
label={isPinned ? _t("action|unpin") : _t("action|pin")}
621-
onClick={this.onPinClick}
624+
onClick={() => this.onPinClick(isPinned)}
622625
/>
623626
);
624627
}

src/components/views/dialogs/UnpinAllDialog.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { logger } from "matrix-js-sdk/src/logger";
2222
import BaseDialog from "../dialogs/BaseDialog";
2323
import { _t } from "../../../languageHandler";
2424
import PinningUtils from "../../../utils/PinningUtils.ts";
25+
import PosthogTrackers from "../../../PosthogTrackers.ts";
2526

2627
/**
2728
* Properties for {@link UnpinAllDialog}.
@@ -61,6 +62,7 @@ export function UnpinAllDialog({ matrixClient, roomId, onFinished }: UnpinAllDia
6162
onClick={async () => {
6263
try {
6364
await PinningUtils.unpinAllEvents(matrixClient, roomId);
65+
PosthogTrackers.trackPinUnpinMessage("Unpin", "UnpinAll");
6466
} catch (e) {
6567
logger.error("Failed to unpin all events:", e);
6668
}

src/components/views/messages/MessageActionBar.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import { GetRelationsForEvent, IEventTileType } from "../rooms/EventTile";
6767
import { VoiceBroadcastInfoEventType } from "../../../voice-broadcast/types";
6868
import { ButtonEvent } from "../elements/AccessibleButton";
6969
import PinningUtils from "../../../utils/PinningUtils";
70+
import PosthogTrackers from "../../../PosthogTrackers.ts";
7071

7172
interface IOptionsButtonProps {
7273
mxEvent: MatrixEvent;
@@ -407,12 +408,13 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
407408
/**
408409
* Pin or unpin the event.
409410
*/
410-
private onPinClick = async (event: ButtonEvent): Promise<void> => {
411+
private onPinClick = async (event: ButtonEvent, isPinned: boolean): Promise<void> => {
411412
// Don't open the regular browser or our context menu on right-click
412413
event.preventDefault();
413414
event.stopPropagation();
414415

415416
await PinningUtils.pinOrUnpinEvent(MatrixClientPeg.safeGet(), this.props.mxEvent);
417+
PosthogTrackers.trackPinUnpinMessage(isPinned ? "Pin" : "Unpin", "Timeline");
416418
};
417419

418420
public render(): React.ReactNode {
@@ -441,8 +443,8 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
441443
<RovingAccessibleButton
442444
className="mx_MessageActionBar_iconButton"
443445
title={isPinned ? _t("action|unpin") : _t("action|pin")}
444-
onClick={this.onPinClick}
445-
onContextMenu={this.onPinClick}
446+
onClick={(e) => this.onPinClick(e, isPinned)}
447+
onContextMenu={(e: ButtonEvent) => this.onPinClick(e, isPinned)}
446448
key="pin"
447449
placement="left"
448450
>

src/components/views/right_panel/RoomSummaryCard.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const onRoomFilesClick = (): void => {
9595
};
9696

9797
const onRoomPinsClick = (): void => {
98+
PosthogTrackers.trackInteraction("PinnedMessageRoomInfoButton");
9899
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.PinnedMessages }, true);
99100
};
100101

src/components/views/rooms/PinnedEventTile.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { OpenForwardDialogPayload } from "../../../dispatcher/payloads/OpenForwa
4242
import { createRedactEventDialog } from "../dialogs/ConfirmRedactDialog";
4343
import { ShowThreadPayload } from "../../../dispatcher/payloads/ShowThreadPayload";
4444
import PinningUtils from "../../../utils/PinningUtils.ts";
45+
import PosthogTrackers from "../../../PosthogTrackers.ts";
4546

4647
const AVATAR_SIZE = "32px";
4748

@@ -152,6 +153,8 @@ function PinMenu({ event, room, permalinkCreator }: PinMenuProps): JSX.Element {
152153
* View the event in the timeline.
153154
*/
154155
const onViewInTimeline = useCallback(() => {
156+
PosthogTrackers.trackInteraction("PinnedMessageListViewTimeline");
157+
155158
dis.dispatch<ViewRoomPayload>({
156159
action: Action.ViewRoom,
157160
event_id: event.getId(),
@@ -173,6 +176,7 @@ function PinMenu({ event, room, permalinkCreator }: PinMenuProps): JSX.Element {
173176
*/
174177
const onUnpin = useCallback(async (): Promise<void> => {
175178
await PinningUtils.pinOrUnpinEvent(matrixClient, event);
179+
PosthogTrackers.trackPinUnpinMessage("Unpin", "MessagePinningList");
176180
}, [event, matrixClient]);
177181

178182
const contentActionable = isContentActionable(event);

src/components/views/rooms/PinnedMessageBanner.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import dis from "../../../dispatcher/dispatcher";
3232
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
3333
import { Action } from "../../../dispatcher/actions";
3434
import MessageEvent from "../messages/MessageEvent";
35+
import PosthogTrackers from "../../../PosthogTrackers.ts";
3536

3637
/**
3738
* The props for the {@link PinnedMessageBanner} component.
@@ -68,6 +69,8 @@ export function PinnedMessageBanner({ room, permalinkCreator }: PinnedMessageBan
6869
const shouldUseMessageEvent = pinnedEvent.isRedacted() || pinnedEvent.isDecryptionFailure();
6970

7071
const onBannerClick = (): void => {
72+
PosthogTrackers.trackInteraction("PinnedMessageBannerClick");
73+
7174
// Scroll to the pinned message
7275
dis.dispatch<ViewRoomPayload>({
7376
action: Action.ViewRoom,
@@ -309,6 +312,9 @@ function BannerButton({ room }: BannerButtonProps): JSX.Element {
309312
className="mx_PinnedMessageBanner_actions"
310313
kind="tertiary"
311314
onClick={() => {
315+
if (isPinnedMessagesPhase) PosthogTrackers.trackInteraction("PinnedMessageBannerCloseListButton");
316+
else PosthogTrackers.trackInteraction("PinnedMessageBannerViewAllButton");
317+
312318
RightPanelStore.instance.showOrHidePhase(RightPanelPhases.PinnedMessages);
313319
}}
314320
>

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1893,10 +1893,10 @@
18931893
resolved "https://registry.yarnpkg.com/@mapbox/whoots-js/-/whoots-js-3.1.0.tgz#497c67a1cef50d1a2459ba60f315e448d2ad87fe"
18941894
integrity sha512-Es6WcD0nO5l+2BOQS4uLfNPYQaNDfbot3X1XUoloz+x0mPDS3eeORZJl06HXjwBG1fOGwCRnzK88LMdxKRrd6Q==
18951895

1896-
"@matrix-org/analytics-events@^0.24.0":
1897-
version "0.24.0"
1898-
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.24.0.tgz#21a64537ac975b18e1eb13d9fd0bdc7d448a6039"
1899-
integrity sha512-3FDdtqZ+5cMqVffWjFNOIQ7RDFN6XS11kqdtN2ps8uvq5ce8gT0yXQvK37WeKWKZZ5QAKeoMzGhud+lsVcb1xg==
1896+
"@matrix-org/analytics-events@^0.25.0":
1897+
version "0.25.0"
1898+
resolved "https://registry.yarnpkg.com/@matrix-org/analytics-events/-/analytics-events-0.25.0.tgz#b0b85297dc05a67feaf89cc5d70b80283c988141"
1899+
integrity sha512-UCTuMjlJGArMqG9qXGfeNz/XtZDFldwuO+dkqP6Wo1nVdWasoWAOlcimDWQ2JnNFCg+UDZU+HLBdS5juTd6xTg==
19001900

19011901
"@matrix-org/emojibase-bindings@^1.1.2":
19021902
version "1.1.3"

0 commit comments

Comments
 (0)