https://www.growthbook.io/ logo
#ask-questions
Title
# ask-questions
a

adorable-solstice-28735

07/14/2023, 5:50 PM
and one more question, Graham mentioned that for inline experiments, I can dynamically set the url attribute and target the experiment (I am using react) However, after setting the attribute, I can't find any info how to check for the url/path. do I have to manually parse the gb object context, and execute the experiment if the url = /somepath ? Or is there a built-in function I can use to check the paths?
f

fresh-football-47124

07/17/2023, 1:44 AM
GrowthBook has several ways to match rules, for URLs, you can use regex for path matching
a

adorable-solstice-28735

07/17/2023, 3:27 PM
can you point me to the docs where I can find about inline matching rules?
I see this for UI Editor: https://docs.growthbook.io/app/visual#url-targeting but I am running an inline experiment from the React
This is my hook example:
Copy code
useEffect(() => {

      // Load all experiments and variants
      gb.loadFeatures({ autoRefresh: true, timeout: 2000 })

      // Set user attributes for targeting (from cookie, auth system, etc.)
      gb.setAttributes({
        id: client_id, 
        url: window.location.href
      });

      if (expConfig.running) {

        //load configured experiment
        const exp = gb.run(expConfig);

        if (exp.value === expConfig.variations[0]) { //always a control
          dispatch(bootOptimize( {enableExperiment: false }));
          console.log(`exp variant - ${expConfig.variations[0]}`);
        }
        if (exp.value === expConfig.variations[1]) {
          dispatch(bootOptimize( {enableExperiment: true }));
          console.log(`exp variant - ${expConfig.variations[1]}`);
        }

      }

  }, [])
but I can't find anything on how to properly apply the rule matching in the code
f

fresh-football-47124

07/18/2023, 2:03 AM
a

adorable-solstice-28735

07/18/2023, 2:22 AM
oh wow I totally missed that, thanks!!
9 Views