How to detect when a user is logged in

I’m trying to count the number of times a user logs in. The problem is when the user selects to Stay logged in, how do I count how many times this user visits the app? It’s a single-page app and counting page loads is not likely to work at all.

Thanks.

How do you define app visits?

Opening the app after closing the tab?
Do you define a certain time between visits to be counted?

Those are great questions! I realize I should have been more specific.

What I’m trying to track is simply how many users are revisiting the app and using it. For now I’m only interested in whether they viewed my app at least once in a day.

I have users that are using the app every day who are not recognized as revisiting the app. I think it’s probably just open in their browser and they stay logged in and don’t restart their computer (a complete guess, of course). I also enabled the Stay Logged in feature when they log in, so they may have also just selected that.

You’re definitely right that some users staying logged in with the app open in a browser tab might not trigger a page reload — so workflows like “Page is loaded” won’t run again, and they won’t be tracked as revisiting.

A more reliable approach is to track actual user interactions, not just whether they loaded the page.

Instead of only relying on page load, update the user’s last_visited_date whenever they interact with the app in a meaningful way — for example:

  • Clicking a button
  • Typing in an input
  • Saving a form, etc.

You will need two fields:

  • last_visited_date (type: date)
  • visit_count (type: number)

Then you can create a custom event to add to the key workflows (like button clicks, navigation, etc.):

  • Add a condition:
    Only when Current date/time:formatted as 5/07/25 is not Current User’s last_visited_date:formatted as 5/07/25

  • Then use this action:
    Make changes to Current User →
    last_visited_date = Current date/time
    visit_count = Current User’s visit_count + 1

This way is more reliable because it tracks real activity

1 Like

How do you define to view your app? :grinning_face_with_smiling_eyes:

I guess you refer to having the app opened in a focused browser tab.

You can have a Do every X seconds workflow that

  • Updates a lastFirstVisitOfDay (date) field in the User table.
  • Executes only if the value of the field is not a today’s timestamp.
  • Increases a counter stored in dailyAppVisits (number) of table User.

Disclaimer: Do every X seconds workflows stop executing when the User loses connection with Bubble servers under some circunstances, e.g. suffers a connection outage or hibernates the device. So, test if this is enough for your use case, otherwise you’ll need a more convoluted solution similar to what I exposed in User presence system design (user online/offline status).