Counting number of days user has logged in on

Hi.

I’m trying to calculate the number of individual days that a user has logged in on.

I’m relatively new to Bubble and unfortunately am stumped on this and couldn’t find any discussions addressing this elsewhere on the forum.

I’ve set up a workflow so that +1 could be applied to a field on the action ‘When user is logged in’ but this would, of course, calculate the total number of logins rather than the number of individual days where X user has logged in.

If anybody has a way to calculate this it would be very much appreciated.

Many thanks,
Jeremy

The slam-dunk approach requires a professional plan unfortunately and that’s scheduling a Recurring Workflow API on a daily frequency (doesn’t matter the launch time):

-A DB entry gets updated on user login with the timestamp of when the user logged in.
-The daily recurring worklflow just scans that column for all times that are within the last 24 hours and for all such users, adds one to their counter.

In API workflow:
-DB Make changes to list of things
–Do a search for users, constraint Last_logged_in timestamp > CUrrent Date/Time +hours: -24
–Increment field = Increment field + 1

Hi there, @JeremySimpson… here’s an idea that wouldn’t require a professional plan (no offense to Jesse, of course)… just food for thought.

Add a field called last login to the User data type. When a user logs in, increment their login counter by 1 only when the date in the user’s last login field is not the current date. Then, update the last login field to be the current date only when the date that’s in the field is not the current date.

So, for example, a user whose last login was yesterday (July 10) logs in today (July 11). The workflow updates the user’s login counter by 1 because the date in the user’s last login field is not the current date (i.e., the date in the field is July 10 rather than July 11). Then, the workflow updates the last login date to July 11 because the date in the field is not already July 11. Now, assume the user logs in again on July 11. Neither of those workflows will trigger because the date in the last login field is the current date.

Any of that make sense? Hope so… and again, just food for thought.

Best…
Mike

3 Likes

Yep, this idea is better. Update increment_counter on user login if last_login < Curdate:+hours -24. Then update last_login (but only if last_login < 24 hours ago!!)

Go with this one. Also removes the risk of an outage whereby the recurring API doesn’t fire and you miss some counts.

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