Getting Started

Quickstart

Welcome to ConfigDirector docs! This is a quickstart guide to get you up and running.

Welcome to ConfigDirector, a cloud service to manage remote configuration and feature flags.

In this section we'll walk you through:

  1. Creating your first config
  2. Installing and configuring an SDK
  3. Retrieving the config in your app via the SDK
  4. Configuring contexts and targeting rules

1. Create your first config

  1. Sign in to the ConfigDirector dashboard. You'll be prompted to create a free account if you don't have one. Don't worry, it's free to start and does not require a payment method. You can start pay as you go later if you need more than the free allowance.
  2. Click on the Create button next to the Configs navigation to create a new config.
  3. Enter a key (the key is both the name and how you'll reference it in code) for the config, adjust other selections, and save it.

2. Install and configure an SDK for your language and framework

Client and server SDK keys belong to an environment within your project. Use environment variables to provide them at runtime to match the given environment.
  1. Retrieve your client and server SDK keys by going to SDK keys in the dashboard's navigation panel.
  2. Select each environment to access its client and server SDK keys.
  3. Install and configure an SDK for your application stack:
Server SDK keys are secret values. Do not commit them to your source code repository. Provide them at runtime via environment variables instead.
npm install --save @configdirector/client-sdk
config-director-setup.ts (Initialize the client)
import { createClient } from "@configdirector/client-sdk";

export const client = createClient("YOUR-CLIENT-SDK-KEY");
await client.initialize();
npm install --save @configdirector/react-web-sdk
main.tsx
import { createRoot } from "react-dom/client"
import App from "./App"
import { ConfigDirectorProvider } from "@configdirector/react-web-sdk";

createRoot(document.getElementById("root")!).render(
  <ConfigDirectorProvider sdkKey="YOUR-CLIENT-SDK-KEY">
    <App />
  </ConfigDirectorProvider>
);
npm install --save @configdirector/vue-sdk
main.ts
import { createApp } from "vue";
import App from "./App.vue";
import { ConfigDirectorPlugin } from "@configdirector/vue-sdk";

const app = createApp(App);

app.use(ConfigDirectorPlugin, { sdkKey: "YOUR-CLIENT-SDK-KEY" });

app.mount("#app");

3. Retrieve config values

main.ts (Use the client)
import { client } from "./config-director-setup"

// Retrieve the current value
const value = client.getValue("my-config-key", false);

// Subscribe to value updates
const unwatchMyKey = client.watch(
  "my-config-key",
  false,
  (newValue) => {
    console.log("Value updated:", newValue)
  },
);

unwatchMyKey(); // Call the unwatch function returned to remove the listener

client.unwatch("my-config-key"); // Removes all listeners for that key
YourComponent.tsx
import { useConfigValue } from "@configdirector/react-web-sdk";

function YourComponent() {
  const { value } = useConfigValue("my-config-key", false);

  return (<p>my-config-key: {value}</p>);
}

export default YourComponent;
YourComponent.vue
<script setup lang="ts">
import { useConfigValue } from "@configdirector/vue-sdk";

const { value } = useConfigValue("my-config-key", false);
</script>

<template>
  <div>my-config-key is : {{ value }}</div>
</template>

4. Configure contexts and targeting rules

  1. With any of our SDKs you can provide an optional context with attributes that can be leveraged in targeting rules. A context describes a user unless you give it another context kind, such as a device or a tenant. Choose your SDK for instructions on how to provide a context:

A context can be provided when initializing the client:

config-director-setup.ts
import { createClient } from "@configdirector/client-sdk";

export const client = createClient("YOUR-CLIENT-SDK-KEY");
await client.initialize({
  id: "12345",
  name: "Example User",
  traits: {
    region: "North America", // Any arbitrary traits which can be referenced in targeting rules
  }
});

The context can also be updated via updateContext:

main.ts
import { client } from "./config-director-setup"

await client.updateContext({
  id: "654321",
  name: "Another User",
  traits: {
    region: "Australia",
  },
});

// Update it to `undefined` (anonymous user context) when a user signs out
await client.updateContext();

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with kind:

main.ts
await client.updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});

Leaving kind out means user. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

The browser connects with the context given to the provider's context prop. Give it there when you already know the context as the page loads, so the first connection carries it:

main.tsx
import { createRoot } from "react-dom/client"
import App from "./App"
import { ConfigDirectorProvider } from "@configdirector/react-web-sdk";

createRoot(document.getElementById("root")!).render(
  <ConfigDirectorProvider
    sdkKey="YOUR-CLIENT-SDK-KEY"
    context={{ id: "12345", name: "Example User", traits: { region: "North America" } }}>
    <App />
  </ConfigDirectorProvider>
);

To change the context afterwards, for example when a user signs in, call updateContext from the useContext hook where the change happens. Each updateContext call opens a new connection with the new context:

YourComponent.tsx
import { useConfigValue, useContext } from "@configdirector/react-web-sdk";

function YourComponent() {
  const { value: myConfigValue } = useConfigValue("my-config", "default value");
  const { updateContext } = useContext();

  const onUpdate = async () => {
    await updateContext({
      id: "654321",
      name: "Another User",
      traits: {
        region: "Australia",
      },
    });
  };

  return (
    <div>
      <p>My config value: {myConfigValue}</p>
      <button type="button" onClick={onUpdate}>
        Update context
      </button>
    </div>
  );
}

export default YourComponent;

Rendering the provider with a different context prop updates the context the same way.

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with kind:

YourComponent.tsx
updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});

Leaving kind out means user. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

A context can be provided when initializing the plugin:

main.ts
import { createApp } from "vue";
import App from "./App.vue";
import { ConfigDirectorPlugin } from "@configdirector/vue-sdk";

const app = createApp(App);

app.use(ConfigDirectorPlugin, {
  sdkKey: "YOUR-CLIENT-SDK-KEY",
  context: {
    id: "12345",
    name: "Example User",
    traits: {
      region: "North America", // Any arbitrary traits which can be referenced in targeting rules
    },
  },
});

app.mount("#app");

The context can also be updated via the useContext composable:

YourComponent.vue
<script setup lang="ts">
import { useConfigValue, useContext } from "@configdirector/vue-sdk";

const { updateContext } = useContext();
const { value } = useConfigValue("my-config-key", false);

const onUpdate = () => {
  updateContext({
    id: "654321",
    name: "Another User",
    traits: {
      region: "Australia",
    },
  });
};
</script>

<template>
  <div>my-config-key is : {{ value }}</div>
  <button type="button" @click="onUpdate">Update Context</button>
</template>

To evaluate configs for an entity other than a user, such as a tenant, set the context kind with kind:

updateContext({
  id: "acme",
  kind: "tenant",
  name: "Acme Inc.",
  traits: {
    plan: "enterprise",
  },
});

Leaving kind out means user. A context kind is 1 to 64 lowercase letters, digits, dashes, or underscores. A context with an invalid context kind is ignored: the SDK logs an error, and configs are evaluated as if no context had been given. Context kinds are available from version 1.7.0 of the SDK.

  1. You can now configure targeting rules by navigating to your config in the dashboard. Targeting rules are the very first tab on the config view:

Next steps

Prefer to manage projects, configs, targeting rules, and segments as code, or from an AI coding assistant? See the Terraform provider and the MCP server.