elnovice
Tracking users, I may miss some pieces. Novice alert
Hi all,
I am trying to track users using Presence, but I might miss some important pieces.
I would like to track every user on the website.
If I track a user in iex, I am able to see it in the tracking page:
iex(26)> MyAppWeb.Presence.track(self(), "myapp:presence", user.id, %{email: user.email})
So I decided to put the same line in every controller, to track users that navigates the various pages, but what I got as the presence message diff is something like:
%{
joins: %{
"c6d10ab9-13bd-4809-aed7-89549ee66e47" => %{
metas: [%{email: "user@email.com", phx_ref: "F0PzlVF7lm0KmiCL"}]
}
},
leaves: %{}
}
%{
joins: %{},
leaves: %{
"c6d10ab9-13bd-4809-aed7-89549ee66e47" => %{
metas: [%{email: "user@email.com", phx_ref: "F0PzlVF7lm0KmiCL"}]
}
}
}
So like the user joined and then left right after.
What am I missing here?
Sorry for being so novice, I am trying to learn by doing…
Kind Regards
Marked As Solved
LostKobrakai
Controllers only handle the http request and then stop. So they’re only active while the page is loading for your users. Once loading completes the process handling the request has stopped. You’d want to use e.g. the phoenix channels implementation to track their presence on a long running process, which actually maps to their time spending on the then loaded page.







