send posthog callEnded events instantly in embedded mode (prohibit missing events) (#816)

Signed-off-by: Timo K <timok@element.io>
Co-authored-by: Timo K <timok@element.io>
This commit is contained in:
Timo 2023-01-03 17:09:21 +01:00 committed by GitHub
commit 05be247946
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 15 deletions

View file

@ -176,7 +176,7 @@ export function GroupCallView({
const [left, setLeft] = useState(false);
const history = useHistory();
const onLeave = useCallback(() => {
const onLeave = useCallback(async () => {
setLeft(true);
let participantCount = 0;
@ -184,13 +184,20 @@ export function GroupCallView({
participantCount += deviceMap.size;
}
// In embedded/widget mode the iFrame will be killed right after the call ended prohibiting the posthog event from getting sent,
// therefore we want the event to be sent instantly without getting queued/batched.
const sendInstantly = !!widget;
PosthogAnalytics.instance.eventCallEnded.track(
groupCall.groupCallId,
participantCount
participantCount,
sendInstantly
);
leave();
if (widget) {
// we need to wait until the callEnded event is tracked. Otherwise the iFrame gets killed before tracking the event.
await new Promise((resolve) => window.setTimeout(resolve, 500)); // 500ms
PosthogAnalytics.instance.logout();
widget.api.transport.send(ElementWidgetActions.HangupCall, {});
widget.api.setAlwaysOnScreen(false);
}