mirror of
https://github.com/BillyOutlast/posthog.com.git
synced 2026-02-09 13:51:20 +01:00
38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
`PostHog.FeatureFlags.check/2` is the main function for checking a feature flag in Elixir. More documentation on it can be found in the [HexPM Docs](https://hexdocs.pm/posthog/PostHog.FeatureFlags.html).
|
|
|
|
|
|
#### Boolean feature flags
|
|
|
|
```elixir
|
|
iex> PostHog.FeatureFlags.check("example-feature-flag-1", "user123")
|
|
{:ok, true}
|
|
```
|
|
|
|
It will attempt to take `distinct_id` from the context if it's not provided.
|
|
|
|
```elixir
|
|
iex> PostHog.set_context(%{distinct_id: "user123"})
|
|
:ok
|
|
iex> PostHog.FeatureFlags.check("example-feature-flag-1")
|
|
{:ok, true}
|
|
```
|
|
|
|
|
|
#### Multivariate feature flags
|
|
|
|
```elixir
|
|
iex> PostHog.FeatureFlags.check("example-feature-flag-1", "user123")
|
|
{:ok, "variant2"}
|
|
```
|
|
|
|
### Errors
|
|
|
|
We'll return an error if the feature flag doesn't exist.
|
|
|
|
```elixir
|
|
iex> PostHog.FeatureFlags.check("example-feature-flag-3", "user123")
|
|
{:error, %PostHog.UnexpectedResponseError{message: "Feature flag example-feature-flag-3 was not found in the response", response: ...}}
|
|
```
|
|
|
|
You can also use `PostHog.FeatureFlags.check!/2` if you're feeling adventurous or running a script and prefer errors to be raised instead.
|