BilldogEng.Analytics (BilldogEng v1.0.0-beta.1)

Copy Markdown View Source

Analytics client: capture/identify/groupIdentify/alias + batching.

Events accumulate in an in-memory queue (held in this GenServer) and are flushed as a single batched POST to /ingest-events when:

  • the queue reaches flush_at,
  • the background timer fires every flush_interval, or
  • flush/1 / shutdown/1 is called.

A failed flush re-queues its batch (front of the queue) so events are never lost on a single transient failure; the BilldogEng.Transport also retries with backoff before a flush is considered failed.

Mirrors the Node SDK analytics.ts.

Summary

Functions

Alias one distinct id to another. Emits $create_alias.

Capture an arbitrary event for a user. Batched per the configured policy.

Returns a specification to start this module under a supervisor.

Force-flush the queue immediately. Blocks until the in-flight batch settles.

Set properties on a group. Emits $groupidentify.

Set person properties. Emits $identify.

Current number of queued (not-yet-flushed) events.

Flush remaining events and stop the background timer.

Functions

alias(pid, distinct_id, alias)

@spec alias(pid(), String.t(), String.t()) :: :ok

Alias one distinct id to another. Emits $create_alias.

capture(pid, distinct_id, event, properties \\ %{}, groups \\ %{})

@spec capture(pid(), String.t(), String.t(), map(), map()) :: :ok

Capture an arbitrary event for a user. Batched per the configured policy.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

flush(pid)

@spec flush(pid()) :: :ok | {:error, BilldogEng.Error.t()}

Force-flush the queue immediately. Blocks until the in-flight batch settles.

group_identify(pid, group_type, group_key, properties \\ %{})

@spec group_identify(pid(), String.t(), String.t(), map()) :: :ok

Set properties on a group. Emits $groupidentify.

identify(pid, distinct_id, properties \\ %{})

@spec identify(pid(), String.t(), map()) :: :ok

Set person properties. Emits $identify.

queue_length(pid)

@spec queue_length(pid()) :: non_neg_integer()

Current number of queued (not-yet-flushed) events.

shutdown(pid)

@spec shutdown(pid()) :: :ok | {:error, BilldogEng.Error.t()}

Flush remaining events and stop the background timer.