JohnnyCurran / TimeTravel

Phoenix LiveView TimeTravel Debugger
MIT License
114 stars 0 forks source link

Could this be extended to allow user session capture? #16

Open alexslade opened 9 months ago

alexslade commented 9 months ago

@JohnnyCurran I've discovered this recently while looking for session replay functionality for user testing (not debugging, as this lib seems to be intended).

Have you considered extending this to capture events without the browser plugin? And to allow replay / live viewing of a session? Similar to wha tools like posthog.com do, but without sending data out to 3rd parties.

Or, if I wanted to attempt extending this, do you think the current implementation is compatible with that concept or not?

JohnnyCurran commented 8 months ago

Hi @alexslade ,

Sorry for the delay, this got buried under my other GH notifications

Obviously the biggest drawback to the Telemetry approach is going to be that you're unable to capture purely client-side events. That said, thinking about it, those are mostly limited to "show/hide a DOM element". Anything that updates client state is going to end up invoking some sort of update/handle_event/handle_info, etc.

You can see all of the telemetry events that LiveView emits here https://hexdocs.pm/phoenix_live_view/telemetry.html

You could absolutely extend this library to try and do what you need to do. You'll probably want to have a Live Hook that puts a random live session id into LiveView sessions where users are not logged in:

|> put_session(:live_socket_id, "users_socket:#{user.id}")

You may find it easier to create your own repo with this as a reference, too. Really the interesting bits are all in here: https://github.com/JohnnyCurran/TimeTravel/blob/main/lib/telemetry_handler.ex

How you store the assigns would be very interesting, too. You could consider using :erlang.term_to_binary but that does have some security implications.

Best of luck to you and if you do decide to use Telemetry for session tracking I'd like to hear how you progress with it!