Elixir

Last updated:

|Edit this page
Which features are available in this library?
  • Event capture
  • Autocapture
  • User identification
  • Session recording
  • Feature flags
  • Group analytics

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

Installation

This library was built by the community and is not maintained by the PostHog core team.

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

Elixir
def deps do
[
{:posthog, "~> 0.1"}
]
end

Configuration

Elixir
config :posthog,
api_url: "<ph_instance_address>",
api_key: "<ph_project_api_key>"

Optionally, you can pass in a :json_library key. The default JSON parser is Jason.

Capturing events

You can send custom events using capture:

Elixir
Posthog.capture("user_signed_up", %{
distinct_id: distinct_id_of_the_user
})

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 also include additional information in the event by setting the properties value:

Elixir
Posthog.capture("user_signed_up", %{
distinct_id: distinct_id_of_the_user,
properties: %{
login_type: "email",
is_free_trial: true
}
})

Batching events

To capture multiple events at once, use batch():

Elixir
Posthog.batch([{"user_signed_up", [distinct_id: distinct_id_of_the_user], nil}])

Feature flags

PostHog's feature flags enable you to safely deploy and roll back new features.

Feature flags are not supported yet in our Elixir SDK. However, you can integrate them into your project by using the PostHog API.

Thanks

Thanks to nkezhaya for contributing this library.

Questions?

Was this page useful?

Next article

Flutter

This is an optional library you can install if you're working with Flutter. It uses an internal queue to make calls fast and non-blocking. It also batches requests and flushes asynchronously, making it perfect to use in any part of your mobile app. PostHog supports the iOS, macOS, Android and Web platforms. Installation Usage To use this, add posthog_flutter as a dependency in your pubspec.yaml file . Example Capturing events Identify We highly recommend reading our section on Identifying…

Read next article