Skip to content

Commit 8976087

Browse files
docs: Add feature flags support to Elixir (#10588)
Co-authored-by: Ian Vanagas <[email protected]>
1 parent 3810e7a commit 8976087

File tree

10 files changed

+86
-25
lines changed

10 files changed

+86
-25
lines changed

contents/blog/how-to-measure-product-engagement.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ In this article we’ll take a look at why strong customer engagement metrics ar
2424

2525
- [What is product engagement?](#what-is-product-engagement)
2626
- [What are product engagement metrics?](#what-are-product-engagement-metrics)
27+
- [Common engagement metrics](#common-engagement-metrics)
2728
- [What is the best way to measure product engagement?](#what-is-the-best-way-to-measure-product-engagement)
29+
- [Active users](#active-users)
30+
- [Stickiness](#stickiness)
31+
- [Adoption](#adoption)
2832
- [What tools are good for tracking product engagement?](#what-tools-are-good-for-tracking-product-engagement)
2933
- [Further reading](#further-reading)
3034

@@ -88,7 +92,7 @@ An easier way to track this is to use a tool such as PostHog, which has a dedica
8892
Adoption represents the number of users using key features in your product.
8993
Each new feature presents an opportunity for additional customer value. Low adoption implies that you’re offering something which users don’t need, or that there’s something wrong with the feature itself. High adoption means users are flocking to a new feature.
9094

91-
If users are paying for features they don’t use then it lowers the perceived value, so it’s essential to keep an eye on what isn’t working and rollback where necessary. That’s why PostHog offers tools like [feature flags](https://posthog.com/docs/user-guides/feature-flags), which help you to incrementally roll out new features and key an eye on adoption progress. If something isn’t working, you can roll it back instantly.
95+
If users are paying for features they don’t use then it lowers the perceived value, so it’s essential to keep an eye on what isn’t working and rollback where necessary. That’s why PostHog offers tools like [feature flags](https://posthog.com/docs/feature-flags/tutorials), which help you to incrementally roll out new features and key an eye on adoption progress. If something isn’t working, you can roll it back instantly.
9296

9397
[Flagging the use of specific features as a key event](https://posthog.com/docs/user-guides/events) per user type will also help you to track adoption.whether you’re successfully reaching the users they were intended for.
9498

contents/docs/experiments/adding-experiment-code.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,18 @@ if variant == "variant-name" {
140140
// Do something
141141
}
142142
```
143+
144+
```elixir
145+
{:ok, feature_flag} = PostHog.feature_flag("experiment-feature-flag-key", "user_distinct_id")
146+
147+
if feature_flag.enabled == "variant-name" do
148+
# Do something
149+
end
150+
```
151+
143152
</MultiLanguage>
144153

145-
> Since feature flags are not supported yet in our Java, Rust, and Elixir SDKs, to run an experiment using these SDKs see our docs on [how to run experiments without feature flags](/docs/experiments/running-experiments-without-feature-flags). This also applies to running experiments using our API.
154+
> Since feature flags are not supported yet in our Java and Rust SDKs, to run an experiment using these SDKs see our docs on [how to run experiments without feature flags](/docs/experiments/running-experiments-without-feature-flags). This also applies to running experiments using our API.
146155
147156
## Step 2 (server-side only): Add the feature flag to your events
148157

contents/docs/experiments/installation.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import GoInstall from '../integrate/_snippets/install-go.mdx'
2929
import ReactNativeInstall from '../integrate/_snippets/install-react-native.mdx'
3030
import AndroidInstall from '../integrate/_snippets/install-android.mdx'
3131
import IOSInstall from '../integrate/_snippets/install-ios.mdx'
32+
import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'
3233

3334
<!-- prettier-ignore -->
34-
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS']}>
35+
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Java', 'Rust', 'Elixir', 'api']}>
3536
<Tab.List>
3637
<Tab>Web</Tab>
3738
<Tab>React</Tab>
@@ -90,9 +91,7 @@ import IOSInstall from '../integrate/_snippets/install-ios.mdx'
9091
</blockquote>
9192
</Tab.Panel>
9293
<Tab.Panel>
93-
<blockquote class='warning-note'>
94-
Since feature flags are not supported yet in our <a href="/docs/libraries/elixir">Elixir SDK</a>, see our docs on <a href="/docs/experiments/running-experiments-without-feature-flags">how to run experiments without feature flags</a>.
95-
</blockquote>
94+
<ElixirInstall />
9695
</Tab.Panel>
9796
<Tab.Panel>
9897
<blockquote class='warning-note'>

contents/docs/feature-flags/adding-feature-flag-code.mdx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import ReactNativeFeatureFlagsCode from '../integrate/feature-flags-code/_snippe
2424
import AndroidFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-android.mdx'
2525
import IOSFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-ios.mdx'
2626
import FlutterFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-flutter.mdx'
27+
import ElixirFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-elixir.mdx'
2728

2829
<!-- prettier-ignore -->
2930
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Flutter', 'Java', 'Rust', 'Elixir', 'api']}>
@@ -89,9 +90,7 @@ import FlutterFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/f
8990
</blockquote>
9091
</Tab.Panel>
9192
<Tab.Panel>
92-
<blockquote class='warning-note'>
93-
Feature flags are not supported yet in our <a href="/docs/libraries/elixir">Elixir SDK</a>. However, you can integrate them into your project by using the <a href="/docs/feature-flags/adding-feature-flag-code?tab=api">PostHog API</a>.
94-
</blockquote>
93+
<ElixirFeatureFlagsCode />
9594
</Tab.Panel>
9695
<Tab.Panel>
9796
<APIFeatureFlagsCode />

contents/docs/feature-flags/installation.mdx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import FlutterInstall from '../integrate/_snippets/install-flutter.mdx'
3333
import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'
3434

3535
<!-- prettier-ignore -->
36-
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Java', 'Rust', 'Elixir', 'Flutter', 'api']}>
36+
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Java', 'Rust', 'Flutter', 'Elixir', 'api']}>
3737
<Tab.List>
3838
<Tab>Web</Tab>
3939
<Tab>React</Tab>
@@ -47,8 +47,8 @@ import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'
4747
<Tab>iOS</Tab>
4848
<Tab>Java</Tab>
4949
<Tab>Rust</Tab>
50-
<Tab>Elixir</Tab>
5150
<Tab>Flutter</Tab>
51+
<Tab>Elixir</Tab>
5252
<Tab>API</Tab>
5353
</Tab.List>
5454
<Tab.Panels>
@@ -93,12 +93,10 @@ import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'
9393
</blockquote>
9494
</Tab.Panel>
9595
<Tab.Panel>
96-
<blockquote class='warning-note'>
97-
Feature flags are not supported yet in our <a href="/docs/libraries/elixir">Elixir SDK</a>. However, you can integrate them into your project by using the <a href="/docs/feature-flags/installation?tab=api">PostHog API</a>.
98-
</blockquote>
96+
<FlutterInstall />
9997
</Tab.Panel>
10098
<Tab.Panel>
101-
<FlutterInstall />
99+
<ElixirInstall />
102100
</Tab.Panel>
103101
<Tab.Panel>
104102
<APIInstall />
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Elixir supports a subset of what our [feature flag API](/docs/api/decide) provides.
2+
3+
#### Boolean feature flags
4+
5+
```elixir
6+
is_my_flag_enabled = Posthog.feature_flag_enabled?("flag-key", "distinct_id_of_your_user")
7+
8+
if is_my_flag_enabled
9+
# Do something differently for this user
10+
# Optional: fetch the payload
11+
{:ok, feature_flag} = Posthog.feature_flag("flag-key", "distinct_id_of_your_user")
12+
end
13+
```
14+
15+
#### Multivariate feature flags
16+
17+
```elixir
18+
{:ok, feature_flag} = Posthog.feature_flag("flag-key", "distinct_id_of_your_user")
19+
# %Posthog.FeatureFlag{ name: "flag-key", value: %{"variant-1" => "value-1", "variant-2" => "value-2"}, enabled: "variant-2" }
20+
21+
if feature_flag.enabled == 'variant-2' # replace 'variant-2' with the key of your variant
22+
# Do something differently for this user
23+
end
24+
```
25+
26+
#### Fetching all feature flags
27+
28+
```elixir
29+
Posthog.feature_flags("distinct_id_of_your_user")
30+
31+
{:ok,
32+
%{
33+
"featureFlagPayloads" => %{
34+
"feature-1" => 1,
35+
"feature-2" => %{"variant-1" => "value-1", "variant-2" => "value-2"}
36+
},
37+
"featureFlags" => %{"feature-1" => true, "feature-2" => "variant-2"}
38+
}}
39+
40+
```
41+
42+
More documentation can be found in the [repository](https://github.com/nkezhaya/posthog).

contents/docs/libraries/elixir/index.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ icon: >-
1111
features:
1212
eventCapture: true
1313
userIdentification: true
14-
featureFlags: false
14+
featureFlags: true
1515
groupAnalytics: true
1616
surveys: false
1717
llmObservability: false
@@ -38,7 +38,9 @@ import FeatureFlagsLibsIntro from "../_snippets/feature-flags-libs-intro.mdx"
3838

3939
<FeatureFlagsLibsIntro />
4040

41-
Feature flags are not supported yet in our Elixir SDK. However, you can integrate them into your project by using the [PostHog API](/docs/feature-flags/adding-feature-flag-code?tab=api).
41+
import ElixirFeatureFlagsCode from '../../integrate/feature-flags-code/_snippets/feature-flags-code-elixir.mdx'
42+
43+
<ElixirFeatureFlagsCode />
4244

4345
## Thanks
4446

src/components/LibraryFeatures/index.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ const features = [
99
{
1010
key: 'autoCapture',
1111
name: 'Autocapture',
12-
url: 'https://posthog.com/docs/data/autocapture',
12+
url: 'https://posthog.com/docs/product-analytics/autocapture',
1313
},
1414
{
1515
key: 'userIdentification',
1616
name: 'User identification',
17-
url: 'https://posthog.com/docs/integrate/identifying-users',
17+
url: 'https://posthog.com/docs/product-analytics/identify',
18+
},
19+
{ key: 'sessionRecording', name: 'Session replay', url: 'https://posthog.com/docs/session-replay' },
20+
{ key: 'featureFlags', name: 'Feature flags', url: 'https://posthog.com/docs/feature-flags' },
21+
{
22+
key: 'groupAnalytics',
23+
name: 'Group analytics',
24+
url: 'https://posthog.com/docs/product-analytics/group-analytics',
1825
},
19-
{ key: 'sessionRecording', name: 'Session replay', url: 'https://posthog.com/docs/user-guides/recordings' },
20-
{ key: 'featureFlags', name: 'Feature flags', url: 'https://posthog.com/docs/user-guides/feature-flags' },
21-
{ key: 'groupAnalytics', name: 'Group analytics', url: 'https://posthog.com/docs/user-guides/group-analytics' },
2226
{ key: 'surveys', name: 'Surveys', url: 'https://posthog.com/docs/surveys' },
2327
{
2428
key: 'llmObservability',
@@ -29,7 +33,7 @@ const features = [
2933
] as const
3034

3135
export type LibraryFeaturesProps = {
32-
availability?: Record<typeof features[number]['key'], boolean>
36+
availability?: Record<(typeof features)[number]['key'], boolean>
3337
}
3438

3539
export const LibraryFeatures = ({ availability }: LibraryFeaturesProps) => {

src/navs/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,9 @@ export const docsMenu = {
13001300
{
13011301
name: 'Elixir',
13021302
url: '/docs/libraries/elixir',
1303+
badge: {
1304+
title: '3rd party',
1305+
},
13031306
},
13041307
{
13051308
name: 'Flutter',

vercel.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@
128128
{ "source": "/docs/features/cohorts", "destination": "/docs/user-guides/cohorts" },
129129
{ "source": "/docs/features/dashboards", "destination": "/docs/user-guides/dashboards" },
130130
{ "source": "/docs/features/events", "destination": "/docs/user-guides/events" },
131-
{ "source": "/docs/features/feature-flags", "destination": "/docs/user-guides/feature-flags" },
132131
{ "source": "/docs/features/funnels", "destination": "/docs/user-guides/funnels" },
133132
{ "source": "/docs/features/organizations", "destination": "/docs/user-guides/organizations" },
134133
{ "source": "/docs/features/paths", "destination": "/docs/user-guides/paths" },
@@ -676,7 +675,9 @@
676675
{ "source": "/docs/experiments/under-the-hood", "destination": "/docs/experiments/experiment-significance" },
677676
{ "source": "/docs/experiments/significance", "destination": "/docs/experiments/experiment-significance" },
678677
{ "source": "/docs/session-replay/manual", "destination": "/docs/session-replay/installation" },
679-
{ "source": "/docs/user-guides/feature-flags", "destination": "/docs/feature-flags/manual" },
678+
{ "source": "/docs/features/feature-flags", "destination": "/docs/feature-flags" },
679+
{ "source": "/docs/user-guides/feature-flags", "destination": "/docs/feature-flags" },
680+
{ "source": "/docs/feature-flags/manual", "destination": "/docs/feature-flags" },
680681
{ "source": "/manual/group-analytics", "destination": "/docs/product-analytics/group-analytics" },
681682
{ "source": "/docs/product-analytics/hogql", "destination": "/docs/hogql" },
682683
{ "source": "/docs/hogql/guide", "destination": "/docs/product-analytics/sql" },

0 commit comments

Comments
 (0)