Hello everyone. I am unsure how to verify that thi...
# ask-questions
r
Hello everyone. I am unsure how to verify that this is set up correctly. I am setting up an experiment via the JS SDK. My goal is for half of customers to get one experience where the class name "in-experiment" , and the other half to get another experience. how can I test to be sure that this is happening if I don't have my analytics set up yet. I'll add my code and my Growthbook Extension screenshots in a thread here
Copy code
const gb = new GrowthBook({
            apiHost: "<https://cdn.growthbook.io>",
            clientKey: "### I confirmed this is correct",
            // Enable easier debugging during development
            enableDevMode: true,
            // Update the instance in realtime as features change in GrowthBook
            subscribeToChanges: true,
            // Targeting attributes
            attributes: {
            },
            // Called every time a user is put into an experiment
            trackingCallback: (experiment, result) => {
              console.log("Experiment Viewed", {
                experimentId: experiment.key,
                variationId: result.key,
              });
            },
          });
          // Use an async function to initialize GrowthBook
          async function initializeGrowthBook() {
            // Download features and experiments from the CDN
            await gb.init();
            console.log("GrowthBook initialized");
            // the objective is to create a feature or experiment that puts customers into a 50/50 experiment where
            // half of customers will see a viewing experience enabled by the existence of the class name "in-experiment"
            // and the other half of customers see a viewing experience where "in-experiment" is not applied.
              if (gb.isOn("groove-mini-cart")) {
                const miniCartChange = gb.getFeatureValue("groove-mini-cart");
                console.log(miniCartChange, 'Create change?');
                if (miniCartChange == true) {
                    $('body').addClass('in-experiment');
                }
              }
          }
          initializeGrowthBook(); // Call the async function
          console.log(gb);
Screenshot 2024-12-20 at 10.28.55 AM.png
Screenshot 2024-12-20 at 10.29.04 AM.png
f
Hi George
In order to assign to an experiment, GrowthBook needs to assign those users based on one attribute that immutable - typically this is a user_id
I don't see in the code where you're setting an attribute - and you'll need to match the attribute you set with the one used for assignment
r
How do I do that?