View Source GrowthBook.Helpers (GrowthBook v0.3.0)

GrowthBook internal helper functions.

A collection of helper functions for use internally inside the GrowthBook library. You should not (have to) use any of these functions in your own application. They are documented for library developers only. Breaking changes in this module will not be considered breaking changes in the library's public API (or cause a minor/major semver update).

Link to this section Summary

Functions

Given a hash and bucket ranges, assign one of the bucket ranges.

Converts and experiment's coverage and variation weights into a list of bucket ranges.

Returns an list of floats with count items that are all equal and sum to 1.

Checks if an experiment variation is being forced via a URL query string.

This checks if a userId is within an experiment namespace or not.

Determines if a number n is within the provided range.

Determines if the user is part of a gradual feature rollout.

Link to this section Functions

Link to this function

choose_variation(hash, bucket_ranges)

View Source

Specs

choose_variation(float(), [GrowthBook.bucket_range()]) :: integer()

Given a hash and bucket ranges, assign one of the bucket ranges.

Specs

coalesce([any()]) :: any()

Specs

coalesce(any(), any()) :: any()
Link to this function

get_bucket_ranges(count, coverage, weights)

View Source

Specs

get_bucket_ranges(integer(), float(), [float()] | nil) :: [
  GrowthBook.bucket_range()
]

Converts and experiment's coverage and variation weights into a list of bucket ranges.

Examples

iex> GrowthBook.Helpers.get_bucket_ranges(2, 1, [0.5, 0.5])
[{0.0, 0.5}, {0.5, 1.0}]

iex> GrowthBook.Helpers.get_bucket_ranges(2, 0.5, [0.4, 0.6])
[{0.0, 0.2}, {0.4, 0.7}]
Link to this function

get_equal_weights(count)

View Source

Specs

get_equal_weights(integer()) :: [float()]

Returns an list of floats with count items that are all equal and sum to 1.

Examples

iex> GrowthBook.Helpers.get_equal_weights(2)
[0.5, 0.5]
Link to this function

get_query_string_override(experiment_id, url, count)

View Source

Specs

get_query_string_override(String.t(), String.t(), integer()) :: integer() | nil

Checks if an experiment variation is being forced via a URL query string.

Examples

iex> GrowthBook.Helpers.get_query_string_override("my-test", "http://localhost/?my-test=1", 2)
1

iex> GrowthBook.Helpers.get_query_string_override("my-test", "not valid", 2)
nil
Link to this function

in_namespace?(user_id, arg2)

View Source

Specs

in_namespace?(String.t(), GrowthBook.namespace() | nil) :: boolean()

This checks if a userId is within an experiment namespace or not.

Specs

in_range?(number(), GrowthBook.BucketRange.t()) :: boolean()

Determines if a number n is within the provided range.

Link to this function

included_in_rollout?(attributes, seed, hash_attribute, range, coverage, hash_version)

View Source

Specs

included_in_rollout?(
  map(),
  String.t(),
  String.t(),
  GrowthBook.BucketRange.t(),
  number(),
  integer()
) :: boolean()

Determines if the user is part of a gradual feature rollout.