Skip to content

Instantly share code, notes, and snippets.

@huantt
Created October 20, 2023 08:18
Show Gist options
  • Save huantt/68460f48e735ed018ab4bee0d85909ea to your computer and use it in GitHub Desktop.
Save huantt/68460f48e735ed018ab4bee0d85909ea to your computer and use it in GitHub Desktop.
Demo how to get experiment AB testing using growthbook.io service
package main
import (
_ "embed"
"fmt"
"github.com/growthbook/growthbook-golang"
)
func main() {
context := growthbook.NewContext()
grw := growthbook.New(context)
grw.WithTrackingCallback(func(experiment *growthbook.Experiment, result *growthbook.Result) {
})
// Get client Key in SDK Configuration (sidebar)
grw.WithClientKey("{Client Key}")
grw.LoadFeatures(&growthbook.FeatureRepoOptions{AutoRefresh: true})
for i := 0; i < 100; i++ {
grw.WithAttributeOverrides(growthbook.Attributes{
"browser": "chrome",
"deviceId": i,
})
feature := grw.EvalFeature("ui")
fmt.Println(fmt.Sprintf("User #%d using the variantion '%s'", i, feature.ExperimentResult.Name))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment