Keep User Logged Activity

I’m thinking of two solutions:
Have an Activity collection, where documents are activity records, which are inserted at the end of every method.


Have an activity field on User documents, and push that user’s activity records into that array field.
I’m thinking solution 1 is better. Thoughts?

Question 2) How do I Easily differential online users from offline.

I would personally create a collection specifically for logging activity and use the matb33:collection-hooks package to keep track of activity.

As far as online/offline I’ll shamelessly plug socialize:user-presence


Ive used user-presence, it ROCKS.


You should definitely use the user-presence package for presence.

Don’t overthink user activity. If this is for analytics purposes, your first method is fine, but provide an empty callback to your database writes so you’re never slowing down important application code due to analytics work. But you’ll get a lot more value out of Mixpanel or Google Analytics for this purpose.

If this is for cosmetic purposes to render say, “Last post was: … Last comment was: … Last logged in: …”, try to compute exactly what it is that you need to render the client, and save that directly to the document that will be rendered in the page the user visits to read the activity. You definitely don’t want to be querying limit + sort some huge number of activity records for a cosmetic thing like that.

1 Like