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

shy-butcher-30505

09/21/2021, 1:35 PM
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

future-teacher-7046

09/21/2021, 1:56 PM
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

shy-butcher-30505

09/22/2021, 8:44 AM
thanks!! 🙏 it was confusing, I couldn't find it in the documentation
9 Views