Module: Growthbook

Defined in:
lib/growthbook.rb,
lib/growthbook/util.rb,
lib/growthbook/context.rb,
lib/growthbook/feature.rb,
lib/growthbook/conditions.rb,
lib/growthbook/feature_rule.rb,
lib/growthbook/feature_result.rb,
lib/growthbook/decryption_util.rb,
lib/growthbook/payload_reducer.rb,
lib/growthbook/inline_experiment.rb,
lib/growthbook/tracking_callback.rb,
lib/growthbook/feature_repository.rb,
lib/growthbook/sticky_bucket_service.rb,
lib/growthbook/feature_usage_callback.rb,
lib/growthbook/inline_experiment_result.rb

Overview

The GrowthBook SDK

Defined Under Namespace

Classes: Conditions, Context, DecryptionUtil, Feature, FeatureRepository, FeatureResult, FeatureRule, FeatureUsageCallback, InMemoryStickyBucketService, InlineExperiment, InlineExperimentResult, PayloadReducer, StickyBucketService, TrackingCallback, Util

Class Method Summary collapse

Class Method Details

.prune_condition(attributes, condition, saved_groups = {}) ⇒ true, ...

Partially evaluate a targeting condition when only some attributes are known, e.g. on a server. Attributes missing from attributes are unknown.

Parameters:

  • attributes (Hash) —

    The known attributes

  • condition (Hash) —

    The targeting condition

  • saved_groups (Hash) (defaults to: {}) —

    The payload's saved groups

Returns:

  • (true, false, Hash) —

    true or false once the result can't depend on the unknown attributes, otherwise the condition minus every branch already decided



13
14
15
16
17
18
19
# File 'lib/growthbook.rb', line 13

def self.prune_condition(attributes, condition, saved_groups = {})
  Growthbook::Conditions.prune_condition(
    Growthbook::Conditions.parse_condition(attributes || {}),
    Growthbook::Conditions.parse_condition(condition),
    saved_groups || {}
  )
end

.reduce_payload(payload, attributes: {}, include: {}, exclude: {}, prerequisites: 'keep') ⇒ Hash

Shrink a features payload for a user whose attributes are only partly known, e.g. on a server that bootstraps a client-side SDK. The result evaluates the same as the full payload for anyone who agrees with the known attributes.

Parameters:

  • payload (Hash) —

    A decrypted features payload, as returned by the SDK API (features, experiments, savedGroups, contextualBandits)

  • attributes (Hash) (defaults to: {}) —

    The attributes known for the user

  • include (Hash) (defaults to: {}) —

    Keep only features and experiments that match every filter: projects, tags (arrays, any one value is enough) and customFields (a hash of field to array of values)

  • exclude (Hash) (defaults to: {}) —

    Drop features and experiments that match any filter, with the same keys as include

  • prerequisites ('keep', 'filter') (defaults to: 'keep') —

    With 'keep' (the default), the prerequisites of kept features and experiments are kept even when the filters drop them. With 'filter', only holdouts are.

Returns:

  • (Hash) —

    The reduced payload, with every other key of payload unchanged



34
35
36
37
38
39
40
41
42
# File 'lib/growthbook.rb', line 34

def self.reduce_payload(payload, attributes: {}, include: {}, exclude: {}, prerequisites: 'keep')
  Growthbook::PayloadReducer.new(
    Growthbook::Conditions.parse_condition(payload),
    attributes: Growthbook::Conditions.parse_condition(attributes || {}),
    include: payload_filters(include),
    exclude: payload_filters(exclude),
    prerequisites: prerequisites
  ).reduce
end