View Source SauceAnalytics.Store (sauce_analytics v0.1.1)

Session store for analytics information, uses an ETS as a backend for the data.

options

Options

  • :table_name - The name of the table that the ETS will use. Defaults to :sauce_analytic_session_table
  • :session_max_age - The number of seconds before a session in the Store is considered expired. Defaults to 3600 (1 hour)
  • :clean_interval - The number of seconds that specify the period of time between each clean up of expired sessions. Defaults to 5400 (1.5 hours)

Link to this section Summary

Functions

Assigns a user to a session in the Store.

Returns a specification to start this module under a supervisor.

Returns the state/configuration of the SauceAnalytics.Store GenServer.

Increments view_sequence or event_sequence on a session in the Store.

Returns a session in the Store.

If the session referenced in revive_session does not exist, the session will be revived.

Creates a new session in the Store.

Revives a previously expired and deleted session in the Store.

Returns true if a session exists in the Store, false otherwise.

Starts the Store GenServer with the given opts.

Link to this section Types

@type opts() ::
  {:table_name, atom()}
  | {:session_max_age, integer()}
  | {:clean_interval, integer()}
@type session() ::
  {session_id :: reference(), user_agent :: String.t(),
   view_sequence :: integer(), event_sequence :: integer(),
   user_id :: String.t(), last_modified :: integer()}

Link to this section Functions

Link to this function

assign_user(session_id, user_id)

View Source
@spec assign_user(session_id :: reference(), user_id :: String.t()) ::
  :ok | {:error, :not_found}

Assigns a user to a session in the Store.

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec get_state() :: SauceAnalytics.Store.State.t()

Returns the state/configuration of the SauceAnalytics.Store GenServer.

Link to this function

inc_sequence(session_id, type)

View Source
@spec inc_sequence(session_id :: reference(), type :: :view | :event) ::
  :ok | {:error, :not_found}

Increments view_sequence or event_sequence on a session in the Store.

type can either be :view or :event

Link to this function

lookup_session(session_id)

View Source
@spec lookup_session(session_id :: reference()) ::
  {:ok, SauceAnalytics.Store.Session.t()} | {:error, :not_found}

Returns a session in the Store.

Link to this function

maybe_revive_session(revive_session)

View Source
@spec maybe_revive_session(revive_session :: SauceAnalytics.ReviveSession.t()) ::
  SauceAnalytics.Store.Session.t()

If the session referenced in revive_session does not exist, the session will be revived.

Link to this function

new_session(session_id, user_agent)

View Source
@spec new_session(session_id :: reference(), user_agent :: String.t()) :: :ok

Creates a new session in the Store.

Link to this function

revive_session(revive_session)

View Source
@spec revive_session(revive_session :: SauceAnalytics.ReviveSession.t()) ::
  SauceAnalytics.Store.Session.t()

Revives a previously expired and deleted session in the Store.

Given a SauceAnalytics.ReviveSession struct a session can be generated which contains the same session_id that the client expects.

Link to this function

session_exists?(session_id)

View Source
@spec session_exists?(session_id :: reference()) :: boolean()

Returns true if a session exists in the Store, false otherwise.

@spec start_link([opts()]) :: GenServer.on_start()

Starts the Store GenServer with the given opts.

Use this in your application supervision tree.