Tracking spent time on page and then send it to my Xano Backend before page is closed

Hi,

I need to track spent timed on every page on my webapp. In Weweb we use TimeJs to calculate the correct time excluding idle. This work like a charm.

Next, i need to update a row in a xano table when user is leaving. My problem is we can make a workflow on page unload, but the api call is not processing when the user close the tab. I can only update time spent when user change tabs for now, which is a problem for me.

Is there a way to achieve it ?

I saw TimeMe can use websocket, but xano don’t for now :frowning:
I saw the eventListener onbeforeunload but don’t know how to add this eventListener on weweb.

Thanks you for your help

Easiest way for you to do this is use the Weweb Before Unmount event in the page workflows

If you cannot use that, then you can just add a before unmount listener using custom JS

Thanks for the answer

Can you explain a bit more about the before unmount event in page workflows? I don’t see that as an option for trigger?

There are many browser events that can be used to trigger final actions before a user goes away. Before Unmount is one native in Weweb. If you check the list of triggers, scroll down :point_down:t5: you should see before Unmount.

If you don’t find that, cos I’ve not seen the editor since the summer update. You can use pagehide

Pagehide is probably the best for the use case the OP posted about, where the user is closing the tab. But it’s not natively supported by Weweb. But you can still use it with custom JS (if you want). You can read it below

Where is the best place to implement this in weweb. App Custome Code Section between script tags ?