Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metrics on call event #1089

Open
wants to merge 2 commits into
base: develop_tchap
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
"text": "Read the Privacy Policy"
}
],
"posthog": {
"project_api_key": "phc_eQOeaQiaIxdX9kaQmqYTD7RJLyFubYmGYKUI9czqqQD",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai mis la cle comme chez element-web ou android en attendant d'avoir une infra de dev

"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": ["*"],
Expand Down
43 changes: 42 additions & 1 deletion linked-dependencies/matrix-react-sdk/src/LegacyCallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -734,6 +742,30 @@ export default class LegacyCallHandler extends EventEmitter {
}
};

/** :TCHAP: metrics-call **/
private async trackCallStart(call: MatrixCall): Promise<void> {
PosthogAnalytics.instance.trackEvent<CallStartEvent>({
eventName: "CallStarted",
placed: true,
isVideo: call.type == CallType.Video,
numParticipants: 2,
});
}

private async trackCallEnded(call: MatrixCall): Promise<void> {
let durationMs: number = call.getCallStartTime() == undefined ?
0
: Math.round((Date.now() - call.getCallStartTime()!));
PosthogAnalytics.instance.trackEvent<CallEndedEvent>({
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<void> {
const stats = await call.getCurrentCallStats();
logger.debug(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<ViewRoomPayload>({
action: Action.ViewRoom,
room_id: roomId,
Expand Down
17 changes: 17 additions & 0 deletions patches/metrics-call/matrix-js-sdk+33.1.0.patch
Original file line number Diff line number Diff line change
@@ -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<CallEvent, CallEventHandlerMap
return callOnHold;
}

+ // :TCHAP: metrics-call-js-sdk
+ public getCallStartTime(): number| undefined {
+ return this.callStartTime!;
+ }
+ // end :TCHAP:
+
/**
* Sends a DTMF digit to the other party
* @param digit - The digit (nb. string - '#' and '*' are dtmf too)
6 changes: 6 additions & 0 deletions patches/patches.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
"src/http-api/fetch.ts",
"src/sync.ts"
]
},
"metrics-call": {
"package": "matrix-js-sdk",
"files": [
"src/webrtc/call.ts"
]
}
}
7 changes: 7 additions & 0 deletions patches/subtree-modifications.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
"src/hooks/useUserOnboardingTasks.ts",
"src/hooks/useUserOnboardingContext.ts"

]
},
"metrics-call": {
"issue": "https://github.com/tchapgouv/tchap-web-v4/issues/1088",
"files": [
"src/LegacyCallHandler.tsx"

]
}
}
Loading