Packages
posthog
0.3.0
2.16.2
2.16.1
2.16.0
2.15.1
2.15.0
2.14.2
2.14.1
2.14.0
2.13.0
2.12.1
2.12.0
2.11.1
2.11.0
2.10.3
2.10.2
2.10.1
2.10.0
2.9.2
2.9.1
2.9.0
2.8.4
2.8.3
2.8.2
2.8.1
2.8.0
2.7.1
2.7.0
2.6.1
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.0
2.0.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.0
0.2.0
0.1.0
Official PostHog Elixir SDK
Current section
Files
Jump to
Current section
Files
README.md
# Posthog
This library provides an HTTP client for Posthog.
## Installation
The package can be installed by adding `posthog` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:posthog, "~> 0.3"}
]
end
```
## Configuration
```elixir
config :posthog,
api_url: "http://posthog.example.com",
api_key: "..."
```
You can pass in a `:json_library` key. The default JSON parser is Jason.
You can pass in a `:version` key. The default version is 3 (which is currently the latest).
## Usage
Capturing events:
```elixir
Posthog.capture("login", distinct_id: user.id)
```
Specifying additional headers:
```elixir
Posthog.capture("login", [distinct_id: user.id], [headers: [{"x-forwarded-for", "127.0.0.1"}]])
```
Capturing multiple events:
```elixir
Posthog.batch([{"login", [distinct_id: user.id], nil}])
```
Fetching all matched feature flags for identifier:
```elixir
Posthog.feature_flags("distinct-id")
{:ok,
%{
"featureFlagPayloads" => %{
"feature-1" => 1,
"feature-2" => %{"variant-1" => "value-1", "variant-2" => "value-2"}
},
"featureFlags" => %{"feature-1" => true, "feature-2" => "variant-2"}
}}
```
Fetching match information for a feature flag:
```elixir
# For boolean feature flags
Posthog.feature_flag("feature-1", "matching-id")
{:ok,
%Posthog.FeatureFlag{
name: "feature-1",
value: 1,
enabled: true
}}
Posthog.feature_flag("feature-1", "non-matching-id")
{:ok,
%Posthog.FeatureFlag{
name: "feature-1",
value: nil,
enabled: false
}}
# For multivariate feature flags
Posthog.feature_flag("feature-2", "distinct-id")
{:ok,
%Posthog.FeatureFlag{
name: "feature-2",
value: %{"variant-1" => "value-1", "variant-2" => "value-2"},
enabled: "variant-2"
}}
# For non-existent or disabled feature flags
{:error, :not_found}
```
Checking if feature flag is enabled:
```elixir
Posthog.feature_flag_enabled?("feature-2", "distinct-id")
true
```