elnovice

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

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.

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement