Only send callEndedEvent if the user has joined the call.
This commit is contained in:
@@ -27,8 +27,8 @@ interface CallEnded extends IPosthogEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CallEndedTracker {
|
export class CallEndedTracker {
|
||||||
private cache: { startTime: Date; maxParticipantsCount: number } = {
|
private cache: { startTime?: Date; maxParticipantsCount: number } = {
|
||||||
startTime: new Date(0),
|
startTime: undefined,
|
||||||
maxParticipantsCount: 0,
|
maxParticipantsCount: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,26 +49,32 @@ export class CallEndedTracker {
|
|||||||
sendInstantly: boolean,
|
sendInstantly: boolean,
|
||||||
rtcSession: MatrixRTCSession,
|
rtcSession: MatrixRTCSession,
|
||||||
): void {
|
): void {
|
||||||
PosthogAnalytics.instance.trackEvent<CallEnded>(
|
if (this.cache.startTime) {
|
||||||
{
|
PosthogAnalytics.instance.trackEvent<CallEnded>(
|
||||||
eventName: "CallEnded",
|
{
|
||||||
callId: callId,
|
eventName: "CallEnded",
|
||||||
callParticipantsMax: this.cache.maxParticipantsCount,
|
callId: callId,
|
||||||
callParticipantsOnLeave: callParticipantsNow,
|
callParticipantsMax: this.cache.maxParticipantsCount,
|
||||||
callDuration: (Date.now() - this.cache.startTime.getTime()) / 1000,
|
callParticipantsOnLeave: callParticipantsNow,
|
||||||
roomEventEncryptionKeysSent:
|
callDuration: (Date.now() - this.cache.startTime.getTime()) / 1000,
|
||||||
rtcSession.statistics.counters.roomEventEncryptionKeysSent,
|
roomEventEncryptionKeysSent:
|
||||||
roomEventEncryptionKeysReceived:
|
rtcSession.statistics.counters.roomEventEncryptionKeysSent,
|
||||||
rtcSession.statistics.counters.roomEventEncryptionKeysReceived,
|
roomEventEncryptionKeysReceived:
|
||||||
roomEventEncryptionKeysReceivedAverageAge:
|
rtcSession.statistics.counters.roomEventEncryptionKeysReceived,
|
||||||
rtcSession.statistics.counters.roomEventEncryptionKeysReceived > 0
|
roomEventEncryptionKeysReceivedAverageAge:
|
||||||
? rtcSession.statistics.totals
|
rtcSession.statistics.counters.roomEventEncryptionKeysReceived > 0
|
||||||
.roomEventEncryptionKeysReceivedTotalAge /
|
? rtcSession.statistics.totals
|
||||||
rtcSession.statistics.counters.roomEventEncryptionKeysReceived
|
.roomEventEncryptionKeysReceivedTotalAge /
|
||||||
: 0,
|
rtcSession.statistics.counters.roomEventEncryptionKeysReceived
|
||||||
},
|
: 0,
|
||||||
{ send_instantly: sendInstantly },
|
},
|
||||||
);
|
{ send_instantly: sendInstantly },
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
logger.warn(
|
||||||
|
"[PosthogEvents] Failed to send posthog callEnded event due to missing startTime",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user