Rene Padillo
Rene Padillo

Reputation: 2358

Session length tracking on PWA

Just wanted to ask if it's possible to track session length on a Progressive Web Application? Any advice or ideas on how I can track the user's session length?

I'm using Mixpanel library for our analytics/statistics.

I can track the session length only if the user clicks on the logout button, however there are cases wherein the user will just close the app/browser directly causing an issue where I cannot determine when did the user ended their app usage, so it's crucial for me to send a track event to the API that the user closed the app/browser.

Is it possible with the current state of progressive web apps to detect if the app or browser was closed? or not?

Upvotes: 1

Views: 829

Answers (1)

Peter Fernandes
Peter Fernandes

Reputation: 316

You can detect if the page is left via the onunload and onbeforeunload events.

Check out the answer here:
Detect browser or tab closing

I would also check out the Beacon API which will let you send any analytics requests that you need when the user leaves the app:
https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API

Upvotes: 2

Related Questions