Skip to content

Commit

Permalink
Send key distribution stats to posthog
Browse files Browse the repository at this point in the history
  • Loading branch information
hughns committed Aug 31, 2024
1 parent d894b74 commit 135e08c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"i18next-http-backend": "^2.0.0",
"livekit-client": "^2.0.2",
"lodash": "^4.17.21",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#50078b1b93b89bb94a631524ef6f673eb244a39a",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#15e49b4575b426359803f4a0cb0d97bd48bc55fc",
"matrix-widget-api": "^1.8.2",
"normalize.css": "^8.0.1",
"observable-hooks": "^4.2.3",
Expand Down
28 changes: 28 additions & 0 deletions src/analytics/PosthogEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

import { DisconnectReason } from "livekit-client";
import { logger } from "matrix-js-sdk/src/logger";
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";

import {
IPosthogEvent,
Expand Down Expand Up @@ -43,6 +44,12 @@ interface CallEnded extends IPosthogEvent {
callParticipantsMax: number;
callDuration: number;
encryption: EncryptionScheme;
toDeviceEncryptionKeysSent: number;
toDeviceEncryptionKeysReceived: number;
toDeviceEncryptionKeysReceivedAverageAge: number;
roomEventEncryptionKeysSent: number;
roomEventEncryptionKeysReceived: number;
roomEventEncryptionKeysReceivedAverageAge: number;
}

export class CallEndedTracker {
Expand All @@ -66,6 +73,7 @@ export class CallEndedTracker {
callId: string,
callParticipantsNow: number,
e2eeType: E2eeType,
rtcSession: MatrixRTCSession,

Check warning on line 76 in src/analytics/PosthogEvents.ts

View check run for this annotation

Codecov / codecov/patch

src/analytics/PosthogEvents.ts#L75-L76

Added lines #L75 - L76 were not covered by tests
sendInstantly: boolean,
): void {
PosthogAnalytics.instance.trackEvent<CallEnded>(
Expand All @@ -76,6 +84,26 @@ export class CallEndedTracker {
callParticipantsOnLeave: callParticipantsNow,
callDuration: (Date.now() - this.cache.startTime.getTime()) / 1000,
encryption: mapE2eeType(e2eeType),
toDeviceEncryptionKeysSent:
rtcSession.statistics.counters.toDeviceEncryptionKeysSent,
toDeviceEncryptionKeysReceived:
rtcSession.statistics.counters.toDeviceEncryptionKeysReceived,
toDeviceEncryptionKeysReceivedAverageAge:
rtcSession.statistics.counters.toDeviceEncryptionKeysReceived > 0
? rtcSession.statistics.totals
.toDeviceEncryptionKeysReceivedTotalAge /
rtcSession.statistics.counters.toDeviceEncryptionKeysReceived
: 0,
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,

Check warning on line 106 in src/analytics/PosthogEvents.ts

View check run for this annotation

Codecov / codecov/patch

src/analytics/PosthogEvents.ts#L86-L106

Added lines #L86 - L106 were not covered by tests
},
{ send_instantly: sendInstantly },
);
Expand Down
1 change: 1 addition & 0 deletions src/room/GroupCallView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export const GroupCallView: FC<Props> = ({
rtcSession.room.roomId,
rtcSession.memberships.length,
matrixInfo.e2eeSystem.kind,
rtcSession,

Check warning on line 227 in src/room/GroupCallView.tsx

View check run for this annotation

Codecov / codecov/patch

src/room/GroupCallView.tsx#L226-L227

Added lines #L226 - L227 were not covered by tests
sendInstantly,
);

Expand Down

0 comments on commit 135e08c

Please sign in to comment.