### Install GrowthBook Go SDK Source: https://docs.growthbook.io/lib/go Use 'go get' to install the GrowthBook Go SDK. Ensure you have Go version 1.21 or higher. ```bash go get github.com/growthbook/growthbook-golang ``` -------------------------------- ### Install GrowthBook SDK with Bun Source: https://docs.growthbook.io/lib/nextjs Install the GrowthBook SDK using Bun. ```bash bun add @flags-sdk/growthbook ``` -------------------------------- ### Start GrowthBook with Docker Source: https://docs.growthbook.io/guide/nextjs-app-router Use Docker Compose to start the local GrowthBook environment. This requires Docker to be installed. ```bash docker compose up -d ``` -------------------------------- ### Quick Start: Initialize and Use GrowthBook SDK Source: https://docs.growthbook.io/lib/ruby Initialize the GrowthBook SDK by fetching features and creating a context with user attributes. Use the context to check feature flags and get feature values. ```ruby require 'growthbook' # Fetch features from a GrowthBook instance # You should cache this in Redis or similar in production features_repository = Growthbook::FeatureRepository.new( endpoint: 'https://cdn.growthbook.io/api/features/MY_API_KEY', decryption_key: nil ) features = features_repository.fetch # Create a context for the current user/request gb = Growthbook::Context.new( features: features, # User attributes for targeting / variation assignment attributes: { id: '123', country: 'US' } ) # Use a boolean feature flag if gb.on? :my_feature_key puts 'My feature is on!' end # Get the value of a multivariate feature with a fallback btn_color = gb.feature_value(:signup_btn_color, 'pink') ``` -------------------------------- ### Install GrowthBook SDK with pnpm Source: https://docs.growthbook.io/lib/nextjs Install the GrowthBook SDK using pnpm. ```bash pnpm add @flags-sdk/growthbook ``` -------------------------------- ### Install GrowthBook SDK with npm Source: https://docs.growthbook.io/lib/nextjs Install the GrowthBook SDK using npm. ```bash npm install --save @flags-sdk/growthbook ``` -------------------------------- ### Install GrowthBook SDK with Yarn Source: https://docs.growthbook.io/lib/nextjs Install the GrowthBook SDK using Yarn. ```bash yarn add @flags-sdk/growthbook ``` -------------------------------- ### Install Dependencies with Bun Source: https://docs.growthbook.io/guide/nextjs-and-vercel-feature-flags Install the necessary GrowthBook and Vercel packages using Bun. ```bash bun add @growthbook/growthbook @vercel/flags @vercel/edge-config ``` -------------------------------- ### Verify GrowthBook Setup Source: https://docs.growthbook.io/integrations/ai-agents/agent-skills Verify that your GrowthBook credentials are set up correctly by running the flag-search skill. If there are issues, the error message will guide you back to the setup skill. ```bash /growthbook:flag-search ``` -------------------------------- ### Install GrowthBook CLI with Bun Source: https://docs.growthbook.io/tools/cli Install the GrowthBook CLI as a project dependency using Bun. ```bash bun add growthbook ``` -------------------------------- ### Install GrowthBook React Native SDK with Bun Source: https://docs.growthbook.io/lib/react-native Install the SDK using Bun. ```bash bun add @growthbook/growthbook-react ``` -------------------------------- ### Installation Source: https://docs.growthbook.io/lib/nextjs Install the GrowthBook SDK using your preferred package manager. ```APIDOC npm install --save @flags-sdk/growthbook ``` ```APIDOC yarn add @flags-sdk/growthbook ``` ```APIDOC pnpm add @flags-sdk/growthbook ``` ```APIDOC bun add @flags-sdk/growthbook ``` -------------------------------- ### Install @growthbook/growthbook-react Source: https://docs.growthbook.io/lib/quickstart Install the React SDK and core GrowthBook package using npm, Yarn, pnpm, or Bun. ```bash npm install @growthbook/growthbook-react @growthbook/growthbook ``` ```bash yarn add @growthbook/growthbook-react @growthbook/growthbook ``` ```bash pnpm add @growthbook/growthbook-react @growthbook/growthbook ``` ```bash bun add @growthbook/growthbook-react @growthbook/growthbook ``` -------------------------------- ### Install Edge Utils with Bun Source: https://docs.growthbook.io/lib/edge/other Install the GrowthBook edge-utils package using Bun. ```bash bun add @growthbook/edge-utils ``` -------------------------------- ### Install GrowthBook React SDK Source: https://docs.growthbook.io/guide/rudderstack-and-nextjs-with-growthbook Install the GrowthBook React SDK using yarn. ```bash yarn add @growthbook/growthbook-react ``` -------------------------------- ### Start Next.js Development Server Source: https://docs.growthbook.io/guide/nextjs-and-vercel-feature-flags Commands to start the Next.js development server using different package managers. ```bash npm run dev ``` ```bash yarn dev ``` ```bash pnpm run dev ``` ```bash bun run dev ``` -------------------------------- ### Start Minikube for Local Development Source: https://docs.growthbook.io/self-host/kubernetes Start a Minikube instance for local Kubernetes development. This is intended for testing and development only. ```bash minikube start ``` -------------------------------- ### Install Growthbook with Helm Source: https://docs.growthbook.io/self-host/kubernetes Use this Helm command to install Growthbook. Ensure you have a values file configured for your environment. ```bash helm install growthbook growthbook/growthbook -f values-gcp.yaml ``` -------------------------------- ### Install Fastly Edge SDK with Bun Source: https://docs.growthbook.io/lib/edge/fastly Use this command to install the GrowthBook Edge SDK for Fastly using Bun. ```bash bun add @growthbook/edge-fastly ``` -------------------------------- ### Set up Create React App with GrowthBook SDK Source: https://docs.growthbook.io/guide/create-react-app-and-growthbook Installs Create React App and the necessary GrowthBook and nanoid libraries. Ensure the app is running by visiting http://localhost:3000/. ```bash npx create-react-app my-app cd my-app npm install --save @growthbook/growthbook-react nanoid npm start ``` -------------------------------- ### Use a Feature Flag in JavaScript Source: https://docs.growthbook.io/quick-start Check if a feature flag is enabled in your JavaScript application. This is a basic example for getting started with feature flags. ```javascript if (gb.isOn("my-feature")) { console.log("It's On!") } ``` -------------------------------- ### Setup Go GrowthBook OpenFeature Provider Source: https://docs.growthbook.io/lib/openfeature Initializes the GrowthBook client and wraps it in the OpenFeature provider, then registers it. ```go import ( "context" "log" gb "github.com/growthbook/growthbook-golang" gbprovider "github.com/growthbook/growthbook-openfeature-provider-go" "github.com/open-feature/go-sdk/openfeature" ) // Create the underlying GrowthBook client gbClient, err := gb.NewClient(context.Background(), gb.WithAPIHost("https://cdn.growthbook.io"), gb.WithClientKey("sdk-abc123"), ) if err != nil { log.Fatal("GrowthBook client initialization failed: ", err) } defer gbClient.Close() // Wrap it in the OpenFeature provider and register it provider := gbprovider.NewProvider(gbClient) if err = openfeature.SetProvider(provider); err != nil { log.Fatal("Failed to set OpenFeature provider: ", err) } client := openfeature.NewClient("my-app") ``` -------------------------------- ### Install Go GrowthBook OpenFeature Provider Source: https://docs.growthbook.io/lib/openfeature Use go get to install the Go provider. Requires Go 1.21+. ```bash go get github.com/growthbook/growthbook-openfeature-provider-go ``` -------------------------------- ### Set up local GrowthBook instance Source: https://docs.growthbook.io/guide/nextjs-and-growthbook Clone the GrowthBook repository and use Docker Compose to run a local instance. Visit `http://localhost:3000` to create an account. ```bash git clone https://github.com/growthbook/growthbook.git cd growthbook docker compose up -d ``` -------------------------------- ### JavaScript/React SDK Setup with Tracking Source: https://docs.growthbook.io/app/managed-warehouse Install the GrowthBook SDK and enable the auto-attributes and growthbook tracking plugins for JavaScript or React applications. ```javascript import { GrowthBook } from "@growthbook/growthbook"; import { autoAttributesPlugin, growthbookTrackingPlugin } from "@growthbook/growthbook/plugins"; const gb = new GrowthBook({ clientKey: "YOUR_CLIENT_KEY", plugins: [ autoAttributesPlugin(), growthbookTrackingPlugin() ] }); ``` -------------------------------- ### Quick Start with GrowthBook C# SDK Source: https://docs.growthbook.io/lib/csharp Initialize GrowthBook with user context, load features from the API, and evaluate feature flags. ```csharp using GrowthBook; using Newtonsoft.Json.Linq; // 1. Create a context with user attributes var context = new Context { Enabled = true, Attributes = new JObject { ["id"] = "user-123", ["country"] = "US", ["plan"] = "premium" } }; // 2. Initialize GrowthBook var gb = new GrowthBook.GrowthBook(context); // 3. Load features from API (async) await gb.LoadFeaturesAsync("https://cdn.growthbook.io", "sdk_abc123"); // 4. Evaluate features if (gb.IsOn("new-dashboard")) { ShowNewDashboard(); } var buttonColor = gb.GetFeatureValue("button-color", "blue"); var maxRetries = gb.GetFeatureValue("max-retries", 3); ``` -------------------------------- ### Example BucketRange Tuple Source: https://docs.growthbook.io/lib/build-your-own A tuple representing a range on the numberline between 0 and 1, used for experiment bucketing. It consists of two float values: the start and end of the range. ```json [0.3, 0.7] ``` -------------------------------- ### Initialize GBFeaturesRepository and GrowthBook SDK (Java) Source: https://docs.growthbook.io/lib/java Demonstrates how to create a singleton instance of GBFeaturesRepository, initialize it to fetch features, and then use those features to initialize the GrowthBook SDK. Includes optional configuration for API host, client key, encryption key, and refresh strategy. ```java GBFeaturesRepository featuresRepository = GBFeaturesRepository .builder() .apiHost("https://cdn.growthbook.io") .clientKey("") // replace with your client key .encryptionKey("") // optional, nullable .refreshStrategy(FeatureRefreshStrategy.SERVER_SENT_EVENTS) // optional; options: STALE_WHILE_REVALIDATE, SERVER_SENT_EVENTS (default: STALE_WHILE_REVALIDATE) .build(); // Optional callback for getting updates when features are refreshed featuresRepository.onFeaturesRefresh(new FeatureRefreshCallback() { @Override public void onRefresh(String featuresJson) { System.out.println("Features have been refreshed"); System.out.println(featuresJson); } }); try { featuresRepository.initialize(); } catch (FeatureFetchException e) { // TODO: handle the exception e.printStackTrace(); } // Initialize the GrowthBook SDK with the GBContext and features GBContext context = GBContext .builder() .featuresJson(featuresRepository.getFeaturesJson()) .attributesJson(userAttributesJson) .build(); GrowthBook growthBook = new GrowthBook(context); ``` -------------------------------- ### Quick Usage of GrowthBook Go SDK Source: https://docs.growthbook.io/lib/go Initialize a GrowthBook client with a client key and SSE data source. Ensure data is loaded before evaluating features. Create a child client with specific attributes to evaluate features. ```go import ( "context" "log" gb "github.com/growthbook/growthbook-golang" ) // Create a new client instance with a client key and a data source that loads features // in the background using an SSE stream. Pass the client's options to the NewClient function. client, err := gb.NewClient( context.Background(), gb.WithClientKey("sdk-XXXX"), gb.WithSseDataSource(), ) defer client.Close() if err != nil { log.Fatal("Client initialization failed: ", err) } // The data source starts asynchronously. Use EnsureLoaded to wait until the client data // is initialized for the first time. if err := client.EnsureLoaded(context.Background()); err != nil { log.Fatal("Data loading failed: ", err) } // Create a child client with specific attributes. attrs := gb.Attributes{"id": 100, "user": "user1"} child, err := client.WithAttributes(attrs) if err != nil { log.Fatal("Child client creation failed: ", err) } // Evaluate a text feature. buttonColor := child.EvalFeature(context.Background(), "buy-button-color") if buttonColor.Value == "blue" { // Perform actions for blue button. } // Evaluate a boolean feature. darkMode := child.EvalFeature(context.Background(), "dark-mode") if darkMode.On { // Enable dark mode. } ``` -------------------------------- ### Initialize Hono Project with Deno Source: https://docs.growthbook.io/guide/deno-hono Use this command to create a new Hono project with Deno as the runtime. Replace 'my-app' with your desired project name. ```bash deno run -A npm:create-hono@latest my-app ``` -------------------------------- ### Create and Initialize Client with Auto Updates Source: https://docs.growthbook.io/lib/go Use `gb.NewClient` with `gb.WithSseDataSource` to create a client that automatically fetches and updates features. `client.EnsureLoaded` blocks until features are ready or a context timeout occurs. ```go // Create client with automatic updates client, err := gb.NewClient( context.Background(), gb.WithClientKey("sdk-abc123"), gb.WithSseDataSource(), ) if err != nil { log.Fatal(err) } // EnsureLoaded blocks until features are ready ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() if err := client.EnsureLoaded(ctx); err != nil { log.Fatal("Features not loaded in time:", err) } // Features are now loaded and will update automatically fmt.Println("Features loaded successfully") ``` -------------------------------- ### Quick Start: Initialize and Evaluate Features in Elixir Source: https://docs.growthbook.io/lib/elixir Initialize GrowthBook with your client key and API host, build a context with user attributes, and evaluate features. ```elixir # 1. Initialize GrowthBook with your API key GrowthBook.init( client_key: "sdk-abc123", api_host: "https://cdn.growthbook.io" ) # 2. Create a context with user attributes context = GrowthBook.build_context(%{ "id" => "user-123", "country" => "US" }) # 3. Evaluate features if GrowthBook.feature(context, "new-dashboard").on? do render_new_dashboard() else render_old_dashboard() end # Get feature values button_color = GrowthBook.feature(context, "button-color").value max_retries = GrowthBook.feature(context, "max-retries").value || 3 ``` -------------------------------- ### Install Dependencies with pnpm Source: https://docs.growthbook.io/guide/nextjs-and-vercel-feature-flags Install the necessary GrowthBook and Vercel packages using pnpm. ```bash pnpm add @growthbook/growthbook @vercel/flags @vercel/edge-config ``` -------------------------------- ### Initialize GBFeaturesRepository and GrowthBook SDK (Kotlin) Source: https://docs.growthbook.io/lib/java Shows how to initialize the GBFeaturesRepository and GrowthBook SDK in Kotlin. This includes setting up the repository with CDN host, client key, and an optional encryption key, along with a callback for feature refreshes. ```kotlin val featuresRepository = GBFeaturesRepository( "https://cdn.growthbook.io", "", "", // optional, nullable 30, ).apply { // Optional callback for getting updates when features are refreshed onFeaturesRefresh { println("Features have been refreshed \n $it") } } // Fetch the features try { featuresRepository.initialize() } catch (e: FeatureFetchException) { // TODO: handle the exception e.printStackTrace() } // Initialize the GrowthBook SDK with the GBContext and features val context = GBContext .builder() .featuresJson(featuresRepository.featuresJson) .attributesJson(userAttributes) .build() val growthBook = GrowthBook(context) ``` -------------------------------- ### Install Dependencies with Yarn Source: https://docs.growthbook.io/guide/nextjs-and-vercel-feature-flags Install the necessary GrowthBook and Vercel packages using Yarn. ```bash yarn add @growthbook/growthbook @vercel/flags @vercel/edge-config ``` -------------------------------- ### Configure GrowthBook Credentials Source: https://docs.growthbook.io/integrations/ai-agents/agent-skills Run the setup skill to configure your GrowthBook credentials. It prompts for your PAT or API key and API URL (for self-hosted instances), validates them, and saves them to ~/.config/growthbook/.env. Alternatively, export them as environment variables. ```bash /growthbook:gb-setup ``` ```bash export GB_API_KEY= # required: PAT or Secret Key export GB_API_URL=https://api.your-host # self-hosted only ``` -------------------------------- ### Install Dependencies with npm Source: https://docs.growthbook.io/guide/nextjs-and-vercel-feature-flags Install the necessary GrowthBook and Vercel packages using npm. ```bash npm install @growthbook/growthbook @vercel/flags @vercel/edge-config ``` -------------------------------- ### Install GrowthBook React Native SDK with pnpm Source: https://docs.growthbook.io/lib/react-native Install the SDK using pnpm. ```bash pnpm add @growthbook/growthbook-react ``` -------------------------------- ### Install GrowthBook React Native SDK with npm Source: https://docs.growthbook.io/lib/react-native Install the SDK using npm. ```bash npm install --save @growthbook/growthbook-react ``` -------------------------------- ### Initialize GrowthBook SDK and Evaluate Features Source: https://docs.growthbook.io/lib/kotlin-jvm Initialize the GrowthBook SDK with your API key, host, and user attributes. This snippet demonstrates fetching feature flags and running inline experiments. ```kotlin import com.sdk.growthbook.GBSDKBuilder import com.sdk.growthbook.model.GBExperiment import com.sdk.growthbook.model.toGbString import com.sdk.growthbook.network.GBNetworkDispatcherOkHttp suspend fun main() { // User attributes for targeting and experiments val attributes = mapOf( "id" to "user_123".toGbString(), "environment" to "production".toGbString(), "organization" to "acme-corp".toGbString(), "role" to "admin".toGbString() ) // Create network dispatcher (OkHttp recommended for servers) val networkDispatcher = GBNetworkDispatcherOkHttp() // Build GrowthBook SDK instance val growthBook = GBSDKBuilder( apiKey = "sdk_abc123", apiHost = "https://cdn.growthbook.io/", attributes = attributes, networkDispatcher = networkDispatcher, trackingCallback = { experiment, result -> // Track experiment views in your analytics println("Experiment: ${experiment.key}, Variation: ${result.variationId}") } ).initialize() // Fetch feature definitions growthBook.refreshCache() // Evaluate feature flags val newFeatureEnabled = growthBook.feature("new-checkout-flow").on val maxRetries = growthBook.featureValue("max-retries") ?: 3 println("New checkout flow: $newFeatureEnabled") println("Max retries: $maxRetries") // Run inline experiments val buttonColorExperiment = growthBook.run( GBExperiment( key = "button-color-test", variations = listOf("blue", "red", "green").map { it.toGbString() } ) ) println("Button color: ${buttonColorExperiment.value}") } ``` -------------------------------- ### Initialize GrowthBook SDK (Singleton Pattern) Source: https://docs.growthbook.io/lib/roku Create a single instance of the GrowthBook SDK and initialize it once in your application's entry point. Reuse this global instance throughout your app to avoid redundant API calls and excessive memory usage. ```vbscript ' In your main entry point sub Main() ' Create global field once m.global.addFields({ gb: invalid }) ' Initialize once m.global.gb = GrowthBook({ clientKey: "sdk_YOUR_KEY", attributes: { id: GetDeviceId() } }) m.global.gb.init() ' Now use throughout app ShowApp() end sub ' In any component or function function CheckFeature() ' Access the same instance if m.global.gb.isOn("my-feature") then DoSomething() end if end function ``` -------------------------------- ### Install Edge Utils with pnpm Source: https://docs.growthbook.io/lib/edge/other Install the GrowthBook edge-utils package using pnpm. ```bash pnpm add @growthbook/edge-utils ``` -------------------------------- ### Install Edge Utils with Yarn Source: https://docs.growthbook.io/lib/edge/other Install the GrowthBook edge-utils package using Yarn. ```bash yarn add @growthbook/edge-utils ``` -------------------------------- ### Install Edge Utils with npm Source: https://docs.growthbook.io/lib/edge/other Install the GrowthBook edge-utils package using npm. ```bash npm install --save @growthbook/edge-utils ``` -------------------------------- ### Install GrowthBook and Tailwind CSS Source: https://docs.growthbook.io/guide/deno-hono Install the GrowthBook JS SDK and Tailwind CSS using the 'deno add' command. This registers the packages in your deno.json import map. ```bash deno add jsr:@growthbook/growthbook npm:tailwindcss ``` -------------------------------- ### GrowthBook SDK Initialization Options Source: https://docs.growthbook.io/lib/roku Demonstrates the minimum required options for initializing the GrowthBook SDK, either by loading features from an API using `clientKey` or by using embedded features in offline mode. ```roku ' Option 1: API loading gb = GrowthBook({ clientKey: "sdk_abc123", attributes: { id: GetDeviceId() } }) ' Option 2: Offline mode gb = GrowthBook({ features: myFeatures, attributes: { id: GetDeviceId() } }) ``` -------------------------------- ### Async Client with Sticky Bucketing Source: https://docs.growthbook.io/lib/python Demonstrates initializing the GrowthBook client asynchronously with a custom synchronous sticky bucket service. ```python from growthbook import AbstractStickyBucketService, GrowthBookClient, Options, UserContext class MyStickyBucketService(AbstractStickyBucketService): def get_assignments(self, attributeName, attributeValue): # Implementation must be synchronous return None def save_assignments(self, doc): # Implementation must be synchronous pass async def main(): # Create sticky bucket service sticky_service = MyStickyBucketService() # Create client with sticky bucketing client = GrowthBookClient( Options( api_host="https://cdn.growthbook.io", client_key="sdk-abc123", sticky_bucket_service=sticky_service ) ) try: await client.initialize() # User will get consistent experiment assignments user = UserContext(attributes={"id": "user_123"}) # ... finally: await client.close() ``` -------------------------------- ### Install GrowthBook CLI with pnpm Source: https://docs.growthbook.io/tools/cli Install the GrowthBook CLI as a project dependency using pnpm. ```bash pnpm add growthbook ``` -------------------------------- ### Initialize Client with Environment Variables Source: https://docs.growthbook.io/lib/go Use environment variables for sensitive keys like GROWTHBOOK_DECRYPTION_KEY and GROWTHBOOK_CLIENT_KEY. Ensure the decryption key is set to avoid fatal errors during client initialization. ```go import ( "os" gb "github.com/growthbook/growthbook-golang" ) // Use environment variables for sensitive keys decryptionKey := os.Getenv("GROWTHBOOK_DECRYPTION_KEY") if decryptionKey == "" { log.Fatal("GROWTHBOOK_DECRYPTION_KEY environment variable not set") } client, err := gb.NewClient( context.Background(), gb.WithClientKey(os.Getenv("GROWTHBOOK_CLIENT_KEY")), gb.WithDecryptionKey(decryptionKey), gb.WithSseDataSource(), ) ``` -------------------------------- ### Install GrowthBook CLI with Yarn Source: https://docs.growthbook.io/tools/cli Install the GrowthBook CLI as a project dependency using Yarn. ```bash yarn add growthbook ``` -------------------------------- ### Install GrowthBook CLI with npm Source: https://docs.growthbook.io/tools/cli Install the GrowthBook CLI as a project dependency using npm. ```bash npm install growthbook --save ```