Elixir

Last updated:

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

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

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

Installation

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.

Usage

Call Posthog.capture() with an event name and distinct_id as a property to capture an event. You can also pass in any other properties, including person and group properties, as a map.

Elixir
Posthog.capture("login", %{
distinct_id: user.id,
email: user.email,
plan: user.plan,
"$set": %{
email: user.email,
proUser: false,
"$groups": %{
organization: "twitter"
}
},
"$set_once": %{
user_first_location: "colorado"
}
})

To capture multiple events at once, use Posthog.batch().

Elixir
Posthog.batch([{"login", [distinct_id: user.id], nil}])

Thanks

Thanks to nkezhaya for contributing this library.

Questions?

Was this page useful?

Next article

Flutter

This is a community maintained library. It is not officially supported by PostHog. 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. Package Usage To use this, add posthog_flutter as a dependency in your pubspec.yaml file . Supported methods Method Android iOS Web identify X X X capture X X X…

Read next article