Meteor-Community-Packages / meteor-user-status

Track user connection state and inactivity in Meteor.
MIT License
558 stars 86 forks source link

How to track anonymous users? #52

Open hexsprite opened 9 years ago

hexsprite commented 9 years ago

Is there a way to track anonymous users?

hexsprite commented 9 years ago

I found your answer here: http://stackoverflow.com/questions/13544333/how-to-track-the-number-of-anonymous-users-server-side-in-meteor

I'm assuming I would have to look at the server side in memory UserStatus?

mizzao commented 9 years ago

Yep. You can also use the connectionX events as shown in the README.

If you want to do something on the client side, you may want to publish some information about the user as I described in #53.

KristerV commented 9 years ago

I find it very easy to combine mizzao:user-status with artwells:accounts-guest - it creates a guest user for the visitors, which user-status works great with out of the box.

evolross commented 8 years ago

Just needed to do this myself. Getting the anonymous user count is as easy as querying the in-memory UserStatus.connections collection for connections without a userId.

UserStatus.connections.find({userId: {$exists: false}}).count()

evolross commented 8 years ago

This leads to another question... I want to get the above anonymous user count reactively to my client... it seems this is really hard/impossible if I don't have the UserStatus.connections collection setup on my client as well so I can do a proper pub/sub. How would I create a "client version" of this collection so I can connect to the "server-only" version? Otherwise it's damn near impossible get a "server-only" var reactively to the client.