segment v0.2.0 Segment.Analytics.Batcher

The Segment.Analytics.Batcher module is the default service implementation for the library which uses the Segment Batch HTTP API to put events in a FIFO queue and send on a regular basis.

The Segment.Analytics.Batcher can be configured with

  config :segment,
    max_batch_size: 100,
    batch_every_ms: 5000
  • config :segment, :max_batch_size The maximum batch size of messages that will be sent to Segment at one time. Default value is 100.
  • config :segment, :batch_every_ms The time (in ms) between every batch request. Default value is 2000 (2 seconds)

    The Segment Batch API does have limits on the batch size "There is a maximum of 500KB per batch request and 32KB per call.". While the library doesn't check the size of the batch, if this becomes a problem you can change max_batch_size to a lower number and probably want to change batch_every_ms to run more frequently. The Segment API asks you to limit calls to under 50 a second, so even if you have no other Segment calls going on, don't go under 20ms!

Link to this section Summary

Functions

Make a call to Segment with an event. Should be of type Track, Identify, Screen, Alias, Group or Page. This event will be queued and sent later in a batch.

Returns a specification to start this module under a supervisor.

Force the batcher to flush the queue and send all the events as a big batch (warning could exceed batch size)

Start the Segment.Analytics.Batcher GenServer with an Segment HTTP Source API Write Key

Start the Segment.Analytics.Batcher GenServer with an Segment HTTP Source API Write Key and a Tesla Adapter. This is mainly used for testing purposes to override the Adapter with a Mock.

Link to this section Functions

Make a call to Segment with an event. Should be of type Track, Identify, Screen, Alias, Group or Page. This event will be queued and sent later in a batch.

Link to this function

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

flush()

flush() :: :ok

Force the batcher to flush the queue and send all the events as a big batch (warning could exceed batch size)

Link to this function

start_link(api_key)

start_link(String.t()) :: GenServer.on_start()

Start the Segment.Analytics.Batcher GenServer with an Segment HTTP Source API Write Key

Link to this function

start_link(api_key, adapter)

start_link(String.t(), Tesla.adapter()) :: GenServer.on_start()

Start the Segment.Analytics.Batcher GenServer with an Segment HTTP Source API Write Key and a Tesla Adapter. This is mainly used for testing purposes to override the Adapter with a Mock.