You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(react-sdk,browser-sdk): updated various out-of-date docs (#338)
- Simplified the getting started instructions
- Cleaned up outdates "features update" instructions. There's "Event
listeners" instead.
- Update docs to reflect that `featureOptions` are passed at the root
level now
Copy file name to clipboardExpand all lines: packages/browser-sdk/README.md
+13-31Lines changed: 13 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,15 +100,13 @@ type Configuration = {
100
100
sseBaseUrl?:"https://livemessaging.bucket.co";
101
101
feedback?:undefined; // See FEEDBACK.md
102
102
enableTracking?:true; // set to `false` to stop sending track events and user/company updates to Bucket servers. Useful when you're impersonating a user
103
-
featureOptions?: {
104
-
fallbackFeatures?:
105
-
|string[]
106
-
|Record<string, { key:string; payload:any } |true>; // Enable these features if unable to contact bucket.co. Can be a list of feature keys or a record with configuration values
107
-
timeoutMs?:number; // Timeout for fetching features (default: 5000ms)
108
-
staleWhileRevalidate?:boolean; // Revalidate in the background when cached features turn stale to avoid latency in the UI (default: false)
109
-
staleTimeMs?:number; // at initialization time features are loaded from the cache unless they have gone stale. Defaults to 0 which means the cache is disabled. Increase in the case of a non-SPA
110
-
expireTimeMs?:number; // In case we're unable to fetch features from Bucket, cached/stale features will be used instead until they expire after `expireTimeMs`. Default is 30 days
111
-
};
103
+
fallbackFeatures?:
104
+
|string[]
105
+
|Record<string, { key:string; payload:any } |true>; // Enable these features if unable to contact bucket.co. Can be a list of feature keys or a record with configuration values
106
+
timeoutMs?:number; // Timeout for fetching features (default: 5000ms)
107
+
staleWhileRevalidate?:boolean; // Revalidate in the background when cached features turn stale to avoid latency in the UI (default: false)
108
+
staleTimeMs?:number; // at initialization time features are loaded from the cache unless they have gone stale. Defaults to 0 which means the cache is disabled. Increase this in the case of a non-SPA
109
+
expireTimeMs?:number; // In case we're unable to fetch features from Bucket, cached/stale features will be used instead until they expire after `expireTimeMs`. Default is 30 days
> Note that the callback may be called even if features haven't actually changed.
213
-
214
195
### Remote config
215
196
216
197
Similar to `isEnabled`, each feature has a `config` property. This configuration is managed from within Bucket.
@@ -312,11 +293,12 @@ See details in [Feedback HTTP API](https://docs.bucket.co/reference/http-trackin
312
293
313
294
Event listeners allow for capturing various events occurring in the `BucketClient`. This is useful to build integrations with other system or for various debugging purposes. There are 5 kinds of events:
314
295
315
-
- FeaturesUpdated
316
-
- User
317
-
- Company
318
-
- Check
319
-
- Track
296
+
-`configCheck`: Your code used a feature config
297
+
-`enabledCheck`: Your code checked whether a specific feature should be enabled
298
+
-`featuresUpdated`: Features were updated. Either because they were loaded as part of initialization or because the user/company updated
299
+
-`user`: User information updated (similar to the `identify` call used in tracking terminology)
300
+
-`company`: Company information updated (sometimes to the `group` call used in tracking terminology)
301
+
-`track`: Track event occurred.
320
302
321
303
Use the `on()` method to add an event listener to respond to certain events. See the API reference for details on each hook.
Add the `BucketProvider` context provider to your application.
43
-
This will initialize the Bucket SDK, fetch features and start listening for automated feedback survey events.
42
+
Add the `BucketProvider` context provider to your application:
44
43
45
44
**Example:**
46
45
@@ -52,107 +51,33 @@ import { BucketProvider } from "@bucketco/react-sdk";
52
51
company={{ id: "acme_inc", plan: "pro" }}
53
52
user={{ id: "john doe" }}
54
53
loadingComponent={<Loading />}
55
-
featureOptions={{ fallbackFeatures: ["huddle"] }}
56
54
>
57
55
{/* children here are shown when loading finishes or immediately if no `loadingComponent` is given */}
58
56
</BucketProvider>;
59
57
```
60
58
61
-
-`publishableKey` is used to connect the provider to an _environment_ on Bucket. Find your `publishableKey` under [environment settings](https://app.bucket.co/envs/current/settings/app-environments) in Bucket,
62
-
-`company`, `user` and `otherContext` make up the _context_ that is used to determine if a feature is enabled or not. `company` and `user` contexts are automatically transmitted to Bucket servers so the Bucket app can show you which companies have access to which features etc.
63
-
> [!Note]
64
-
> If you specify `company` and/or `user` they must have at least the `id` property, otherwise they will be ignored in their entirety. You should also supply anything additional you want to be able to evaluate feature targeting against,
65
-
-`featureOptions` contains configuration for features:
66
-
67
-
-`fallbackFeatures`: A list of strings which specify which features to consider enabled if the SDK is unable to fetch features. Can be provided in two formats:
68
-
69
-
```ts
70
-
// Simple array of feature keys
71
-
featureOptions={{
72
-
fallbackFeatures: ["feature1", "feature2"]
73
-
}}
74
-
75
-
// Or with configuration overrides
76
-
featureOptions={{
77
-
fallbackFeatures: {
78
-
"feature1": true, // just enable the feature
79
-
"feature2": { // enable with configuration
80
-
key: "variant-a",
81
-
payload: {
82
-
limit: 100,
83
-
mode: "test"
84
-
}
85
-
}
86
-
}
87
-
}}
88
-
```
59
+
### 3. Use `useFeature(<featureKey>)` to get feature status
Attributes cannot be nested (multiple levels) and must be either strings, numbers or booleans.
166
91
A number of special attributes exist:
167
92
168
93
-`name` -- display name for `user`/`company`,
@@ -212,6 +137,65 @@ configuration in your application.
212
137
Note that, similar to `isEnabled`, accessing `config` on the object returned by `useFeature()` automatically
213
138
generates a `check` event.
214
139
140
+
## `<BucketProvider>` component
141
+
142
+
The `<BucketProvider>` initializes the Bucket SDK, fetches features and starts listening for automated feedback survey events. The component can be configured using a number of props:
143
+
144
+
- `publishableKey` is used to connect the provider to an _environment_ on Bucket. Find your `publishableKey` under [environment settings](https://app.bucket.co/envs/current/settings/app-environments) in Bucket,
145
+
- `company`, `user` and `otherContext` make up the _context_ that is used to determine if a feature is enabled or not. `company` and `user` contexts are automatically transmitted to Bucket servers so the Bucket app can show you which companies have access to which features etc.
146
+
> [!Note]
147
+
> If you specify `company` and/or `user` they must have at least the `id` property, otherwise they will be ignored in their entirety. You should also supply anything additional you want to be able to evaluate feature targeting against,
148
+
- `fallbackFeatures`: A list of strings which specify which features to consider enabled if the SDK is unable to fetch features. Can be provided in two formats:
149
+
150
+
```ts
151
+
// Simple array of feature keys
152
+
fallbackFeatures={["feature1", "feature2"]}
153
+
154
+
// Or with configuration overrides
155
+
fallbackFeatures: {
156
+
"feature1": true, // just enable the feature
157
+
"feature2": { // enable with configuration
158
+
key: "variant-a",
159
+
payload: {
160
+
limit: 100,
161
+
mode: "test"
162
+
}
163
+
}
164
+
}
165
+
```
166
+
167
+
- `timeoutMs`: Timeout in milliseconds when fetching features from the server,
168
+
- `staleWhileRevalidate`: If set to `true`, stale features will be returned while refetching features in the background,
169
+
- `expireTimeMs`: If set, features will be cached between page loads for this duration (in milliseconds),
170
+
- `staleTimeMs`: Maximum time (in milliseconds) that stale features will be returned if `staleWhileRevalidate` is true and new features cannot be fetched.
171
+
- `loadingComponent` lets you specify an React component to be rendered instead of the children while the Bucket provider is initializing. If you want more control over loading screens, `useFeature()` returns `isLoading` which you can use to customize the loading experience:
{/* children here are shown when loading finishes */}
187
+
</LoadingBucket>
188
+
<BucketProvider>
189
+
```
190
+
191
+
- `enableTracking`: Set to `false` to stop sending tracking events and user/company updates to Bucket. Useful when you're impersonating a user (defaults to `true`),
192
+
- `apiBaseUrl`: Optional base URL for the Bucket API. Use this to override the default API endpoint,
193
+
- `appBaseUrl`: Optional base URL for the Bucket application. Use this to override the default app URL,
194
+
- `sseBaseUrl`: Optional base URL for Server-Sent Events. Use this to override the default SSE endpoint,
195
+
- `debug`: Set to `true` to enable debug logging to the console,
196
+
- `toolbar`: Optional configuration for the Bucket toolbar,
197
+
- `feedback`: Optional configuration for feedback collection
198
+
215
199
## Hooks
216
200
217
201
### `useFeature()`
@@ -248,7 +232,7 @@ function StartHuddleButton() {
248
232
<button
249
233
onClick={(e) =>
250
234
requestFeedback({
251
-
title: payload?.question ?? "How do you like Huddles?",
235
+
title: payload?.question??"How do you like the Huddles feature?",
0 commit comments