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

**URL:** https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137
**Category:** How do I?
**Tags:** xano, weweb
**Created:** [February 20, 2024, 4:46pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137 "2024-02-20T16:46:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![GAlp](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@GAlp](https://community.weweb.io/u/GAlp)
#### Post date: [February 20, 2024, 4:46pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137/1 "2024-02-20T16:46:19Z")

</div>

Hi,

I need to track spent timed on every page on my webapp. In Weweb we use [TimeJs](https://github.com/jasonzissman/TimeMe.js/) 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 ☹  
I saw the eventListener `onbeforeunload` but don’t know how to add this eventListener on weweb.

Thanks you for your help

---

<div class="post-metadata">

### Author: ![AgentD](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/agentd/32/6331_2.png) [@AgentD](https://community.weweb.io/u/AgentD)
#### Post date: [February 20, 2024, 8:53pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137/2 "2024-02-20T20:53:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![GAlp](https://avatars.discourse-cdn.com/v4/letter/g/71e660/32.png) [@GAlp](https://community.weweb.io/u/GAlp)
#### Post date: [March 5, 2024, 1:22pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137/3 "2024-03-05T13:22:21Z")

</div>

Thanks for the answer

---

<div class="post-metadata">

### Author: ![kyanaloe](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/kyanaloe/32/1076_2.png) [@kyanaloe](https://community.weweb.io/u/kyanaloe)
#### Post date: [July 3, 2024, 2:54pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137/4 "2024-07-03T14:54:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![AgentD](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/agentd/32/6331_2.png) [@AgentD](https://community.weweb.io/u/AgentD)
#### Post date: [July 3, 2024, 8:24pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137/5 "2024-07-03T20:24:02Z")

</div>

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 👇🏾 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

> **[Window: pagehide event - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event)**
>
> The pagehide event is sent to a Window when the browser hides the current page in the process of presenting a different page from the session's history.

---

<div class="post-metadata">

### Author: ![ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@ryan](https://community.weweb.io/u/ryan)
#### Post date: [September 16, 2024, 5:25pm UTC](https://community.weweb.io/t/tracking-spent-time-on-page-and-then-send-it-to-my-xano-backend-before-page-is-closed/7137/6 "2024-09-16T17:25:01Z")

</div>

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