https://www.growthbook.io/ logo
w

wonderful-branch-2202

03/06/2023, 11:56 PM
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

fresh-football-47124

03/07/2023, 3:09 AM
Hi Shruti - can. you share the code you’re stuck with?
w

wonderful-branch-2202

03/07/2023, 3:27 AM
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

fresh-football-47124

03/07/2023, 3:28 AM
what is the singleton?
w

wonderful-branch-2202

03/07/2023, 3:28 AM
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

fresh-football-47124

03/07/2023, 3:29 AM
well, in the first snippet, chat.EnableGenderQuestion = false is both.. is that right?
w

wonderful-branch-2202

03/07/2023, 3:30 AM
Oh yes, but the feature itself is always falling into else code
f

fresh-football-47124

03/07/2023, 3:31 AM
where are you setting the attributes?
w

wonderful-branch-2202

03/07/2023, 3:31 AM
I am little lost now, is that target attributes? I am setting those on the growthbook ui
f

fresh-football-47124

03/07/2023, 3:33 AM
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

wonderful-branch-2202

03/07/2023, 3:36 AM
So with setting these attributes the toggle will work fine?
Did I understand that correctly?
f

fresh-football-47124

03/07/2023, 3:37 AM
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

wonderful-branch-2202

03/07/2023, 3:38 AM
Ahh got it!
Thank you so much, this understanding will unblock me!
7 Views