Documentation
¶
Overview ¶
Package client has client definitions
Package client has client facing factories ¶
Package client //
Package client //
Index ¶
- type OptimizelyClient
- func (o *OptimizelyClient) Activate(experimentKey string, userContext entities.UserContext) (result string, err error)
- func (o *OptimizelyClient) Close()
- func (o *OptimizelyClient) CreateUserContext(userID string, attributes map[string]interface{}) OptimizelyUserContext
- func (o *OptimizelyClient) GetAllFeatureVariables(featureKey string, userContext entities.UserContext) (optlyJSON *optimizelyjson.OptimizelyJSON, err error)
- func (o *OptimizelyClient) GetAllFeatureVariablesWithDecision(featureKey string, userContext entities.UserContext) (enabled bool, variableMap map[string]interface{}, err error)
- func (o *OptimizelyClient) GetDetailedFeatureDecisionUnsafe(featureKey string, userContext entities.UserContext, disableTracking bool) (decisionInfo decision.UnsafeFeatureDecisionInfo, err error)
- func (o *OptimizelyClient) GetEnabledFeatures(userContext entities.UserContext) (enabledFeatures []string, err error)
- func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, userContext entities.UserContext) (string, entities.VariableType, error)
- func (o *OptimizelyClient) GetFeatureVariableBoolean(featureKey, variableKey string, userContext entities.UserContext) (convertedValue bool, err error)
- func (o *OptimizelyClient) GetFeatureVariableDouble(featureKey, variableKey string, userContext entities.UserContext) (convertedValue float64, err error)
- func (o *OptimizelyClient) GetFeatureVariableInteger(featureKey, variableKey string, userContext entities.UserContext) (convertedValue int, err error)
- func (o *OptimizelyClient) GetFeatureVariableJSON(featureKey, variableKey string, userContext entities.UserContext) (optlyJSON *optimizelyjson.OptimizelyJSON, err error)
- func (o *OptimizelyClient) GetFeatureVariableString(featureKey, variableKey string, userContext entities.UserContext) (stringValue string, err error)
- func (o *OptimizelyClient) GetOptimizelyConfig() (optimizelyConfig *config.OptimizelyConfig)
- func (o *OptimizelyClient) GetVariation(experimentKey string, userContext entities.UserContext) (result string, err error)
- func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entities.UserContext) (result bool, err error)
- func (o *OptimizelyClient) OnTrack(callback func(eventKey string, userContext entities.UserContext, ...)) (int, error)
- func (o *OptimizelyClient) RemoveOnTrack(id int) error
- func (o *OptimizelyClient) Track(eventKey string, userContext entities.UserContext, ...) (err error)
- type OptimizelyDecision
- type OptimizelyFactory
- type OptimizelyUserContext
- func (o *OptimizelyUserContext) Decide(key string, options []decide.OptimizelyDecideOptions) OptimizelyDecision
- func (o *OptimizelyUserContext) DecideAll(options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision
- func (o *OptimizelyUserContext) DecideForKeys(keys []string, options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision
- func (o *OptimizelyUserContext) GetForcedDecision(context pkgDecision.OptimizelyDecisionContext) (pkgDecision.OptimizelyForcedDecision, error)
- func (o OptimizelyUserContext) GetOptimizely() *OptimizelyClient
- func (o OptimizelyUserContext) GetUserAttributes() map[string]interface{}
- func (o OptimizelyUserContext) GetUserID() string
- func (o *OptimizelyUserContext) RemoveAllForcedDecisions() bool
- func (o *OptimizelyUserContext) RemoveForcedDecision(context pkgDecision.OptimizelyDecisionContext) bool
- func (o *OptimizelyUserContext) SetAttribute(key string, value interface{})
- func (o *OptimizelyUserContext) SetForcedDecision(context pkgDecision.OptimizelyDecisionContext, ...) bool
- func (o *OptimizelyUserContext) TrackEvent(eventKey string, eventTags map[string]interface{}) (err error)
- type OptionFunc
- func WithBatchEventProcessor(batchSize, queueSize int, flushInterval time.Duration) OptionFunc
- func WithConfigManager(configManager config.ProjectConfigManager) OptionFunc
- func WithContext(ctx context.Context) OptionFunc
- func WithDatafileAccessToken(datafileAccessToken string) OptionFunc
- func WithDecisionService(decisionService decision.Service) OptionFunc
- func WithDefaultDecideOptions(decideOptions []decide.OptimizelyDecideOptions) OptionFunc
- func WithEventDispatcher(eventDispatcher event.Dispatcher) OptionFunc
- func WithEventProcessor(eventProcessor event.Processor) OptionFunc
- func WithExperimentOverrides(overrideStore decision.ExperimentOverrideStore) OptionFunc
- func WithMetricsRegistry(metricsRegistry metrics.Registry) OptionFunc
- func WithPollingConfigManager(pollingInterval time.Duration, initDataFile []byte) OptionFunc
- func WithPollingConfigManagerDatafileAccessToken(pollingInterval time.Duration, initDataFile []byte, datafileAccessToken string) OptionFunc
- func WithUserProfileService(userProfileService decision.UserProfileService) OptionFunc
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 ¶ added in v1.6.0
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 ¶ added in v1.3.0
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 ¶ added in v1.3.0
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 ¶ added in v1.3.0
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 ¶ added in v1.6.0
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"` }
OptimizelyDecision defines the decision returned by decide api.
func NewErrorDecision ¶ added in v1.6.0
func NewErrorDecision(key string, user OptimizelyUserContext, err error) OptimizelyDecision
NewErrorDecision returns a decision with error
func NewOptimizelyDecision ¶ added in v1.6.0
func NewOptimizelyDecision(variationKey, ruleKey, flagKey string, enabled bool, variables *optimizelyjson.OptimizelyJSON, userContext OptimizelyUserContext, reasons []string) 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() (optlyClient *OptimizelyClient, err error)
StaticClient returns a client initialized with a static project config.
type OptimizelyUserContext ¶ added in v1.6.0
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 ¶ added in v1.6.0
func (o *OptimizelyUserContext) Decide(key string, options []decide.OptimizelyDecideOptions) OptimizelyDecision
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 ¶ added in v1.6.0
func (o *OptimizelyUserContext) DecideAll(options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision
DecideAll returns a key-map of decision results for all active flag keys with options.
func (*OptimizelyUserContext) DecideForKeys ¶ added in v1.6.0
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 ¶ added in v1.8.0
func (o *OptimizelyUserContext) GetForcedDecision(context pkgDecision.OptimizelyDecisionContext) (pkgDecision.OptimizelyForcedDecision, error)
GetForcedDecision returns the forced decision for a given flag and an optional rule
func (OptimizelyUserContext) GetOptimizely ¶ added in v1.6.0
func (o OptimizelyUserContext) GetOptimizely() *OptimizelyClient
GetOptimizely returns optimizely client instance for Optimizely user context
func (OptimizelyUserContext) GetUserAttributes ¶ added in v1.6.0
func (o OptimizelyUserContext) GetUserAttributes() map[string]interface{}
GetUserAttributes returns user attributes for Optimizely user context
func (OptimizelyUserContext) GetUserID ¶ added in v1.6.0
func (o OptimizelyUserContext) GetUserID() string
GetUserID returns userID for Optimizely user context
func (*OptimizelyUserContext) RemoveAllForcedDecisions ¶ added in v1.8.0
func (o *OptimizelyUserContext) RemoveAllForcedDecisions() bool
RemoveAllForcedDecisions removes all forced decisions bound to this user context.
func (*OptimizelyUserContext) RemoveForcedDecision ¶ added in v1.8.0
func (o *OptimizelyUserContext) RemoveForcedDecision(context pkgDecision.OptimizelyDecisionContext) bool
RemoveForcedDecision removes the forced decision for a given flag and an optional rule.
func (*OptimizelyUserContext) SetAttribute ¶ added in v1.6.0
func (o *OptimizelyUserContext) SetAttribute(key string, value interface{})
SetAttribute sets an attribute for a given key.
func (*OptimizelyUserContext) SetForcedDecision ¶ added in v1.8.0
func (o *OptimizelyUserContext) SetForcedDecision(context pkgDecision.OptimizelyDecisionContext, decision pkgDecision.OptimizelyForcedDecision) bool
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 ¶ added in v1.6.0
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 ¶ added in v1.3.0
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 ¶ added in v1.6.0
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 ¶ added in v1.3.0
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.