ExAbby.LiveViewHelper (ex_abby v0.3.0)

Functions to handle A/B testing in a LiveView scenario:

  • Using session-based logic, but with no direct conn
  • Checking connected?(socket) before creating/recording

Summary

Functions

For a LiveView mount with multiple experiments

Links session-based trials to a user for a LiveView socket.

Sets a specific variation for a session-based experiment in LiveView. Returns {:ok, trial} if successful, {:error, reason} otherwise.

Functions

fetch_session_exp_variations_lv(socket, session, experiment_names)

For a LiveView mount with multiple experiments:

socket = ExAbby.LiveViewHelper.fetch_session_exp_variations_lv(socket, session, ["exp1", "exp2"])
  1. Checks if connected?(socket) (true once the WS is established)
  2. If connected, reads ex_abby_session_id from session
  3. Calls the underlying function to get or create a trial
  4. Assigns :ab_variation in the socket
  5. Returns the updated socket

Returns socket with :ex_abby_trials assigned as a map of %{experiment_name => variation_name}

record_success_for_session_lv(socket, experiment_name, opts \\ [])

record_successes_for_session_lv(socket, experiment_names, opts \\ [])

save_session_data(socket, session)

set_session_exp_variation_lv(socket, experiment_name, variation_name)

Sets a specific variation for a session-based experiment in LiveView. Returns {:ok, trial} if successful, {:error, reason} otherwise.