https://www.growthbook.io/ logo
#announcements
Title
# announcements
c

careful-machine-67313

07/21/2022, 3:50 PM
👋 Hi everyone! Looking to get some help with setting a forced rule on a feature. When testing, it seems like it is not being applied. Perhaps I am missing something?
f

fresh-football-47124

07/21/2022, 3:51 PM
Hi Jace - can you share a screen shot of your rule(s)?
f

future-teacher-7046

07/21/2022, 3:51 PM
Happy to help. What SDK are you using?
c

careful-machine-67313

07/21/2022, 3:51 PM
Sure one sec. I am using the ReactSDK
f

future-teacher-7046

07/21/2022, 3:52 PM
The rules look fine. It's likely an issue with how the features are loaded in your React code.
c

careful-machine-67313

07/21/2022, 3:53 PM
I just noticed something, I am keying off of id, when in our DB its user_id
Let me try updating this
Also, is ID required on the attributes?
When setting it in react?
f

future-teacher-7046

07/21/2022, 3:55 PM
You can use whatever attributes you want.
c

careful-machine-67313

07/21/2022, 3:56 PM
But does it have to match in order for GB to do the split and know which user to skip?
f

future-teacher-7046

07/21/2022, 3:56 PM
They should match up with what you are using in the rules. So based on the rules in that screenshot, you'll need an
id
attribute
c

careful-machine-67313

07/21/2022, 3:57 PM
Ok
f

future-teacher-7046

07/21/2022, 3:57 PM
Can you share the code you're using to set the features and attributes in the SDK?
c

careful-machine-67313

07/21/2022, 3:59 PM
Sure , one sec
I just added the user_id to my attribute s in the settings
That should now match the column name in the DB
f

future-teacher-7046

07/21/2022, 4:02 PM
if you do
growthbook.evalFeature("your-feature-id")
, can you see what's returned? There should be a
source
property that tells you why a specific value was assigned to the feature
c

careful-machine-67313

07/21/2022, 4:03 PM
One sec let me see what I get
"unknownFeature"
Plus side, I am now seeing the console log tracking call back
I wasnt before
f

future-teacher-7046

07/21/2022, 4:11 PM
ok,
unknownFeature
means the id you are using couldn't be found. That's either caused by a typo in your code or if you're not passing features correctly into the SDK
c

careful-machine-67313

07/21/2022, 4:15 PM
hmmm ok
so part of what I am seeing is that the api when parsing the JSON, features is not part of the object
growthbook.setFeatures(parsed.features) technically never sets
Since features is not part of the parsed object
But, I do see in my network call
f

future-teacher-7046

07/21/2022, 4:21 PM
If you are seeing that in your trackingCallback, then everything should be working fine. If you are fetching the features asynchronously, the first time React renders, the features might not be loaded yet, so it would evaluate to
null
. But when the features load, it will re-render React and it should work fine.
c

careful-machine-67313

07/21/2022, 4:22 PM
No thats not in my callboack
.then((parsed) => { console.log(parsed) growthbook.setFeatures(parsed.features) })
parsed does not have a features object
f

future-teacher-7046

07/21/2022, 4:24 PM
Are you sure? I think the screenshot of the console.log above is coming from a different part of the code
c

careful-machine-67313

07/21/2022, 4:36 PM
in the docs , this is wrong IMO =>
Copy code
.then((parsed) => {
    growthbook.setFeatures(parsed.features);
  });
This actually produces the right response on the eval
Copy code
let r = await fetch(`<https://cdn.growthbook.io/api/features/${gbkey}>`)
				.then((res) => res.json())
				
				growthbook.setFeatures(r.features)
Chaining the responses was not producing the correct eval object in the console log
f

future-teacher-7046

07/21/2022, 4:41 PM
chaining should work fine. You might just need to add
await
in front of the fetch call if you want to evaluate the features immediately.
Copy code
await fetch(`<https://cdn.growthbook.io/api/features/${gbkey}>`)
  .then((res) => res.json())
  .then((parsed) => {
    growthbook.setFeatures(parsed.features);
  })
otherwise, the features will load asynchronously and the features will evaluate to
null
until they fully load. Adding
await
before the fetch will fix that
c

careful-machine-67313

07/21/2022, 4:51 PM
I see ok. Let try that then.
Well I got a little further, I am now facing where further into the app, using the useFeature hook, still gets the "unknownFeature"
Is there way to check if the GB provider is passing the data into my component tree?
NM , I answered that Q
However, I am in the React component dev tool, seeing that the GB provider is showing my feature as "null" , I assume that is not right?
f

future-teacher-7046

07/21/2022, 5:48 PM
it's probably a race condition. If you are setting features inside of a useEffect hook, then the very first render of your application won't have any features defined yet and they will all be
null
. After the useEffect hook finishes, it will populate the features and re-render your application with the correct feature values
Usually not a big deal since all of that happens in milliseconds
c

careful-machine-67313

07/21/2022, 5:51 PM
I see. hmmm ok. Will have to review the app flow then. Thanks for the help and fast responses BTW, just under the gun today to get this working 😉
Do types matter? So for example, my api returns the id of a user as an INT, but the attribute in GrowthBook is set to a STRING in the settings.
Do the types need to match?
Or is that only for when GrowthBook gets the data from the DB ?
f

future-teacher-7046

07/21/2022, 6:27 PM
Javascript is usually pretty lenient with types, but it's better to have them match if you can
c

careful-machine-67313

07/21/2022, 6:32 PM
Ok and I got it working now. And yeah, side note, II found that the attribute type should match the value type you are providing.
Again thanks for the patience and help. Truly appreciate it!
23 Views