Skip to main content
This SDK follows the guidelines set out in GrowthBook’s documentation, and the API is tested on conformance with the test cases from the JS SDK. To ensure an Elixir-friendly API, the implementation deviates from the official SDK in the following ways:
  • Instead of tuple-lists, this library uses actual tuples
  • Comparisons with undefined are implemented by using :undefined
  • Function names are converted to snake_case, and is_ prefix is replaced with a ? suffix
  • Instead of classes, a Context struct is used (similar to %Plug.Conn{} in plug)

Installation

Add growthbook to your list of dependencies in mix.exs:

Quick Start

Get started with GrowthBook in just a few steps:
That’s it! GrowthBook will automatically fetch and refresh your features in the background.

Automatic Features Refresh

The Elixir SDK provides a GenServer-based feature repository that automatically fetches and caches features from the GrowthBook API.

Initialization Options

Refresh Strategies

The SDK supports two refresh strategies:

Periodic Refresh (Default)

Features are automatically refreshed in the background based on the TTL:

Manual Refresh

Features are only refreshed when explicitly requested:

Supervision Tree Integration

For production applications, add the FeatureRepository to your application’s supervision tree:

Graceful Shutdown

When your application shuts down, stop the FeatureRepository GenServer:

Encryption & Security

The Elixir SDK supports encrypted feature payloads and secure attribute hashing to protect sensitive data.

Encrypted Features

Encrypted features ensure that sensitive feature configurations are never exposed in plain text:
Setup Steps:
  1. Enable “Encrypt SDK Payload” in your SDK Connection settings
  2. Copy the encryption key from your SDK Connection
  3. Store it securely in environment variables
  4. Pass it to GrowthBook.init/1

Secure Attributes

When secure attribute hashing is enabled, you can safely target users based on sensitive attributes like email or phone numbers without exposing the actual values.

Setup

Enable secure attribute hashing in your SDK Connection, then hash sensitive attributes before passing them to GrowthBook:

Usage

Security Best Practices

Recommendations:
  • Never commit encryption keys or salts to version control
  • Use different keys for each environment (dev, staging, production)
  • Rotate keys regularly and coordinate updates across all systems
  • Monitor decryption failures which may indicate key rotation issues
  • Use secrets management tools like Vault, AWS Secrets Manager, or similar

Using Features

Once GrowthBook is initialized, you can evaluate features and run experiments.

Feature Evaluation

Feature Result Properties

The GrowthBook.feature/2 function returns a result with these properties:

Running Inline Experiments

You can run experiments directly without defining them as features:

Experiment Configuration

The Experiment struct supports these properties:

Experiment Result

The experiment result contains detailed information:

Tracking Experiments

The SDK doesn’t include built-in tracking callbacks, but you can implement tracking by checking experiment results:

User Attributes

Attributes are used for targeting and experiment assignment:
Best Practices:
  • Use consistent naming conventions (snake_case or camelCase)
  • Keep attribute values simple and serializable
  • Document custom attributes for your team
  • Consider attribute cardinality for targeting efficiency

Context Struct

The GrowthBook.Context struct is the core data structure:
You can create contexts manually or use the helper function:

Error Handling

The SDK is designed to fail gracefully:

Troubleshooting & Logging

Common Issues

Features Not Loading

If features aren’t loading, check the following:

Decryption Failures

If encrypted features fail to decrypt:

Network Issues

For network connectivity problems:

Logging Configuration

Enable detailed logging to debug issues:

Debug Helper Module

Create a helper module for debugging GrowthBook:

Health Checks

Implement health checks for monitoring:

Integrations

The Elixir SDK integrates seamlessly with popular Elixir frameworks and libraries.

Phoenix Web Application

Integrate GrowthBook with Phoenix for feature flags in your web application:

Phoenix LiveView

Use GrowthBook with Phoenix LiveView for real-time feature flag updates:

View Helpers

Create view helpers for easy feature flag usage in templates:

Supported Features