Documentation ¶
Index ¶
- func ActivatedImpression(i Impression) func(*Events) error
- func AnonymizeIP(anonymize bool) func(*Events) error
- func ClientName(name string) func(*Events) error
- func ClientVersion(version string) func(*Events) error
- func EnrichDecisions(enrich bool) func(*Events) error
- func ReportEvents(client api.Client, events Events) error
- type Datafile
- type DatafileExperiment
- type DatafileTrafficAllocation
- type DatafileVariation
- type Events
- type Experiment
- type Impression
- type Project
- type Variation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActivatedImpression ¶
func ActivatedImpression(i Impression) func(*Events) error
ActivatedImpression adds the variation impression to the set of reported events. Note that while many impressions can be added as events, each impression must have originated from the same Optimizely account or an error will be returned while creating the events.
func AnonymizeIP ¶
AnonymizeIP sets the anonymize IP flag on the events. Defaults to true.
func ClientName ¶
ClientName sets the client name property on the events. By default, the client name will be set to the path of this library, i.e. github.com/spothero/optimizely-sdk-go.
func ClientVersion ¶
ClientVersion overrides the client version of this library. If using Go 1.12+ and Go modules, the version of this library will be extracted from the build information. Otherwise, unless ClientVersion is set here, no version will be reported to Optimizely.
func EnrichDecisions ¶
EnrichDecisions sets the enrich decisions property on the events. Defaults to true.
func ReportEvents ¶
ReportEvents is a convenience wrapper for sending events to the Optimizely reporting API that marshals the events to JSON and calls the api package.
Note: The provided client does not necessarily have to be instantiated with a token as the events endpoint does not require one.
Types ¶
type Datafile ¶ added in v0.5.3
type Datafile struct { Version string `json:"version"` Revision string `json:"revision"` ProjectID string `json:"projectId"` AccountID string `json:"accountId"` Experiments []DatafileExperiment `json:"experiments"` }
Datafile used for loading the JSON datafile from Optimizely
type DatafileExperiment ¶ added in v0.5.3
type DatafileExperiment struct { ID string `json:"id"` Key string `json:"key"` LayerID string `json:"layerId"` Status string `json:"status"` Variations []DatafileVariation `json:"variations"` TrafficAllocation []DatafileTrafficAllocation `json:"trafficAllocation"` ForcedVariations map[string]string `json:"forcedVariations"` }
DatafileExperiment is the structure of the experiment within a datafile. This type is only used when deserializing the datafile.
type DatafileTrafficAllocation ¶ added in v0.5.3
type DatafileTrafficAllocation struct { EntityID string `json:"entityId"` EndOfRange int `json:"endOfRange"` }
DatafileTrafficAllocation is the structure of the traffic allocation with a datafile. This type is only used when deserializing the datafile.
type DatafileVariation ¶ added in v0.5.3
DatafileVariation is an experiment variation within a datafile used for deserialization.
type Events ¶
type Events eventBatch
Events are reportable actions back to the Optimizely API. Currently only impression events are supported.
func EventsFromContext ¶
EventsFromContext creates Events from all the impressions that were seen during the lifecycle of the provided context. If no impressions were seen or no project was found in the provided context, nil is returned. The options provided to this function match the options provided to NewEvents with the exception that the ActivatedImpression function should never be provided as an option and may result in a panic if the provided impression was created by a project in a different account from the project stored in the context.
type Experiment ¶
type Experiment struct { Key string // contains filtered or unexported fields }
Experiment represents a single Optimizely experiment. It contains metadata as well as the traffic allocation for the experiment and any forced variations.
type Impression ¶
Impression is the outcome of bucketing a user into a specific variation. This type holds the variation that the user was bucketed into, the user ID that generated the outcome, and the timestamp at which the variation was generated.
type Project ¶
type Project struct { Version string Revision string ProjectID string AccountID string RawDataFile json.RawMessage // contains filtered or unexported fields }
Project is an Optimizely project containing a set of experiments. Project also includes the raw JSON datafile which was used to generate the Project.
func NewProjectFromDataFile ¶
NewProjectFromDataFile creates a new Optimizely project given the raw JSON datafile
func (Project) GetVariation ¶
func (p Project) GetVariation(experimentName, userID string) *Impression
GetVariation returns an impression, if applicable, for a given experiment and a given user id. If no variation is applicable, nil is returned. The Impression returned by this method can be used later to generate events for reporting to the Optimizely API.
func (Project) ToContext ¶
ToContext creates a context with the project as a value in the context for a specific user ID. By using GetVariation with the context returned from this method, not only will each Impression be returned to the caller, but each Impression will be recorded in the context. Once the lifecycle of the context is complete, use EventsFromContext to create a unified Events object containing every impression that occurred during the context's lifecycle. This provides simplified API for bucketing a user across multiple experiments and multiple code-paths.