How can I sense how many people are on a page?

Hello, I’d like to make something where it senses how many people are on a page and if there are none, it clears all fields in the page’s dataset.

If you click on the ‘enter’ button, it redirects you to a page with an empty dataset and no users. If there are no free pages, a message can appear on your screen. How can I do that?

I think the only way is to generate a separate DATABASE, where you save everyone who has logged-in.

The problem is just, how to be sure when a person is logged-out again?

  1. You can make a TIMER, which will throw out the user out of your page after a certain amount of time.

  2. Some of the user maybe will log-out, where you will again be able to record this action inside your generated DB to log the user again as IN or OUT.

  3. Surely there are some more possibilities.

Try to use the SERACH of this FORUM, maybe you will have some luck to find some posts.

If you are programming a LOGIN-LOGOUT-SYSTEM, you will find maybe a lot of usefull things, following these posts & examples here…

You will find even more STUFF for READING and UNDERSTANDING.

USE THE SEARCH AND YOU WILL FIND WHAT YOU NEED!

Same problems already were bespoke years ago.

@russian-dima , In regard to your first sentence, in the PrivateMemebersData collection there’s lastLogin field that gets automatically updated with the specific login time, so no need to create a special collection for that.
(but I must say I did not understand Stef’s question, so maybe it is not relevant).

Hmm, good catch! :thinking:
So still the question how to be sure who is still online or not?

  1. Running an INTEVAL → checking for UPDATES in this field (for example all 30 secs?

But still i would not know if maybe, the person already leaved, right?

  1. I would still generate a separate DB for it. Why?
    For example generating a TRACKING-FUNCTION, which would record the users activity on my site. If no activity for more then (certain amount of time → 5min → no page-change) → LOG-OUT

  2. other option(s)?

How you would solve it?

Instead of poking with intervals, maybe it’ll be better to use wix-realtime.
This way you can publish a message from backend end to front end:

In the masterPage.js create a channel based on current page path/name.
And whenever you want, publish to these channels.
Once the message received on the front-end, it will call a jsw function and report the page name to the backend.
If no message received in the backend - it means no one is connected to this channel.
https://www.wix.com/velo/reference/wix-realtime
https://www.wix.com/velo/reference/wix-realtime-backend

Thanks i will keep it on my mind and try it out, when i find enough time for experiments.