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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 0 deletions

View File

@ -64,6 +64,7 @@ interface PlatformProperties {
appVersion: string;
matrixBackend: "embedded" | "jssdk";
callBackend: "livekit" | "full-mesh";
cryptoVersion?: string;
}
interface PosthogSettings {
@ -184,6 +185,9 @@ export class PosthogAnalytics {
appVersion,
matrixBackend: widget ? "embedded" : "jssdk",
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 { logger } from "matrix-js-sdk/src/logger";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
import {
IPosthogEvent,
@ -20,6 +21,9 @@ interface CallEnded extends IPosthogEvent {
callParticipantsOnLeave: number;
callParticipantsMax: number;
callDuration: number;
roomEventEncryptionKeysSent: number;
roomEventEncryptionKeysReceived: number;
roomEventEncryptionKeysReceivedAverageAge: number;
}
export class CallEndedTracker {
@ -43,6 +47,7 @@ export class CallEndedTracker {
callId: string,
callParticipantsNow: number,
sendInstantly: boolean,
rtcSession: MatrixRTCSession,
): void {
PosthogAnalytics.instance.trackEvent<CallEnded>(
{
@ -51,6 +56,16 @@ export class CallEndedTracker {
callParticipantsMax: this.cache.maxParticipantsCount,
callParticipantsOnLeave: callParticipantsNow,
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 },
);

View File

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