Is there a way to count all online members?

I am looking for a way to count all currently signed in members to my site, to then be displayed on page. Is there a way to do this?

I started typing something but lost it but @russian-dima had something similar to what my suggestion was and that is logging a plus one minus one on the onlogin event.

im sure you could get something going with google analytics too. all the best!

Thanks!

No problem but who logs out of sites these days? :thinking:. You could Run a clean up process in where if someone has been online for longer than say 12 hours then don’t count them but that
would require a log table with each event logged but depends on how detailed you wanna be

I will probably add a task running every 4 hours to check if someone has been active in that time, and set their database entry false otherwise. It’s going to be a bit fiddly and I’m not sure it’s worth the effort page speed wise. Shouldn’t slow it down too much on the user’s end if I’m running it backend, right?

Nah not every four hours as a cron job you should be fine.

Just schedule so the four hour hits the non busy spots if you know what i mean? Someone else May have a better way…

may as well give it a try :slight_smile: thanks for the ideas

Yeap

@kylejsoutham
Kyle i already forgot, that i have written such an post. Ok, i am honest i can’t hold 4500-post in my head anymore.

This is an old post of me, yes it is a possible szenario, but i think i know a better way now. When i was working intensively with Wix-CRM, i made some little discovery.

You will find in the Wix-CRM-Backend an API where you can get all your contacts. Inspecring the results of this query → you will find a VALUE → called → ACTIVE. This value shows for each of your contacts if this user is online or not (logged-in) or not as i can remember. Check it out (not sure).

If i am right, you can do your cron-job and query all your contacts from BACKEND, run a Filter which would find all ACTIVE users and you have your wished results.

Doing it this way → you do not need a further own created DB. Your advantage → your code is more flexible & integrable.
Also the log-out roblem should be resolved this way.

Good luck.

@russian-dima hahah I said there’d be a better way! as for your 4503 posts I don’t blame you as I don’t remember what I did yesterday

@kylejsoutham :sweat_smile:

And here some Infos about cron-jobs…

I never have written code, related to a cron-job → so i can’t give any suggestions on it (leck of knowledge in this case).

The most frequently setup for checking for online-users would be 1-hour. I would use it, to be as most precise on the results.

I am working on a Login-system–> so this thing is also interessting for me.

I just tried to find that mentioned → ACTIVE status in the Contacts-querie again, but i think i messed something up.

The ACTIVE-state was for all MEMBERS showing if they are ACTIVE or BLOCKED. So i think i was wrong. But how ever, you still can use either the queried contacts or even the queried PMD-data to find out which user is online or not. For this there are different ways of how to achieve that.

  1. Checking the las login DATE…in the PMD-Query…
    Here you even have the exact —> TIME.
    Doing a comparisson and you know who is online and who not.
    By the way, on the pic you also can see the mentioned ACTIVE status, which was for BLOCKED or ACTIVE users on your site.

So you will get this informations, either from Wix-CRM, or you simply query your Private-Members-Database to get all these informations.

Another idea? Why using a cron-job at all? Do we need this? A cron-job can be started just every 1-hour, in 1-hour a lot can happen. Some users may already have leaved your site. How to check the queried results even more frequently?

Perhaps you can generate a code which will run when a user logs in ( onLogin() ), which would also start a checking function for online users. Addind a timelimitation for 5min or something like that → so the function will not be to frequent if you have millions of users on your site. Almost every-user who logs in, would start the check-function. (Additionaly you can also let run your cron-job in the back-ground → if anybody is active on your site for hours). —> WORST_CASE-SCENARIO :rofl::laughing::rofl::laughing:

So now you should be able to get every-5mins your new query about, who and whens was a certain USER ONLINE → because now your cron-job is done by the users itself xDDD → let the USERs work for you xD.

Teh PROBLEM → Here we just know who is perhaps currently online. Why → perhaps? → Because the user also could already logged-out in the meanwhile.

On my opinion → here an API is missed by VELO/Wix, which flags the online-state for every single user (both sides → offline and online).

So the only way now, how to figure out if the found user in our query is still online, or already gone offline in the meanwhile → there is NOW-WAY !

Ok, now it really seems, that we have no way to get an OFFLINE-STATE of a user by time.

Solution-1:
We just use the cron-job again (which runs frequently every hour), we check the the las login-date/time → if the last login was more than about 1-hour ago, we set the login state to → OFFLINE → WOW HOW PRECISE is this?

—> THAT’S → BULLSHIT ! :laughing::rofl::laughing::rofl::laughing::rofl::laughing::rofl::laughing::rofl::laughing::rofl::laughing::rofl::laughing::rofl:

Ok, next try!
Solution-2: And now ATTENTION !!!
We generate somewhere in the public-file some code, which will be triggered almost by every single ACTION of a USER, no matter if it was just a redirection, a button-click on your site or what ever.

