Hey, is the following script enough to run a simpl...
# ask-questions
s
Hey, is the following script enough to run a simple A/A test to confirm goals?
<script type="module">
import { GrowthBook } from "<https://unpkg.com/@growthbook/growthbook/dist/bundles/esm.min.js>";
// Define the experimental context
const growthbook = new GrowthBook({
// Called when a user is put into an experiment
trackingCallback: (experiment, result) => {
ga("send", "event", "experiment", experiment.key, result.variationId, {
// Custom dimension for easier analysis
`dimension1:
${experiment.key}::${result.variationId}
,
Copy code
});`
},
});
const { value } = growthbook.run({
"key": "aa",
"variations": ["Control", "Variation 1"],
"url": /https:\/\/speero.com\//i,
"hashAttribute": "anonId"
})
console.log(value); // "Control" or "Variation 1"
</script>
f
GrowthBook currently does not auto-generate anonIds for you, so you'll need to pass that in when creating the GrowthBook instance. You can re-use the anonymous id from Google Analytics since it looks like you are using that for tracking anyway. Something like the following should work:
Copy code
import { GrowthBook } from "<https://unpkg.com/@growthbook/growthbook/dist/bundles/esm.min.js>";
ga((tracker) => {
  // Define the experimental context
  const growthbook = new GrowthBook({
    user: {
      anonId: tracker.get('clientId')
    },
    // Called when a user is put into an experiment
    trackingCallback: (experiment, result) => {
      ga("send", "event", "experiment", experiment.key, result.variationId, {
        // Custom dimension for easier analysis
        dimension1: `${experiment.key}::${result.variationId}`,
      });
    },
  });
  const { value } = growthbook.run({
    key: "aa",
    variations: ["Control", "Variation 1"],
    url: /https:\/\/speero.com\//i,
    hashAttribute: "anonId",
  });
  console.log(value); // "Control" or "Variation 1"
})
s
thanks!! 🙏 it was confusing, I couldn't find it in the documentation