-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add feature flags support to Elixir (#10588)
Co-authored-by: Ian Vanagas <[email protected]>
- Loading branch information
1 parent
3810e7a
commit 8976087
Showing
10 changed files
with
86 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
contents/docs/integrate/feature-flags-code/_snippets/feature-flags-code-elixir.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Elixir supports a subset of what our [feature flag API](/docs/api/decide) provides. | ||
|
||
#### Boolean feature flags | ||
|
||
```elixir | ||
is_my_flag_enabled = Posthog.feature_flag_enabled?("flag-key", "distinct_id_of_your_user") | ||
|
||
if is_my_flag_enabled | ||
# Do something differently for this user | ||
# Optional: fetch the payload | ||
{:ok, feature_flag} = Posthog.feature_flag("flag-key", "distinct_id_of_your_user") | ||
end | ||
``` | ||
|
||
#### Multivariate feature flags | ||
|
||
```elixir | ||
{:ok, feature_flag} = Posthog.feature_flag("flag-key", "distinct_id_of_your_user") | ||
# %Posthog.FeatureFlag{ name: "flag-key", value: %{"variant-1" => "value-1", "variant-2" => "value-2"}, enabled: "variant-2" } | ||
|
||
if feature_flag.enabled == 'variant-2' # replace 'variant-2' with the key of your variant | ||
# Do something differently for this user | ||
end | ||
``` | ||
|
||
#### Fetching all feature flags | ||
|
||
```elixir | ||
Posthog.feature_flags("distinct_id_of_your_user") | ||
|
||
{:ok, | ||
%{ | ||
"featureFlagPayloads" => %{ | ||
"feature-1" => 1, | ||
"feature-2" => %{"variant-1" => "value-1", "variant-2" => "value-2"} | ||
}, | ||
"featureFlags" => %{"feature-1" => true, "feature-2" => "variant-2"} | ||
}} | ||
|
||
``` | ||
|
||
More documentation can be found in the [repository](https://github.com/nkezhaya/posthog). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters