client

package
v1.8.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package client has client definitions

Package client has client facing factories

Package client //

Package client //

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OptimizelyClient

type OptimizelyClient struct {
	ConfigManager   config.ProjectConfigManager
	DecisionService decision.Service
	EventProcessor  event.Processor
	// contains filtered or unexported fields
}

OptimizelyClient is the entry point to the Optimizely SDK

func (*OptimizelyClient) Activate

func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.UserContext) (result string, err error)

Activate returns the key of the variation the user is bucketed into and queues up an impression event to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) Close

func (o *OptimizelyClient) Close()

Close closes the Optimizely instance and stops any ongoing tasks from its children components.

func (*OptimizelyClient) CreateUserContext

func (o *OptimizelyClient) CreateUserContext(userID string, attributes map[string]interface{}) OptimizelyUserContext

CreateUserContext creates a context of the user for which decision APIs will be called. A user context will be created successfully even when the SDK is not fully configured yet.

func (*OptimizelyClient) GetAllFeatureVariables

func (o *OptimizelyClient) GetAllFeatureVariables(featureKey string, userContext entities.UserContext) (optlyJSON *optimizelyjson.OptimizelyJSON, err error)

GetAllFeatureVariables returns all the variables as OptimizelyJSON object for a given feature.

func (*OptimizelyClient) GetAllFeatureVariablesWithDecision

func (o *OptimizelyClient) GetAllFeatureVariablesWithDecision(featureKey string, userContext entities.UserContext) (enabled bool, variableMap map[string]interface{}, err error)

GetAllFeatureVariablesWithDecision returns all the variables for a given feature along with the enabled state.

func (*OptimizelyClient) GetDetailedFeatureDecisionUnsafe

func (o *OptimizelyClient) GetDetailedFeatureDecisionUnsafe(featureKey string, userContext entities.UserContext, disableTracking bool) (decisionInfo decision.UnsafeFeatureDecisionInfo, err error)

GetDetailedFeatureDecisionUnsafe triggers an impression event and returns all the variables for a given feature along with the experiment key, variation key and the enabled state. Usage of this method is unsafe and not recommended since it can be removed in any of the next releases.

func (*OptimizelyClient) GetEnabledFeatures

func (o *OptimizelyClient) GetEnabledFeatures(userContext entities.UserContext) (enabledFeatures []string, err error)

GetEnabledFeatures returns an array containing the keys of all features in the project that are enabled for the given user. For features tests, impression events will be queued up to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) GetFeatureVariable

func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, userContext entities.UserContext) (string, entities.VariableType, error)

GetFeatureVariable returns feature variable as a string along with it's associated type.

func (*OptimizelyClient) GetFeatureVariableBoolean

func (o *OptimizelyClient) GetFeatureVariableBoolean(featureKey, variableKey string, userContext entities.UserContext) (convertedValue bool, err error)

GetFeatureVariableBoolean returns the feature variable value of type bool associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableDouble

func (o *OptimizelyClient) GetFeatureVariableDouble(featureKey, variableKey string, userContext entities.UserContext) (convertedValue float64, err error)

GetFeatureVariableDouble returns the feature variable value of type double associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableInteger

func (o *OptimizelyClient) GetFeatureVariableInteger(featureKey, variableKey string, userContext entities.UserContext) (convertedValue int, err error)

GetFeatureVariableInteger returns the feature variable value of type int associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableJSON

func (o *OptimizelyClient) GetFeatureVariableJSON(featureKey, variableKey string, userContext entities.UserContext) (optlyJSON *optimizelyjson.OptimizelyJSON, err error)

GetFeatureVariableJSON returns the feature variable value of type json associated with the given feature and variable keys.

func (*OptimizelyClient) GetFeatureVariableString

func (o *OptimizelyClient) GetFeatureVariableString(featureKey, variableKey string, userContext entities.UserContext) (stringValue string, err error)

GetFeatureVariableString returns the feature variable value of type string associated with the given feature and variable keys.

func (*OptimizelyClient) GetOptimizelyConfig

func (o *OptimizelyClient) GetOptimizelyConfig() (optimizelyConfig *config.OptimizelyConfig)

GetOptimizelyConfig returns OptimizelyConfig object

func (*OptimizelyClient) GetVariation

func (o *OptimizelyClient) GetVariation(experimentKey string, userContext entities.UserContext) (result string, err error)

GetVariation returns the key of the variation the user is bucketed into. Does not generate impression events.

func (*OptimizelyClient) IsFeatureEnabled

func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entities.UserContext) (result bool, err error)

IsFeatureEnabled returns true if the feature is enabled for the given user. If the user is part of a feature test then an impression event will be queued up to be sent to the Optimizely log endpoint for results processing.

func (*OptimizelyClient) OnTrack

func (o *OptimizelyClient) OnTrack(callback func(eventKey string, userContext entities.UserContext, eventTags map[string]interface{}, conversionEvent event.ConversionEvent)) (int, error)

OnTrack registers a handler for Track notifications

func (*OptimizelyClient) RemoveOnTrack

func (o *OptimizelyClient) RemoveOnTrack(id int) error

RemoveOnTrack removes handler for Track notification with given id

func (*OptimizelyClient) Track

func (o *OptimizelyClient) Track(eventKey string, userContext entities.UserContext, eventTags map[string]interface{}) (err error)

Track generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely log endpoint for results processing.

type OptimizelyDecision

type OptimizelyDecision struct {
	VariationKey string                         `json:"variationKey"`
	Enabled      bool                           `json:"enabled"`
	Variables    *optimizelyjson.OptimizelyJSON `json:"-"`
	RuleKey      string                         `json:"ruleKey"`
	FlagKey      string                         `json:"flagKey"`
	UserContext  OptimizelyUserContext          `json:"userContext"`
	Reasons      []string                       `json:"reasons"`
	Experiment   entities.Experiment            `json:"experiment"`
}

OptimizelyDecision defines the decision returned by decide api.

func NewErrorDecision

func NewErrorDecision(key string, user OptimizelyUserContext, err error) OptimizelyDecision

NewErrorDecision returns a decision with error

func NewOptimizelyDecision

func NewOptimizelyDecision(variationKey, ruleKey, flagKey string, enabled bool, variables *optimizelyjson.OptimizelyJSON, userContext OptimizelyUserContext, reasons []string, experiment entities.Experiment) OptimizelyDecision

NewOptimizelyDecision creates and returns a new instance of OptimizelyDecision

type OptimizelyFactory

type OptimizelyFactory struct {
	SDKKey              string
	Datafile            []byte
	DatafileAccessToken string
	// contains filtered or unexported fields
}

OptimizelyFactory is used to customize and construct an instance of the OptimizelyClient.

func (*OptimizelyFactory) Client

func (f *OptimizelyFactory) Client(clientOptions ...OptionFunc) (*OptimizelyClient, error)

Client instantiates a new OptimizelyClient with the given options.

func (*OptimizelyFactory) StaticClient

func (f *OptimizelyFactory) StaticClient(clientOptions ...OptionFunc) (optlyClient *OptimizelyClient, err error)

StaticClient returns a client initialized with a static project config.

type OptimizelyUserContext

type OptimizelyUserContext struct {
	UserID     string                 `json:"userId"`
	Attributes map[string]interface{} `json:"attributes"`
	// contains filtered or unexported fields
}

OptimizelyUserContext defines user contexts that the SDK will use to make decisions for.

func (*OptimizelyUserContext) Decide

Decide returns a decision result for a given flag key and a user context, which contains all data required to deliver the flag or experiment.

func (*OptimizelyUserContext) DecideAll

DecideAll returns a key-map of decision results for all active flag keys with options.

func (*OptimizelyUserContext) DecideForKeys

