From ad054037f5dbf6e198d32dcbf5be374102db87aa Mon Sep 17 00:00:00 2001 From: mcalinghee Date: Thu, 8 Aug 2024 18:38:37 +0200 Subject: [PATCH 1/2] add metrics on call event --- .../src/LegacyCallHandler.tsx | 43 ++++++++++++++++++- .../metrics-call/matrix-js-sdk+33.1.0.patch | 17 ++++++++ patches/patches.json | 6 +++ patches/subtree-modifications.json | 7 +++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 patches/metrics-call/matrix-js-sdk+33.1.0.patch diff --git a/linked-dependencies/matrix-react-sdk/src/LegacyCallHandler.tsx b/linked-dependencies/matrix-react-sdk/src/LegacyCallHandler.tsx index 7abdb236a..ef89cda16 100644 --- a/linked-dependencies/matrix-react-sdk/src/LegacyCallHandler.tsx +++ b/linked-dependencies/matrix-react-sdk/src/LegacyCallHandler.tsx @@ -20,6 +20,7 @@ limitations under the License. import React from "react"; import { MatrixError, RuleId, TweakName, SyncState } from "matrix-js-sdk/src/matrix"; import { + CallDirection, CallError, CallErrorCode, CallEvent, @@ -29,6 +30,8 @@ import { FALLBACK_ICE_SERVER, MatrixCall, } from "matrix-js-sdk/src/webrtc/call"; +import { CallEnded as CallEndedEvent } from "@matrix-org/analytics-events/types/typescript/CallEnded"; +import { CallStarted as CallStartEvent } from "@matrix-org/analytics-events/types/typescript/CallStarted"; import { logger } from "matrix-js-sdk/src/logger"; import EventEmitter from "events"; import { PushProcessor } from "matrix-js-sdk/src/pushprocessor"; @@ -66,6 +69,7 @@ import { localNotificationsAreSilenced } from "./utils/notifications"; import { SdkContextClass } from "./contexts/SDKContext"; import { showCantStartACallDialog } from "./voice-broadcast/utils/showCantStartACallDialog"; import { isNotNull } from "./Typeguards"; +import { PosthogAnalytics } from "./PosthogAnalytics"; export const PROTOCOL_PSTN = "m.protocol.pstn"; export const PROTOCOL_PSTN_PREFIXED = "im.vector.protocol.pstn"; @@ -695,9 +699,13 @@ export default class LegacyCallHandler extends EventEmitter { this.removeCallForRoom(mappedRoomId); } + /** :TCHAP: metrics-call **/ + this.trackCallEnded(call); + /** end :TCHAP: **/ + if (oldState === CallState.InviteSent && call.hangupParty === CallParty.Remote) { this.play(AudioID.Busy); - + // Don't show a modal when we got rejected/the call was hung up if (!hangupReason || [CallErrorCode.UserHangup, "user hangup"].includes(hangupReason)) break; @@ -734,6 +742,30 @@ export default class LegacyCallHandler extends EventEmitter { } }; + /** :TCHAP: metrics-call **/ + private async trackCallStart(call: MatrixCall): Promise { + PosthogAnalytics.instance.trackEvent({ + eventName: "CallStarted", + placed: true, + isVideo: call.type == CallType.Video, + numParticipants: 2, + }); + } + + private async trackCallEnded(call: MatrixCall): Promise { + let durationMs: number = call.getCallStartTime() == undefined ? + 0 + : Math.round((Date.now() - call.getCallStartTime()!)); + PosthogAnalytics.instance.trackEvent({ + eventName: "CallEnded", + placed: call.direction! == CallDirection.Outbound, + isVideo: call.type == CallType.Video, + durationMs: durationMs, + numParticipants: 2, + }); + } + /** end :TCHAP: **/ + private async logCallStats(call: MatrixCall, mappedRoomId: string): Promise { const stats = await call.getCurrentCallStats(); logger.debug( @@ -921,8 +953,14 @@ export default class LegacyCallHandler extends EventEmitter { if (type === CallType.Voice) { call.placeVoiceCall(); + /** :TCHAP: metrics-call **/ + this.trackCallStart(call) + /** end :TCHAP: **/ } else if (type === "video") { call.placeVideoCall(); + /** :TCHAP: metrics-call **/ + this.trackCallStart(call) + /** end :TCHAP: **/ } else { logger.error("Unknown conf call type: " + type); } @@ -1036,6 +1074,9 @@ export default class LegacyCallHandler extends EventEmitter { call.answer(); this.setActiveCallRoomId(roomId); + /** :TCHAP: metrics-call **/ + this.trackCallStart(call) + /** end :TCHAP: **/ dis.dispatch({ action: Action.ViewRoom, room_id: roomId, diff --git a/patches/metrics-call/matrix-js-sdk+33.1.0.patch b/patches/metrics-call/matrix-js-sdk+33.1.0.patch new file mode 100644 index 000000000..e1b0bc63d --- /dev/null +++ b/patches/metrics-call/matrix-js-sdk+33.1.0.patch @@ -0,0 +1,17 @@ +diff --git a/node_modules/matrix-js-sdk/src/webrtc/call.ts b/node_modules/matrix-js-sdk/src/webrtc/call.ts +index 3f5c61a..a223f4a 100644 +--- a/node_modules/matrix-js-sdk/src/webrtc/call.ts ++++ b/node_modules/matrix-js-sdk/src/webrtc/call.ts +@@ -1572,6 +1572,12 @@ export class MatrixCall extends TypedEventEmitter Date: Mon, 12 Aug 2024 17:24:12 +0200 Subject: [PATCH 2/2] add posthog project api key --- config.dev.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config.dev.json b/config.dev.json index 143d3ad68..34e9fae13 100644 --- a/config.dev.json +++ b/config.dev.json @@ -107,6 +107,11 @@ "text": "Read the Privacy Policy" } ], + "posthog": { + "project_api_key": "phc_eQOeaQiaIxdX9kaQmqYTD7RJLyFubYmGYKUI9czqqQD", + "api_host": "https://us.i.posthog.com" + }, + "privacy_policy_url": "https://tchap.beta.gouv.fr/politique-de-confidentialite", "tchap_features": { "feature_email_notification": ["*"], "feature_space": ["*"],