wide-cartoon-5349
10/17/2024, 4:24 PMorange-terabyte-33302
10/17/2024, 4:24 PMorange-terabyte-33302
10/17/2024, 4:25 PMwide-cartoon-5349
10/21/2024, 4:39 PMorange-terabyte-33302
10/21/2024, 4:39 PMorange-terabyte-33302
10/21/2024, 4:39 PM0.22.0
or later) and pass a Sticky Bucketing Service into your SDK Implementation. You can use one of the built-in Sticky Bucketing Services or implement your own. The built-in services include LocalStorageStickyBucketService
and BrowserCookieStickyBucketService
[source](https://docs.growthbook.io/lib/react#sticky-bucketing). Here's an example of how to use the `BrowserCookieStickyBucketService`: javascript import { GrowthBook, BrowserCookieStickyBucketService } from "@growthbook/growthbook"; import Cookies from 'js-cookie'; const gb = new GrowthBook({ apiHost: "<https://cdn.growthbook.io>", clientKey: "sdk-abc123", stickyBucketService: new BrowserCookieStickyBucketService({ jsCookie: Cookies, }), // ... });
[source](https://docs.growthbook.io/lib/react#sticky-bucketing) In this example, BrowserCookieStickyBucketService
is used for simple bucket persistence using browser cookies. The jsCookie
is implemented (can be polyfilled). Cookie attributes can also be configured. The default cookie expiry is 180 days; override by passing expires: {days}
into the constructor's cookieAttributes
. Remember to update your SDK Connections in the GrowthBook app to ensure that your SDK Connections are configured correctly [source](https://docs.growthbook.io/app/sticky-bucketing#setting-up-sticky-bucketing).wide-cartoon-5349
10/21/2024, 6:49 PMorange-terabyte-33302
10/21/2024, 6:49 PMorange-terabyte-33302
10/21/2024, 6:49 PMBrowserCookieStickyBucketService
in a Next.js application: javascript import { GrowthBook, BrowserCookieStickyBucketService } from "@growthbook/growthbook"; import Cookies from 'js-cookie'; export const growthbookClient = new GrowthBook({ apiHost: "<https://cdn.growthbook.io>", clientKey: "sdk-abc123", stickyBucketService: new BrowserCookieStickyBucketService({ jsCookie: Cookies, }), // ... });
[source](https://linen.growthbook.io/t/18659192/hello-u01t6hchd0a-and-u05ryuxpvnu-i-attended-the-office-hour) In this example, BrowserCookieStickyBucketService
is used for simple bucket persistence using browser cookies. The jsCookie
is implemented (can be polyfilled). Cookie attributes can also be configured. The default cookie expiry is 180 days; override by passing expires: {days}
into the constructor's cookieAttributes
. Remember to update your SDK Connections in the GrowthBook app to ensure that your SDK Connections are configured correctly [source](https://docs.growthbook.io/app/sticky-bucketing#setting-up-sticky-bucketing).wide-cartoon-5349
10/22/2024, 2:23 PMorange-terabyte-33302
10/22/2024, 2:23 PMorange-terabyte-33302
10/22/2024, 2:23 PMwide-cartoon-5349
10/22/2024, 2:30 PMorange-terabyte-33302
10/22/2024, 2:30 PMorange-terabyte-33302
10/22/2024, 2:30 PMjavascript const result = growthbook.feature("my-feature"); if (result.value === "1") { // Variation 1 } else if (result.value === "2") { // Variation 2 } else { // Control }
In this example, "my-feature"
is the name of your feature flag. The growthbook.feature()
function returns an object with a value
property that indicates which variation the user should see. You can then use this value to determine which code to execute for each variation. Remember to replace "my-feature"
, "1"
, "2"
, and the code inside each condition with your actual feature flag name, variation values, and variation code [source](https://docs.growthbook.io/faq#how-do-i-run-an-ab-test-in-growthbook).wide-cartoon-5349
10/23/2024, 4:57 PMorange-terabyte-33302
10/23/2024, 4:57 PMorange-terabyte-33302
10/23/2024, 4:58 PMwide-cartoon-5349
10/23/2024, 4:59 PMorange-terabyte-33302
10/23/2024, 4:59 PMorange-terabyte-33302
10/23/2024, 4:59 PMjavascript const result = growthbook.feature("my-feature"); if (result.value === "ON") { // Code for ON variation } else if (result.value === "OFF") { // Code for OFF variation }
In this example, "my-feature"
is the name of your feature flag, and "ON"
and "OFF"
are the variation values you specified in the GrowthBook UI. The growthbook.feature()
function returns an object with a value
property that indicates which variation the user should see. You can then use this value to determine which code to execute for each variation. Remember to replace "my-feature"
, "ON"
, "OFF"
, and the code inside each condition with your actual feature flag name, variation values, and variation code [source](https://docs.growthbook.io/faq#how-do-i-run-an-ab-test-in-growthbook).wide-cartoon-5349
10/30/2024, 5:26 PMorange-terabyte-33302
10/30/2024, 5:26 PMorange-terabyte-33302
10/30/2024, 5:27 PMjavascript if (growthbook.feature("new-signup-form").on) { // Variation } else { // Control }
This code checks if the "new-signup-form" feature is on, and serves the variation if it is, or the control if it's not [source](https://docs.growthbook.io/faq#how-do-i-run-an-ab-test-in-growthbook). 3. Set up event tracking to measure the impact of your experiment. You'll need to connect GrowthBook to your data source. 4. In your tracking setup, you should include a trigger for when a user views an experiment. This is typically done in the trackingCallback
of your GrowthBook configuration. Here's an example of what this might look like: javascript trackingCallback: (experiment, result) => { // Track that the user was part of the experiment analytics.track("Experiment Viewed", { experimentId: experiment.key, variationId: result.variationId }); }
This callback will fire whenever a user is exposed to an experiment, allowing you to track which users saw which variations [source](https://linen.growthbook.io/t/23080247/hello-team-i-am-new-to-growthbook-and-want-to-run-an-a-b-tes). 5. If you're using Google Tag Manager (GTM), you can set up a custom event trigger for the "Experiment Viewed" event. In GTM, you would: - Create a new trigger - Set it as a Custom Event - Use "experiment_viewed" as the Event name This trigger can then be used to fire tags for tracking your experiment [source](https://docs.growthbook.io/guide/google-tag-manager-and-growthbook#step-4-add-a-trigger). Remember, the exact implementation may vary depending on your specific setup and the tools you're using for tracking and analysis. Always refer to the most recent GrowthBook documentation for the most up-to-date information.wide-cartoon-5349
10/30/2024, 5:31 PMorange-terabyte-33302
10/30/2024, 5:31 PMorange-terabyte-33302
10/30/2024, 5:31 PMjavascript if (growthbook.feature("new-signup-form").on) { // Variation } else { // Control }
This code checks if the "new-signup-form" feature is on for the current user [source](https://docs.growthbook.io/faq#how-do-i-run-an-ab-test-in-growthbook). 5. Tracking Callback: When a user is assigned to an experiment, GrowthBook triggers a tracking callback. This allows you to record the exposure event in your analytics system [source](https://docs.growthbook.io/lib/swift#experimentation-ab-testing). 6. Sticky Bucketing: GrowthBook uses sticky bucketing to ensure that users consistently see the same variation, even across sessions or devices, unless you explicitly change the experiment parameters [source](https://docs.growthbook.io/lib/react#sticky-bucketing). By combining these mechanisms, GrowthBook can accurately and consistently determine when to trigger a feature flag for an A/B test, ensuring that users are assigned to variations in a controlled and measurable way.wide-cartoon-5349
10/30/2024, 5:54 PMorange-terabyte-33302
10/30/2024, 5:54 PMorange-terabyte-33302
10/30/2024, 5:54 PM