Feature flags
Pass visitor data into your docs through a feature flag provider.
Last updated
Was this helpful?
Pass visitor data into your docs through a feature flag provider.
Last updated
Was this helpful?
Was this helpful?
Using adaptive content with feature flags requires adding code to your application.
Currently, the GitBook helper only supports React based setups.
GitBook provides helper functions and integrations for popular feature flag service providers like LaunchDarkly and Bucket.
This allows you to read the feature flags users have access to in your product, as they read your docs. This is useful if you need to show documentation for features that are only available to a specific group of people.
LaunchDarkly allows you to send feature flag access as claims through the launchdarkly-react-client-sdk
and GitBook’s @gitbook/adaptive
package.
If you’re using LaunchDarkly feature flags in your product already, chances are you already have this package configured.
To pass you these feature flags as claims to GitBook, follow these steps:
To get started, you’ll first need to install the LaunchDarkly integration into your GitBook site.
Add your project key and your service access token from your LaunchDarkly settings to the integration’s configuration.
You’ll need to use the withLaunchDarkly
helper with the LaunchDarkly React SDK to pass context into GitBook.
import { render } from 'react-dom';
import { withLaunchDarkly } from '@gitbook/adaptive';
import { asyncWithLDProvider, useLDClient } from 'launchdarkly-react-client-sdk';
import MyApplication from './MyApplication';
function PassFeatureFlagsToGitBookSite() {
const ldClient = useLDClient();
React.useEffect(() => {
if (!ldClient) {
return;
}
return withLaunchDarkly(ldClient);
}, [ldClient]);
return null;
}
(async () => {
const LDProvider = await asyncWithLDProvider({
clientSideID: 'client-side-id-123abc',
context: {
kind: 'user',
key: 'user-key-123abc',
name: 'Sandy Smith',
email: 'sandy@example.com'
},
options: { /* ... */ }
});
render(
<LDProvider>
<PassFeatureFlagsToGitBookSite />
<MyApplication />
</LDProvider>,
document.getElementById('reactDiv'),
);
})();
A visitor schema is required in order for your claims to be able to be read in your published site. Installing and configuring the LaunchDarkly integration should automatically set your visitor schema for you.
After setting your visitor schema, you’re ready to tailor your docs experience for the users visiting your site, using the feature flags the user has access to.
Any feature flag value available in LaunchDarkly will be exposed as part of the visitor schema under the unsigned.launchdarkly.flags
object. Read more about unsigned claims here.
Head to adapting your content to learn more about personalizing your docs for your users.
Bucket allows you to send feature flag access as claims through the @bucketco/react-sdk
and GitBook’s @gitbook/adaptive
package.
If you’re using Bucket feature flags in your product already, chances are you already have this package configured.
To pass you these feature flags as claims to GitBook, follow these steps:
To get started, you’ll first need to install the Bucket integration into your GitBook site.
Add your secret key from your Bucket settings to the integration’s configuration.
You’ll need to use the withBucket
helper with the Bucket React SDK to pass context into GitBook.
import { withBucket } from '@gitbook/adaptive';
import { BucketProvider, useClient } from '@bucketco/react-sdk';
import MyApplication from './MyApplication';
function PassFeatureFlagsToGitBookSite() {
const client = useClient();
React.useEffect(() => {
if (!client) {
return;
}
return withBucket(client);
}, [client]);
return null;
}
export function Application() {
const currentUser = useLoggedInUser();
const appConfig = useAppConfig();
return (
<BucketProvider
publishableKey={appConfig.bucketCo.publishableKey}
user={{
id: currentUser.uid,
email: currentUser.email ?? undefined,
name: currentUser.displayName ?? '',
}}
company={{
id: currentUser.company.id,
}}
>
<PassFeatureFlagsToGitBookSite />
<MyApplication />
</BucketProvider>
);
}
A visitor schema is required in order for your claims to be able to be read in your published site. Installing and configuring the Bucket integration should automatically set your visitor schema for you.
After setting your visitor schema, you’re ready to tailor your docs experience for the users visiting your site, using the feature flags the user has access to.
Any feature flag value available in Bucket will be exposed as part of the visitor schema under the unsigned.bucket.flags
object. Read more about unsigned claims here.
Head to adapting your content to learn more about personalizing your docs for your users.