Hi all, I'm working on getting GrowthBook integra...
# ask-questions
w
Hi all, I'm working on getting GrowthBook integrated into a React Js application to get rid of our current solution. I've got the initialisation working in the
App.js
file but I have a redux reducer where I'm attempting to setAttributes on a user any time an update happens to the user within our application. I have a few questions... • Is this possible? The reason I'm doing this is we have some features which are enabled for certain groups of people. ie. internal features only enabled for users with certain emails/company information on their client data. • When i set the attributes they dont get updated on the attributes screen here https://app.growthbook.io/attributes is there something I'm doing wrong? • The Chrome plugin for Growthbook doesn't seem to be working, do I need any setup in order to get this going? • Is there somewhere that I can have a development SDK key and a production SDK key, reason being for testing tickets in a development environment with flags and then passing them through or duplicating them into prod. • I'd love to move to a paid plan but can I trial this first? Appreciate the help in advance! Here's the code I'm using in the reducer in order to try and set the client attributes.
Copy code
reducers: {
    setClientData: (state, action) => {
      console.log("Updating growthbook data with", action.payload)
      growthbook.setAttributes({
        "id": fire.auth().currentUser.uid,
        ...action.payload,
      });
      state.data = action.payload;
    },
  } ...
b
with regards to the redux question and a quick glance at your code, it looks like there may be an implementation issue with your redux reducer. in general, redux reducers are supposed to return a new state object, they're never supposed to mutate state. you can read more about it in the docs, but
state.data = action.payload
looks like where there's an issue. i'm not sure if it's the only issue, but that's one that immediately glares out. you can see the redux docs for more info: https://redux.js.org/tutorials/fundamentals/part-3-state-actions-reducers#reducers-and-immutable-updates they suggest something like this instead:
Copy code
function reducer(state, action) {
  switch (action.type) {
     case 'update_user':
       return {
         ...state,
         data: action.payload
       }
     default:
       return state
  }
}
with regards to your question about a different key for environments, yes that's supported. you go into the SDK's section under Features and create a new SDK connection. you will have the option to choose the environment for that key.
the attributes you set in the growthbook dashboard will help you with creating targeting conditions for features. when you call setAttributes in the SDK, you're providing the attributes that the SDK's will be evaluating against. the ones in the dashboard help you build the targeting conditions via the UI in the features section. so for example, if you added a targeting attribute as "country" in the dashboard, and you wanted to change some feature flag value (of string type) from the default "hello world" to "hola mundo" if the country is mexico, for all your users from mexico you'd pass
{ country: 'mexico' }
as part of the attributes when calling setAttributes, e.g.
growthbook.setAttributes({ id: 'abc-123', country: 'mexico' })
so that these values can be read by the SDK and considered when evaluating features for users. calling setAttributes in the SDK will not update the dashboard. it's used to say "this is my current user and these are the attributes they have" and their attributes will be considered when evaluating a feature. in the below screenshots i have a country user attribute i've specified in the /attributes section of the dashboard, then it shows up under the targeting conditions dropdown for me to build my targeting conditions.
w
Redux • The redux state seems to be updating fine with dev tools like this and has been for months, even the console.log right before this has all of the relevant data but because the chrome extension isn't working i can't see the data that growthbook is receiving so I can't verify whether it's happening properly. • I'm wondering mainly, do I need to call set attributes in the same file I'm loading features in or can I call the setAttributes in the redux state and then later on load features in a file and it will take the attributes I set before in redux? Or any state management for that matter. SDK Keys • Perfect that answers my question exactly thank you very much 🙂 Attributes • Ah this makes sense, so the attributes I send to growthbook will not be added to the attributes page here they'll just be evaluated against features! The chrome extension • Is there any way to get this set up so i can debug the issue myself with the attributes in redux, Im conscious nit to be wasting your time! Thank you!
Do i need to move to a paid plan for the chrome extension to work?
s
Hi @white-state-74924 The devtools extension should be available in your DevTools panel in chrome. You can open it by right clicking on an element on your page and hitting ‘Inspect Element’ … You should see a tab named ‘GrowthBook’ there
w
@swift-helmet-3648 @better-magician-65629 Thank you both very much, I've signed on to the pro account, thanks for the help setting up, much appreciated!
b
no problem, happy to help, and glad you got it working. 🙌 regarding redux state mutation, it sounds like the way you're doing it is working fine for your needs. if that changes, you may find the FAQ page about immutable data and why it's important not to mutate the state helpful: https://redux.js.org/faq/immutable-data
👍 1