wide-cartoon-5349
10/03/2024, 12:58 PMorange-terabyte-33302
10/03/2024, 12:58 PMorange-terabyte-33302
10/03/2024, 12:58 PMjavascript <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)): 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.wide-cartoon-5349
10/03/2024, 1:00 PMorange-terabyte-33302
10/03/2024, 1:00 PMorange-terabyte-33302
10/03/2024, 1:00 PMwide-cartoon-5349
10/03/2024, 1:43 PMorange-terabyte-33302
10/03/2024, 1:43 PMorange-terabyte-33302
10/03/2024, 1:44 PMgrowthbook
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: 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: 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.