Hello, I have a problem with instantiating the gro...
# announcements
w
Hello, I have a problem with instantiating the growthbook variable for A/B experimentation. I have created a singleton object to overcome the error of it being initialised everytime the experiment is being conducted. Now the information is altogether not showing up. @fresh-football-47124 can you please help me with the resolution? Been stuck at this point since long!
The toggling of the feature flag in experimentation is getting hard to achieve in the backend, is there any set up/ working example which I can refer to?
f
Hi Shruti - can. you share the code you’re stuck with?
w
Copy code
// Perform feature test.
Copy code
if gb.growthbook.Feature("enableskipquestion").On {
        chat.EnableGenderQuestion = false
        <http://log.Info|log.Info>().Msg("Mandatory skip feature off")
    } else {
        chat.EnableGenderQuestion = false
        <http://log.Info|log.Info>().Msg("Mandatory skip feature defaulted")
    }
f
what is the singleton?
w
The toggling is a little difficult to with the value. Everytime the experiment evaluates as false, here is the code snippet for one time initialisation
Copy code
<http://abTestConfigOnce.Do|abTestConfigOnce.Do>(func() {
		data := []byte(`{
			"enableskipquestion": {
			  "defaultValue": true
			}
			"enablegenderquestion": {
				"defaultValue": true
			}
		  }`)

		features := growthbook.ParseFeatureMap(data)

		// Create context and main GrowthBook object.

		context := growthbook.NewContext().WithFeatures(features)
		gb := growthbook.New(context)
		abTestConfigInstance = &AbTestConfig{data: data, growthbook: gb}

		<http://log.Info|log.Info>().Interface("abTestConfigInstance", abTestConfigInstance).Msg("Sourceservice: abTestConfigInstance")

	})
f
well, in the first snippet, chat.EnableGenderQuestion = false is both.. is that right?
w
Oh yes, but the feature itself is always falling into else code
f
where are you setting the attributes?
w
I am little lost now, is that target attributes? I am setting those on the growthbook ui
f
you set targeting attributes in the UI, but the SDK needs to know what the attribute values for each visitor are. Those are passed in with the setAttributes method (depending on the SDK language)
w
So with setting these attributes the toggle will work fine?
Did I understand that correctly?
f
yes
when you set up the experiment, you say what you want to split by (randomization unit)
if the SDK doesn’t have that attribute
it will default to off
w
Ahh got it!
Thank you so much, this understanding will unblock me!