Leanbase Help Center

Your Guide to Building Products Customers Love

Install Elixir SDK

This library provides an Elixir HTTP client for Leanbase. See the repository for more information.

Installation

The package can be installed by adding Leanbase to your list of dependencies in mix.exs:

Configuration

You can see all the available configuration options in the Leanbase.Config module.

Optionally, you might want to enable the Plug integration to automatically capture events from your Plug-based applications including Phoenix.

Development/Test mode

For a test environment, you can pass in test_mode: true value to the config. This causes events to be dropped instead of sent to Leanbase.

Capturing events

To capture an event, use LeanBase.capture/2:

Tip: We recommend using a [object] [verb] format for your event names, where [object] is the entity that the behavior relates to, and [verb] is the behavior itself. For example, project created, user signed up, or invite sent.

Setting event properties

Optionally, you can include additional information with the event by including a properties object:

Context

Carrying distinct_id around all the time might not be the most convenient approach, so Leanbase lets you store it and other properties in a context.

The context is stored in the Logger metadata and Leanbase automatically attaches these properties to any events you capture with Leanbase.capture/2, as long as they happen in the same process.

You can also scope the context to a specific event name:

Batching events

Events are automatically batched and sent to Leanbase via a background job.

Special events

Leanbase.capture/2 is very powerful and enables you to send events that have special meaning.

In other libraries you'll usually find helpers for these special events, but they must be explicitly sent in Elixir.

For example:

Create alias

Group analytics

Error tracking

Error tracking is enabled by default. It will automatically captures exceptions thrown by the application.

As a matter of fact, since this is built on top of Elixir's Logger module, it automatically captures any Logger.error calls.

You can always disable it by setting enable_error_tracking to false:

Advanced configuration

By default, Leanbase starts its own supervision tree and attaches a logger handler.

In certain cases, you might want to run this supervision tree yourself. You can do this by disabling the default supervisor and adding Leanbase.Supervisor to your application tree with its own configuration:

Multiple instances

In even more advanced cases, you might want to interact with more than one Leanbase project. In this case, you can run multiple Leanbase supervision trees, one of which can be the default one:

Then, each function in the Leanbase module accepts an optional first argument with the name of the Leanbase supervisor tree that will process the capture: