Posthog improvements (#2630)

This commit is contained in:
Hugh Nimmo-Smith
2024-09-23 14:35:41 +01:00
committed by GitHub
parent d14b43487a
commit ed35d6b377
3 changed files with 20 additions and 0 deletions

View File

@@ -64,6 +64,7 @@ interface PlatformProperties {
appVersion: string; appVersion: string;
matrixBackend: "embedded" | "jssdk"; matrixBackend: "embedded" | "jssdk";
callBackend: "livekit" | "full-mesh"; callBackend: "livekit" | "full-mesh";
cryptoVersion?: string;
} }
interface PosthogSettings { interface PosthogSettings {
@@ -184,6 +185,9 @@ export class PosthogAnalytics {
appVersion, appVersion,
matrixBackend: widget ? "embedded" : "jssdk", matrixBackend: widget ? "embedded" : "jssdk",
callBackend: "livekit", callBackend: "livekit",
cryptoVersion: widget
? undefined
: window.matrixclient?.getCrypto()?.getVersion(),
}; };
} }

View File

@@ -7,6 +7,7 @@ Please see LICENSE in the repository root for full details.
import { DisconnectReason } from "livekit-client"; import { DisconnectReason } from "livekit-client";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
import { import {
IPosthogEvent, IPosthogEvent,
@@ -20,6 +21,9 @@ interface CallEnded extends IPosthogEvent {
callParticipantsOnLeave: number; callParticipantsOnLeave: number;
callParticipantsMax: number; callParticipantsMax: number;
callDuration: number; callDuration: number;
roomEventEncryptionKeysSent: number;
roomEventEncryptionKeysReceived: number;
roomEventEncryptionKeysReceivedAverageAge: number;
} }
export class CallEndedTracker { export class CallEndedTracker {
@@ -43,6 +47,7 @@ export class CallEndedTracker {
callId: string, callId: string,
callParticipantsNow: number, callParticipantsNow: number,
sendInstantly: boolean, sendInstantly: boolean,
rtcSession: MatrixRTCSession,
): void { ): void {
PosthogAnalytics.instance.trackEvent<CallEnded>( PosthogAnalytics.instance.trackEvent<CallEnded>(
{ {
@@ -51,6 +56,16 @@ export class CallEndedTracker {
callParticipantsMax: this.cache.maxParticipantsCount, callParticipantsMax: this.cache.maxParticipantsCount,
callParticipantsOnLeave: callParticipantsNow, callParticipantsOnLeave: callParticipantsNow,
callDuration: (Date.now() - this.cache.startTime.getTime()) / 1000, callDuration: (Date.now() - this.cache.startTime.getTime()) / 1000,
roomEventEncryptionKeysSent:
rtcSession.statistics.counters.roomEventEncryptionKeysSent,
roomEventEncryptionKeysReceived:
rtcSession.statistics.counters.roomEventEncryptionKeysReceived,
roomEventEncryptionKeysReceivedAverageAge:
rtcSession.statistics.counters.roomEventEncryptionKeysReceived > 0
? rtcSession.statistics.totals
.roomEventEncryptionKeysReceivedTotalAge /
rtcSession.statistics.counters.roomEventEncryptionKeysReceived
: 0,
}, },
{ send_instantly: sendInstantly }, { send_instantly: sendInstantly },
); );

View File

@@ -219,6 +219,7 @@ export const GroupCallView: FC<Props> = ({
rtcSession.room.roomId, rtcSession.room.roomId,
rtcSession.memberships.length, rtcSession.memberships.length,
sendInstantly, sendInstantly,
rtcSession,
); );
// Only sends matrix leave event. The Livekit session will disconnect once the ActiveCall-view unmounts. // Only sends matrix leave event. The Livekit session will disconnect once the ActiveCall-view unmounts.