Skip to content

Commit

Permalink
docs: Add feature flags support to Elixir (#10588)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Vanagas <[email protected]>
  • Loading branch information
rafaeelaudibert and ivanagas authored Feb 6, 2025
1 parent 3810e7a commit 8976087
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 25 deletions.
6 changes: 5 additions & 1 deletion contents/blog/how-to-measure-product-engagement.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ In this article we’ll take a look at why strong customer engagement metrics ar

- [What is product engagement?](#what-is-product-engagement)
- [What are product engagement metrics?](#what-are-product-engagement-metrics)
- [Common engagement metrics](#common-engagement-metrics)
- [What is the best way to measure product engagement?](#what-is-the-best-way-to-measure-product-engagement)
- [Active users](#active-users)
- [Stickiness](#stickiness)
- [Adoption](#adoption)
- [What tools are good for tracking product engagement?](#what-tools-are-good-for-tracking-product-engagement)
- [Further reading](#further-reading)

Expand Down Expand Up @@ -88,7 +92,7 @@ An easier way to track this is to use a tool such as PostHog, which has a dedica
Adoption represents the number of users using key features in your product.
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.

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.
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.

[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.

Expand Down
11 changes: 10 additions & 1 deletion contents/docs/experiments/adding-experiment-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,18 @@ if variant == "variant-name" {
// Do something
}
```

```elixir
{:ok, feature_flag} = PostHog.feature_flag("experiment-feature-flag-key", "user_distinct_id")

if feature_flag.enabled == "variant-name" do
# Do something
end
```

</MultiLanguage>

> 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.
> 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.
## Step 2 (server-side only): Add the feature flag to your events

Expand Down
7 changes: 3 additions & 4 deletions contents/docs/experiments/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import GoInstall from '../integrate/_snippets/install-go.mdx'
import ReactNativeInstall from '../integrate/_snippets/install-react-native.mdx'
import AndroidInstall from '../integrate/_snippets/install-android.mdx'
import IOSInstall from '../integrate/_snippets/install-ios.mdx'
import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'

<!-- prettier-ignore -->
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS']}>
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Java', 'Rust', 'Elixir', 'api']}>
<Tab.List>
<Tab>Web</Tab>
<Tab>React</Tab>
Expand Down Expand Up @@ -90,9 +91,7 @@ import IOSInstall from '../integrate/_snippets/install-ios.mdx'
</blockquote>
</Tab.Panel>
<Tab.Panel>
<blockquote class='warning-note'>
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>.
</blockquote>
<ElixirInstall />
</Tab.Panel>
<Tab.Panel>
<blockquote class='warning-note'>
Expand Down
5 changes: 2 additions & 3 deletions contents/docs/feature-flags/adding-feature-flag-code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ReactNativeFeatureFlagsCode from '../integrate/feature-flags-code/_snippe
import AndroidFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-android.mdx'
import IOSFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-ios.mdx'
import FlutterFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-flutter.mdx'
import ElixirFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/feature-flags-code-elixir.mdx'

<!-- prettier-ignore -->
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Flutter', 'Java', 'Rust', 'Elixir', 'api']}>
Expand Down Expand Up @@ -89,9 +90,7 @@ import FlutterFeatureFlagsCode from '../integrate/feature-flags-code/_snippets/f
</blockquote>
</Tab.Panel>
<Tab.Panel>
<blockquote class='warning-note'>
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>.
</blockquote>
<ElixirFeatureFlagsCode />
</Tab.Panel>
<Tab.Panel>
<APIFeatureFlagsCode />
Expand Down
10 changes: 4 additions & 6 deletions contents/docs/feature-flags/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import FlutterInstall from '../integrate/_snippets/install-flutter.mdx'
import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'

<!-- prettier-ignore -->
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Java', 'Rust', 'Elixir', 'Flutter', 'api']}>
<Tab.Group tabs={['Web', 'React', 'Node.js', 'Python', 'PHP', 'Ruby', 'Go', 'React Native', 'Android', 'iOS', 'Java', 'Rust', 'Flutter', 'Elixir', 'api']}>
<Tab.List>
<Tab>Web</Tab>
<Tab>React</Tab>
Expand All @@ -47,8 +47,8 @@ import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'
<Tab>iOS</Tab>
<Tab>Java</Tab>
<Tab>Rust</Tab>
<Tab>Elixir</Tab>
<Tab>Flutter</Tab>
<Tab>Elixir</Tab>
<Tab>API</Tab>
</Tab.List>
<Tab.Panels>
Expand Down Expand Up @@ -93,12 +93,10 @@ import ElixirInstall from '../integrate/_snippets/install-elixir.mdx'
</blockquote>
</Tab.Panel>
<Tab.Panel>
<blockquote class='warning-note'>
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>.
</blockquote>
<FlutterInstall />
</Tab.Panel>
<Tab.Panel>
<FlutterInstall />
<ElixirInstall />
</Tab.Panel>
<Tab.Panel>
<APIInstall />
Expand Down
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).
6 changes: 4 additions & 2 deletions contents/docs/libraries/elixir/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ icon: >-
features:
eventCapture: true
userIdentification: true
featureFlags: false
featureFlags: true
groupAnalytics: true
surveys: false
llmObservability: false
Expand All @@ -38,7 +38,9 @@ import FeatureFlagsLibsIntro from "../_snippets/feature-flags-libs-intro.mdx"

<FeatureFlagsLibsIntro />

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).
import ElixirFeatureFlagsCode from '../../integrate/feature-flags-code/_snippets/feature-flags-code-elixir.mdx'

<ElixirFeatureFlagsCode />

## Thanks

Expand Down
16 changes: 10 additions & 6 deletions src/components/LibraryFeatures/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ const features = [
{
key: 'autoCapture',
name: 'Autocapture',
url: 'https://posthog.com/docs/data/autocapture',
url: 'https://posthog.com/docs/product-analytics/autocapture',
},
{
key: 'userIdentification',
name: 'User identification',
url: 'https://posthog.com/docs/integrate/identifying-users',
url: 'https://posthog.com/docs/product-analytics/identify',
},
{ key: 'sessionRecording', name: 'Session replay', url: 'https://posthog.com/docs/session-replay' },
{ key: 'featureFlags', name: 'Feature flags', url: 'https://posthog.com/docs/feature-flags' },
{
key: 'groupAnalytics',
name: 'Group analytics',
url: 'https://posthog.com/docs/product-analytics/group-analytics',
},
{ key: 'sessionRecording', name: 'Session replay', url: 'https://posthog.com/docs/user-guides/recordings' },
{ key: 'featureFlags', name: 'Feature flags', url: 'https://posthog.com/docs/user-guides/feature-flags' },
{ key: 'groupAnalytics', name: 'Group analytics', url: 'https://posthog.com/docs/user-guides/group-analytics' },
{ key: 'surveys', name: 'Surveys', url: 'https://posthog.com/docs/surveys' },
{
key: 'llmObservability',
Expand All @@ -29,7 +33,7 @@ const features = [
] as const

export type LibraryFeaturesProps = {
availability?: Record<typeof features[number]['key'], boolean>
availability?: Record<(typeof features)[number]['key'], boolean>
}

export const LibraryFeatures = ({ availability }: LibraryFeaturesProps) => {
Expand Down
3 changes: 3 additions & 0 deletions src/navs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,9 @@ export const docsMenu = {
{
name: 'Elixir',
url: '/docs/libraries/elixir',
badge: {
title: '3rd party',
},
},
{
name: 'Flutter',
Expand Down
5 changes: 3 additions & 2 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
{ "source": "/docs/features/cohorts", "destination": "/docs/user-guides/cohorts" },
{ "source": "/docs/features/dashboards", "destination": "/docs/user-guides/dashboards" },
{ "source": "/docs/features/events", "destination": "/docs/user-guides/events" },
{ "source": "/docs/features/feature-flags", "destination": "/docs/user-guides/feature-flags" },
{ "source": "/docs/features/funnels", "destination": "/docs/user-guides/funnels" },
{ "source": "/docs/features/organizations", "destination": "/docs/user-guides/organizations" },
{ "source": "/docs/features/paths", "destination": "/docs/user-guides/paths" },
Expand Down Expand Up @@ -676,7 +675,9 @@
{ "source": "/docs/experiments/under-the-hood", "destination": "/docs/experiments/experiment-significance" },
{ "source": "/docs/experiments/significance", "destination": "/docs/experiments/experiment-significance" },
{ "source": "/docs/session-replay/manual", "destination": "/docs/session-replay/installation" },
{ "source": "/docs/user-guides/feature-flags", "destination": "/docs/feature-flags/manual" },
{ "source": "/docs/features/feature-flags", "destination": "/docs/feature-flags" },
{ "source": "/docs/user-guides/feature-flags", "destination": "/docs/feature-flags" },
{ "source": "/docs/feature-flags/manual", "destination": "/docs/feature-flags" },
{ "source": "/manual/group-analytics", "destination": "/docs/product-analytics/group-analytics" },
{ "source": "/docs/product-analytics/hogql", "destination": "/docs/hogql" },
{ "source": "/docs/hogql/guide", "destination": "/docs/product-analytics/sql" },
Expand Down

0 comments on commit 8976087

Please sign in to comment.