This functions is always triggered and when this functions runs you check for the user ID who has triggered this function and you also check current and last active time. Why? Because now you have your frequent check for a single user.
When the user stops doing some ACTIONS on your site → let us say 15min or 30min, we just log the user off automaticaly.

Boom → SOLUTION works? Do we have now our OFFLINE-STATE of a USER?

Sorry → just some theoretical thoughts xDDDDDDDDDDD. :roll_eyes::sweat_smile:

In some short words…
-Generate a function → which will be able to check if a current logged-in USER is active on your site → if the user do some actions —> if not → automatic log-out.

Probably you also could use → setInterval(), to generate this cheking-functionality.

How-ever! here we have a missing API/FUNCTION, which could make everything much easier, the same way like shown here (related to the BLOCKED & ACTIVE state of a USER)…

I do agree that it feels like an API that was missed. I feel like solution-2 would probably be the best answer here but surely it should be easier then that.

@devadrianhankin
Ok, now i have found some more defined thoughts about ho to do it.
As already mentioned, you will have to look for the USERs actions on your site.
Is the user active (user make some actions by clicking on event-triggers), you set a timer to → ZERO ← everytime, when user do not reach the expiration-limit of that that timer.

Example:

  1. You have a timer-function → running on your public JS-file.
  2. Timer is setted to 15min → that means → user has to set a flag withing 15min
    —> else he will be logged out automaticaly → because not active.
  3. So all you have to do now → is to call everytime the check-timer-function when user is making some action, for example clicking on a button, or whatever is possible on your site (for every single element on your site → which has triggering functions).

And it’s done!

@devadrianhankin

By the way, there are even more missing in the Wix-CRM data/api.
You can read about it here…

Soooo, if you want to see a working solution for your issue…
take a look here…(OPEN → CONSOLE) and take → 1min ← of your time to inspect the OUTPUTS of CONSOLE.

https://russian-dima.wixsite.com/login-system

SETUP:

  1. Max-Login-Time —> 1min (auto-log-out after 1 min). [of course editable]
  2. Interval for checking of online-status —> every 15-secs. [of course editable]

As described above, it is possible to create an AUTO-LOGOUT after a certain amount of time and log-out a USER automacitaly, ensure that the user is not ACTIVE (ONLINE) anymore.

Try it yourself. If you are quick/fast enough and you press the → “Analytics-Buton” then you will be lucky to RESET the ONLINE-TIME to —> 0.
That will give you further 1min to stay → ONLINE, if not → you will get the → “LOG-OUT-MESSAGE”. :wink:

So as you can see → no CRON-JOBS needed.

I am facing a problem.
Contrary to my expectations, it seems that it is not possible, to stop/reset a running INTERVAL from everywhere you want on the PUBLIC-JS (What does not make any sense)!!!

Instead you only can stop the INTERVAL from the page where you have started it.

For example: You start ein INTERVAL-FUNCTION from → MASTER-PAGE.
—> You an stop this INTERVAL just by a trigger from MASTER-PAGE (although you have your CODE running on a PUBLIC JS-File.

The same if you do it from your normal site-page. If you start it from your normal page → you are able to stop the INTERVAL just from the normal page again, you can’t do it from MasterPage.

@yisrael-wix —> Is is a normal behaviour on a public js-file?
Shouldn’t it be possible to handle all the functions which are located on a PUBLIC-FILE → FROM → EVERYWHERE?:expressionless::neutral_face::expressionless::neutral_face::expressionless::neutral_face::expressionless::neutral_face::expressionless::neutral_face:

That means → you have to place your INTERVAL-FUNCTION on all of your pages. What an unnecessary effort, just to get the state of a user!

Ok anyway! I got it. Perhaps someone should check my mentioned issue, though.

Here now the working version…

https://russian-dima.wixsite.com/login-system

How it works?
No matter which one of the buttons you click (on normal page) → the INTERVAL resets and the timer starts again to count-up, until it reaches the predefined time of → 1min.

For the Master-Page (Header-Section) i just implemented one button for DEMO—> STOP!

If the max-Online-Time for expiration is reached → Here a user can be logged out automaticaly. → VOILA!!! → You have a working ONLINE-USER-COUNTER!
:sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses::sunglasses:

Some setup: working on a public JS-File…

//------User-Interface--------------------------------------------------------------------------
var onlineCheckInterval = 0.2; //(15sec)
var maxOnlineTime = 1;
//------User-Interface--------------------------------------------------------------------------
var myInterval;
var lastActionStamp;

Working with INTERVAL…

CONSOLE-LOG:

By the way:

  • ONLINE-TIME → MILLISECONDS
  • EXPIRATION-TIME ----> MINUTES