Coder Social home page Coder Social logo

growthbook-elixir's Introduction

GrowthBook

Online documentation | Hex.pm

NOTE: This library is in active development, and the API may change.

GrowthBook is a GrowthBook SDK for Elixir/OTP.

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)
  • There may be some discrepancies between handling of Truthy values between the JS and Elixir SDKs (if you notice this, a issue, or better, a PR is welcome)

What is GrowthBook?

GrowthBook is an open source A/B testing platform. The platform works significantly different from other A/B testing platforms, most notably: it is language agnostic.

Clients by default work offline, and manage their own data. This means that you are free to implement A/B tests server-side, or client-side without worrying about things like "anti-flicker" scripts, or the added latency of JS embeds.

Furthermore, GrowthBook supports both experiments (A/B tests and multivariate tests) and feature flags. Because all logic to run experiments and feature flags is contained in the library, there is virtually no added latency to running experiments or using feature flags.

Usage

# Create a context, which can be reused for multiple users
config = Jason.decode!("""
{
  "overrides": {
    "checkout-v2": {
      "status": "running",
      "coverage": 1,
      "weights": [0.5, 0.5],
      "force": 0
    }
  }
}
""")

features_config = Jason.decode!("""
{
  "features": {
    "send-reminder": {
      "defaultValue": false,
      "rules": [{ "condition": { "browser": "chrome" }, "force": true }]
    },
    "add-to-cart-btn-color": {
      "rules": [{ "variations": [{ "color": "red" }, { "color": "green" }] }]
    }
  }
}
""")

overrides = GrowthBook.Config.experiment_overrides_from_config(config)
features = GrowthBook.Config.features_from_config(features_config)

context = %GrowthBook.Context{
  enabled?: true,
  features: features,
  overrides: overrides,
  attributes: %{
    "id" => "12345",
    "country_code" => "NL",
    "browser" => "chrome"
  }
}

# Use a feature toggle
if GrowthBook.feature(context, "send-reminder").on? do
  Logger.info("Sending reminder")
end

# Use a feature's value
color = GrowthBook.feature(context, "add-to-cart-btn-color").value["color"]
Logger.info("Color: " <> color)

# Run an inline experiment
if GrowthBook.run(context, %GrowthBook.Experiment{
  key: "checkout-v2",
  coverage: 1,
  variations: [1, 2]
}).in_experiment? do
  Logger.info("In experiment")
end

Installation

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

def deps do
  [
    {:growthbook, "~> 0.1"}
  ]
end

License

This library is MIT licensed. See the LICENSE file in this repository for details.

growthbook-elixir's People

Contributors

jeroenvisser101 avatar

Stargazers

Mladen Jokanovic avatar Jared Dellitt avatar Jordan Brauer avatar Darwin Christopher Tantuco avatar Graham McNicoll avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.