@@ -40,15 +40,18 @@ If using Nuxt, wrap `<BucketProvider>` in `<ClientOnly>`. `<BucketProvider>` onl
4040<script setup lang="ts">
4141import { useFeature } from "@bucketco/vue-sdk";
4242
43- const huddle = useFeature("huddle");
43+ const { isEnabled } = useFeature("huddle");
4444</script>
4545
4646<template>
47- <div v-if="huddle.isEnabled">
48- <button @click="huddle.track()">Start huddle!</button>
47+ <div v-if="isEnabled">
48+ <button>Start huddle!</button>
49+ </div>
4950</template>
5051```
5152
53+ See [ useFeature()] ( #usefeature ) for a full example
54+
5255## Setting ` user ` and ` company `
5356
5457Bucket determines which features are active for a given ` user ` , ` company ` , or ` otherContext ` .
@@ -70,7 +73,9 @@ A number of special attributes exist:
7073 :publishable-key="publishableKey"
7174 :user="{ id: 'user_123', name: 'John Doe', email: 'john@acme.com' }"
7275 :company="{ id: 'acme_inc', plan: 'pro' }"
73- ></BucketProvider>
76+ >
77+ <!-- your app -->
78+ </BucketProvider>
7479```
7580
7681To retrieve features along with their targeting information, use ` useFeature(key: string) ` hook (described in a section below).
@@ -149,26 +154,40 @@ If you want more control over loading screens, `useIsLoading()` returns a Ref<bo
149154
150155### ` useFeature() `
151156
152- Returns the state of a given feature for the current context. The composable provides type-safe access to feature flags and their configurations.
157+ Returns the state of a given feature for the current context. The composable provides access to feature flags and their configurations.
158+
159+ ` useFeature() ` returns an object with this shape:
160+
161+ ``` ts
162+ {
163+ isEnabled : boolean , // is the feature enabled
164+ track : () => void , // send a track event when the feature is used
165+ requestFeedback : (... ) => void // open up a feedback dialog
166+ config : {key : string , payload : any }, // remote configuration for this feature
167+ isLoading : boolean // if you want to manage loading state at the feature level
168+ }
169+ ```
170+
171+ Example:
153172
154173``` vue
155174<script setup lang="ts">
156175import { useFeature } from "@bucketco/vue-sdk";
157176
158- const huddle = useFeature("huddle");
177+ const { isEnabled, track, requestFeedback, config } = useFeature("huddle");
159178</script>
160179
161180<template>
162- <div v-if="huddle. isLoading">Loading...</div>
163- <div v-else-if="!huddle. isEnabled">Feature not available</div>
181+ <div v-if="isLoading">Loading...</div>
182+ <div v-else-if="!isEnabled">Feature not available</div>
164183 <div v-else>
165- <button @click="huddle. track()">Start huddle!</button>
184+ <button @click="track()">Start huddle!</button>
166185 <button
167186 @click="
168187 (e) =>
169- huddle. requestFeedback({
188+ requestFeedback({
170189 title:
171- huddle. config.payload?.question ??
190+ config.payload?.question ??
172191 'How do you like the Huddles feature?',
173192 position: {
174193 type: 'POPOVER',
@@ -187,7 +206,9 @@ See the reference docs for details.
187206
188207### ` useTrack() `
189208
190- ` useTrack() ` lets you send custom events to Bucket. Use this whenever a user _ uses_ a feature.
209+ ` useTrack() ` returns a function which lets you send custom events to Bucket. It takes a string argument with the event name and optionally an object with properties to attach the event.
210+
211+ Using ` track ` returned from ` useFeature() ` calles this track function with the feature key as the event name.
191212
192213``` vue
193214<script setup lang="ts">
0 commit comments