Kameleoon. Client
(kameleoon_client v0.9.1)
Copy Markdown
Elixir wrapper over a native Kameleoon client Rustler resource.
Summary
Functions
Registers a zero-argument callback invoked whenever the data file (configuration) is updated.
Registers a handler for an SDK event type, or clears it by passing nil.
Types
@type t() :: %Kameleoon.Client{ environment: String.t() | nil, events: GenServer.server(), native: term(), site_code: String.t() | nil }
Functions
@spec get_datafile(t()) :: {:ok, Kameleoon.Types.DataFile.t()} | {:error, Kameleoon.Error.t()}
@spec get_visitor_code(t(), Kameleoon.CookieAccessor.t(), String.t() | nil) :: {:ok, String.t(), Kameleoon.CookieAccessor.state()} | {:error, Kameleoon.Error.t()}
@spec get_visitor_warehouse_audience(t(), String.t(), non_neg_integer(), keyword()) :: :ok | {:error, Kameleoon.Error.t()}
Registers a zero-argument callback invoked whenever the data file (configuration) is updated.
Deprecated: use set_event_handler/3 with :datafile_update instead, which also reports the
update source and the data file modification date.
@spec set_event_handler( t(), Kameleoon.Native.Events.event_type(), (term() -> any()) | nil ) :: :ok | {:error, Kameleoon.Error.t()}
Registers a handler for an SDK event type, or clears it by passing nil.
The handler is a one-argument function which receives an event struct. At most one handler is kept per event type per client, so registering a handler replaces the previous one.
Supported event types and the events they deliver:
:http_request—Kameleoon.Events.HttpRequestSucceededandKameleoon.Events.HttpRequestFailed, once per actual HTTP request attempt the SDK performs, retries included.:datafile_update—Kameleoon.Events.DataFileUpdateEvent, whenever the data file (configuration) is updated by polling or by a real-time (streaming) notification.
Handlers run in their own task, so a crashing handler is logged and never affects the SDK, and a slow handler does not delay the SDK's own work.
Kameleoon.Client.set_event_handler(client, :http_request, fn
%HttpRequestSucceeded{request_type: type, http_status: status, duration_ms: ms} ->
:telemetry.execute([:kameleoon, :request], %{duration_ms: ms}, %{type: type, status: status})
%HttpRequestFailed{request_type: type, failure: failure} ->
Logger.warning("kameleoon #{type} request failed: #{failure.reason}")
end)
@spec set_forced_variation( t(), String.t(), non_neg_integer(), String.t() | nil, keyword() ) :: :ok | {:error, Kameleoon.Error.t()}
@spec set_legal_consent( t(), String.t(), boolean(), Kameleoon.CookieAccessor.t() | nil ) :: {:ok, Kameleoon.CookieAccessor.state() | nil} | {:error, Kameleoon.Error.t()}
@spec track_conversion(t(), String.t(), non_neg_integer(), keyword()) :: :ok | {:error, Kameleoon.Error.t()}