func (o *OptimizelyUserContext) DecideForKeys(keys []string, options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision

DecideForKeys returns a key-map of decision results for multiple flag keys and options.

func (*OptimizelyUserContext) GetForcedDecision

GetForcedDecision returns the forced decision for a given flag and an optional rule

func (OptimizelyUserContext) GetOptimizely

func (o OptimizelyUserContext) GetOptimizely() *OptimizelyClient

GetOptimizely returns optimizely client instance for Optimizely user context

func (OptimizelyUserContext) GetUserAttributes

func (o OptimizelyUserContext) GetUserAttributes() map[string]interface{}

GetUserAttributes returns user attributes for Optimizely user context

func (OptimizelyUserContext) GetUserID

func (o OptimizelyUserContext) GetUserID() string

GetUserID returns userID for Optimizely user context

func (*OptimizelyUserContext) RemoveAllForcedDecisions

func (o *OptimizelyUserContext) RemoveAllForcedDecisions() bool

RemoveAllForcedDecisions removes all forced decisions bound to this user context.

func (*OptimizelyUserContext) RemoveForcedDecision

func (o *OptimizelyUserContext) RemoveForcedDecision(context pkgDecision.OptimizelyDecisionContext) bool

RemoveForcedDecision removes the forced decision for a given flag and an optional rule.

func (*OptimizelyUserContext) SetAttribute

func (o *OptimizelyUserContext) SetAttribute(key string, value interface{})

SetAttribute sets an attribute for a given key.

func (*OptimizelyUserContext) SetForcedDecision

SetForcedDecision sets the forced decision (variation key) for a given decision context (flag key and optional rule key). returns true if the forced decision has been set successfully.

func (*OptimizelyUserContext) TrackEvent

func (o *OptimizelyUserContext) TrackEvent(eventKey string, eventTags map[string]interface{}) (err error)

TrackEvent generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely log endpoint for results processing.

type OptionFunc

type OptionFunc func(*OptimizelyFactory)

OptionFunc is used to provide custom client configuration to the OptimizelyFactory.

func WithBatchEventProcessor

func WithBatchEventProcessor(batchSize, queueSize int, flushInterval time.Duration) OptionFunc

WithBatchEventProcessor sets event processor on a client.

func WithConfigManager

func WithConfigManager(configManager config.ProjectConfigManager) OptionFunc

WithConfigManager sets polling config manager on a client.

func WithContext

func WithContext(ctx context.Context) OptionFunc

WithContext allows user to pass in their own context to override the default one in the client.

func WithDatafileAccessToken

func WithDatafileAccessToken(datafileAccessToken string) OptionFunc

WithDatafileAccessToken sets authenticated datafile token

func WithDecisionService

func WithDecisionService(decisionService decision.Service) OptionFunc

WithDecisionService sets decision service on a client.

func WithDefaultDecideOptions

func WithDefaultDecideOptions(decideOptions []decide.OptimizelyDecideOptions) OptionFunc

WithDefaultDecideOptions sets default decide options on a client.

func WithEventDispatcher

func WithEventDispatcher(eventDispatcher event.Dispatcher) OptionFunc

WithEventDispatcher sets event dispatcher on the factory.

func WithEventProcessor

func WithEventProcessor(eventProcessor event.Processor) OptionFunc

WithEventProcessor sets event processor on a client

func WithExperimentOverrides

func WithExperimentOverrides(overrideStore decision.ExperimentOverrideStore) OptionFunc

WithExperimentOverrides sets the experiment override store on the decision service.

func WithMetricsRegistry

func WithMetricsRegistry(metricsRegistry metrics.Registry) OptionFunc

WithMetricsRegistry allows user to pass in their own implementation of a metrics collector

func WithPollingConfigManager

func WithPollingConfigManager(pollingInterval time.Duration, initDataFile []byte) OptionFunc

WithPollingConfigManager sets polling config manager on a client.

func WithPollingConfigManagerDatafileAccessToken

func WithPollingConfigManagerDatafileAccessToken(pollingInterval time.Duration, initDataFile []byte, datafileAccessToken string) OptionFunc

WithPollingConfigManagerDatafileAccessToken sets polling config manager with auth datafile token on a client

func WithUserProfileService

func WithUserProfileService(userProfileService decision.UserProfileService) OptionFunc

WithUserProfileService sets the user profile service on the decision service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL