<@U07FJ89LFFB> will this work for a A/A test? &lt...
# ask-ai
w
@brash-pillow-71627 will this work for a A/A test? <script> if (growthbook.isOn("luan")) { console.log("Feature is enabled!") } </script>
o
A message from kapa.ai
Yes, the script you provided can be used for an A/A test in GrowthBook. However, it's important to note that an A/A test in GrowthBook is run just like an A/B test, but the "variations" are serving the same values. This means that all users get the same user experience, and any variation in traffic flows or Metric values can be attributed either to errors in your experiment or SDK setup, or to random chance ([source](https://docs.growthbook.io/kb/experiments/aa-tests#what-is-an-aa-test)). Here's how your script would work:
Copy code
javascript <script>   if (growthbook.isOn("luan")) {     console.log("Feature is enabled!")   } </script>
In this script,
growthbook.isOn("luan")
checks if the feature "luan" is enabled. If it is, it logs "Feature is enabled!" to the console. However, before you can use
growthbook.isOn()
, you need to initialize the GrowthBook instance and download features and experiments from the CDN. Here's an example of how to do this ([source](https://docs.growthbook.io/lib/js)):
Copy code
javascript import { GrowthBook } from "@growthbook/growthbook";    // Create a GrowthBook instance   const gb = new GrowthBook({     apiHost: "<https://cdn.growthbook.io>",     clientKey: "sdk-abc123",     // Targeting attributes     attributes: {       id: "123",       country: "US"     },     // Only required for A/B testing     // Called every time a user is put into an experiment     trackingCallback: (experiment, result) => {       console.log("Experiment Viewed", {         experimentId: experiment.key,         variationId: result.key,       });     },   });    // Download features and experiments from the CDN   // Also, start running any Visual Editor or URL Redirect experiments   await gb.init();
After initializing GrowthBook, you can use
gb.isOn("luan")
to check if the feature "luan" is enabled.
w
@brash-pillow-71627 I'm implementing Growthbook through Google Tag Manager, what else do I need to do?
o
A message from kapa.ai
To implement GrowthBook through Google Tag Manager (GTM), you need to follow these steps: 1. Create an SDK Connection within GrowthBook: Add a new SDK Connection within GrowthBook and choose the "Generic HTML" option. After creating the connection, you will be shown a script tag that contains your unique client id. Copy this script tag as you will need it for the next step ([source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook)). 2. Create a GTM tag for the GrowthBook SDK: Create a new tag in your desired GTM workspace. Choose "Custom HTML" as the tag type and give it a name like "GrowthBook SDK". Set the firing triggers to target the specific pages where you need to instrument your feature changes and experiments. Paste in the script tag from your SDK Connection in the previous step ([source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#creating-a-gtm-tag-for-the-growthbook-sdk)). 3. Use Feature Flags (Optional): If you plan to use feature flags, create another "Custom HTML" tag in your workspace, with a name like "GrowthBook Feature Flags" and set the firing trigger to the page you want to run this on ([source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#use-feature-flags)). 4. Tracking via DataLayer and GTM: The GrowthBook SDK will send an event to the DataLayer whenever the user views an experiment. This event can be forwarded on to your analytics tool of choice. The guide provides an example of sending this to Google Analytics v4 ([source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#tracking-via-datalayer-and-gtm)). 5. Publish Your Changes: Finally, publish your changes in Google Tag Manager ([source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#step-5-publish-your-changes)). 6. Viewing Results: Once your analytics tool is successfully tracking your experiment events, the next step is to connect GrowthBook to your data warehouse and view results ([source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#viewing-results)). Remember to refer to the [GrowthBook documentation](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook) for more detailed instructions and examples.
w
@brash-pillow-71627 I'm getting this error after firing Growthbook through GTM and adding the A/A test feature flag: Uncaught ReferenceError: growthbook is not defined at <anonymous>11 at gtm.js?id=GTM-KC4VJK3782435 at b (gtm.js?id=GTM-KC4VJK378494) at yf (gtm.js?id=GTM-KC4VJK320578) at e (gtm.js?id=GTM-KC4VJK3536214) at gtm.js?id=GTM-KC4VJK3137125 at Array.<anonymous> (gtm.js?id=GTM-KC4VJK3537401) at Object.execute (gtm.js?id=GTM-KC4VJK3537141) at yx (gtm.js?id=GTM-KC4VJK3537847) at Dx (gtm.js?id=GTM-KC4VJK3542206)
o
A message from kapa.ai
The error message "Uncaught ReferenceError: growthbook is not defined" suggests that the GrowthBook instance is not properly initialized before you're trying to use it. This could be due to the order of your scripts in Google Tag Manager (GTM), or it could be that the GrowthBook SDK script is not properly loaded. Here are a few things you can check: 1. Check the order of your tags in GTM: Make sure the tag that initializes the GrowthBook instance (the "GrowthBook SDK" tag) is firing before the tag that uses the
growthbook
object (the "GrowthBook Feature Flags" tag). You can check the order of tag firing in GTM's preview mode. 2. Check the GrowthBook SDK script: Make sure the script that loads the GrowthBook SDK is correct and is being loaded properly. The script should look something like this:
Copy code
html <script id="growthbook-sdk" src="https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js" defer></script>
(Source: [Forum Conversation > T > 14269052 Part 1](https://linen.growthbook.io/t/14269052/can-anyone-help-tell-me-why-i-get-this-message-in-the-growth)) 3. Check the initialization of the GrowthBook instance: Make sure you're correctly initializing the GrowthBook instance. The initialization should look something like this:
Copy code
javascript var gb = new growthbook.GrowthBook({   apiHost: "<https://cdn.growthbook.io>",   enableDevMode: true,   clientKey: "sdk-XXXXXXXXXXXXXXXX",   attributes: {     id: cid   },   trackingCallback: function(experiment, result) {     // tracking code here   } });
(Source: [Forum Conversation > T > 14269052 Part 1](https://linen.growthbook.io/t/14269052/can-anyone-help-tell-me-why-i-get-this-message-in-the-growth)) If you've checked all of these and you're still seeing the error, it might be helpful to share more details about your GTM setup and the exact scripts you're using.