How to measure user activity

Say a user logs in and after 4 hours he logs out. I want to store the timming of 4hrs, what’s the most efficient way to do it ?

There are a few ways to do this, there are also some external tools/services that can help you achieve this.

If you want to keep it in-house, you could use the following basic implementation.

Create a new dataType called ‘userSession’
Add a number field called ‘duration’

On user login, Create a new userSession (after login step)
On user logout, update userSession’s duration to currentdatetime-userSession's created date (before logout step)

I would put both these actions into backend API workflows which you call from all over your app. It centralises the action into one place, so if you want to improve/change the function, you only have to do so in the API workflow, it also avoids the user from experiencing delays as the userSession is being fetched+updated.
You could save the current userSession on the User dataType so that you dont need to do a search for it.

Do you only want to measure the time between logouts? What if the user closes the tab without logging out?

Good Question, if the user just close the tab without login out, how to track this kind of behaviour ?

Cant really do this properly on vanilla bubble.
There is one way, but use it with extreme care, and I would generally advise against using it, unless in very specific conditions. You could achieve it by running a workflow using a custom workflow that reschedules itself in the future, and then update a value for activity to currentdate time. This does work, however it costs A LOT of WU, its expensive and its not scalable.
That being said, IF tracking user activity is an extremely important feature for you app, you could set this workflow up, but keep the following considerations in mind.

  • Dont schedule it too frequently, I would say at least 10 minute intervals, but even 30+ minutes would be better. Consider the compromise between cost and accuracy.
  • Don’t put this on the index/landing page, only use it inside your actual app.
  • Make sure to only use it on logged in users
  • Consider implementing a basic activity checker that checks whether the user is making any actions at all. If after 1-2 hours the activity checker is still reporting no activity, stop running the workflow and mark the user as AFK.
  • Consider implementing a basic multitab checker, so that in the scenario that the user has multiple tabs open, the workflow only runs in one of them to save WUs.

There also are Plugins which track when a page/tab is closed or when a user goes idle.

I have never had to implement an online status tracker on an app, and i have never tried using this plugin. I cannot guarnatee it works 100% of the time across all devices. I generally dont love using plugins, however it could be worth it here. Test it.

This topic was automatically closed after 70 days. New replies are no longer allowed.