Skip to content

Commit

Permalink
docs: async storage analytics requirement (Flagsmith#3904)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben Rometsch <ben.rometsch@gmail.com>
  • Loading branch information
kyle-ssg and dabeeeenster authored May 9, 2024
1 parent 9303267 commit 9753e66
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
43 changes: 22 additions & 21 deletions docs/docs/clients/client-side/javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ npm i flagsmith --save

:::tip

The ReactNative SDK shares the exact same implementation of Flagsmith, however, the defaults for some underlying
libraries (e.g. AsyncStorage) use React Native compatible implementations.
The React Native SDK shares the exact same implementation of Flagsmith, however it requires an implementation of
AsyncStorage to be provided (e.g. @react-native-community/async-storage) in order to utilise analytics and caching. See
[here](/clients/javascript#initialisation-options).

:::

Expand Down Expand Up @@ -61,7 +62,7 @@ flagsmith.init({
environmentID: '<YOUR_CLIENT_SIDE_ENVIRONMENT_KEY>',
// api:"http://localhost:8000/api/v1/" set this if you are self hosting, and point it to your API
cacheFlags: true, // stores flags in localStorage cache
enableAnalytics: true, // See https://docs.flagsmith.com/flag-analytics/ for more info
enableAnalytics: true, // See https://docs.flagsmith.com/flag-analytics/ for more info.
onChange: (oldFlags, params) => {
//Occurs whenever flags are changed
const { isFromServer } = params; //determines if the update came from the server or local cached storage
Expand Down Expand Up @@ -234,24 +235,24 @@ All function and property types can be seen

### Initialisation options

| Property | Description | Required | Default Value |
| ------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | -------: | -------------------------------------: |
| `environmentID: string` | Defines which project environment you wish to get flags for. _example ACME Project - Staging._ | **YES** | null |
| `onChange?: (previousFlags:IFlags, params:IRetrieveInfo, loadingState:LoadingState)=> void` | Your callback function for when the flags are retrieved `(previousFlags,{isFromServer:true/false,flagsChanged: true/false, traitsChanged:true/false})=>{...}` | **YES** | null |
| `onError?: (res:{message:string}) => void` | Callback function on failure to retrieve flags. `(error)=>{...}` | | null |
| `realtime?:boolean` | Whether to listen for [Real Time Flag events](/advanced-use/real-time-flags) | | false |
| `asyncStorage?:any` | Needed for cacheFlags option, used to tell the library what implementation of AsyncStorage your app uses, i.e. ReactNative.AsyncStorage vs @react-native-community/async-storage, for web this defaults to an internal implementation. | | null |
| `cacheFlags?: boolean` | Any time flags are retrieved they will be cached, flags and identities will then be retrieved from local storage before hitting the API (see cache options) | | null |
| `cacheOptions?: \{ttl?:number, skipAPI?:boolean\}` | A ttl in ms (default to 0 which is infinite) and option to skip hitting the API in flagsmith.init if there's cache available. | | \{ttl:0, skipAPI:false\} |
| `enableAnalytics?: boolean` | [Enable sending flag analytics](/advanced-use/flag-analytics.md) for getValue and hasFeature evaluations. | | false |
| `enableLogs?: boolean` | Enables logging for key Flagsmith events | | null |
| `defaultFlags?: {flag_name: {enabled: boolean, value: string,number,boolean}}` | Allows you define default features, these will all be overridden on first retrieval of features. | | null |
| `preventFetch?: boolean` | If you want to disable fetching flags and call getFlags later. | | false |
| `state?: IState` | Set a predefined state, useful for SSR / isomorphic applications. | | false |
| `api?: string` | Use this property to define where you're getting feature flags from, e.g. if you're self hosting. | | https://edge.api.flagsmith.com/api/v1/ |
| `eventSourceUrl?: string` | Use this property to define where you're getting real-time flag update events (server sent events) from, e.g. if you're self hosting. | | https://edge.api.flagsmith.com/api/v1/ |
| `identity?: string` | Specifying an identity will fetch flags for that identity in the initial API call. | **YES** | null |
| `traits?:Record<string, string or number or boolean>` | Specifying traits will send the traits for that identity in the initial API call. | **YES** | null |
| Property | Description | Required | Default Value |
| ------------------------------------------------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | -------: | ----------------------------------------------------: |
| `environmentID: string` | Defines which project environment you wish to get flags for. _example ACME Project - Staging._ | **YES** | null |
| `onChange?: (previousFlags:IFlags, params:IRetrieveInfo, loadingState:LoadingState)=> void` | Your callback function for when the flags are retrieved `(previousFlags,{isFromServer:true/false,flagsChanged: true/false, traitsChanged:true/false})=>{...}` | **YES** | null |
| `onError?: (res:{message:string}) => void` | Callback function on failure to retrieve flags. `(error)=>{...}` | | null |
| `realtime?:boolean` | Whether to listen for [Real Time Flag events](/advanced-use/real-time-flags) | | false |
| `AsyncStorage?:any` | Needed in certain frameworks cacheFlags and enableAnalytics options, used to tell the library what implementation of AsyncStorage your app uses, e.g. @react-native-community/async-storage, for web this defaults to an internal implementation. | | built in implementation for web, otherwise undefined. |
| `cacheFlags?: boolean` | Any time flags are retrieved they will be cached, flags and identities will then be retrieved from local storage before hitting the API (see cache options). Requires AsyncStorage to be accessible. | | null |
| `cacheOptions?: \{ttl?:number, skipAPI?:boolean\}` | A ttl in ms (default to 0 which is infinite) and option to skip hitting the API in flagsmith.init if there's cache available. | | \{ttl:0, skipAPI:false\} |
| `enableAnalytics?: boolean` | [Enable sending flag analytics](/advanced-use/flag-analytics.md) for getValue and hasFeature evaluations. | | false |
| `enableLogs?: boolean` | Enables logging for key Flagsmith events | | null |
| `defaultFlags?: {flag_name: {enabled: boolean, value: string,number,boolean}}` | Allows you define default features, these will all be overridden on first retrieval of features. | | null |
| `preventFetch?: boolean` | If you want to disable fetching flags and call getFlags later. | | false |
| `state?: IState` | Set a predefined state, useful for SSR / isomorphic applications. | | false |
| `api?: string` | Use this property to define where you're getting feature flags from, e.g. if you're self hosting. | | https://edge.api.flagsmith.com/api/v1/ |
| `eventSourceUrl?: string` | Use this property to define where you're getting real-time flag update events (server sent events) from, e.g. if you're self hosting. | | https://edge.api.flagsmith.com/api/v1/ |
| `identity?: string` | Specifying an identity will fetch flags for that identity in the initial API call. | **YES** | null |
| `traits?:Record<string, string or number or boolean>` | Specifying traits will send the traits for that identity in the initial API call. | **YES** | null |

### Available Functions

Expand Down
5 changes: 3 additions & 2 deletions docs/docs/clients/client-side/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ npm i flagsmith --save

:::tip

The ReactNative SDK shares the exact same implementation of Flagsmith, however, the defaults for some underlying
libraries (e.g. AsyncStorage) use React Native compatible implementations.
The React Native SDK shares the exact same implementation of Flagsmith, however, requires an implementation of
AsyncStorage to be provided (e.g. @react-native-community/async-storage) in order to utilise analytics and caching. See
[here](/clients/javascript#initialisation-options).

:::

Expand Down

0 comments on commit 9753e66

Please sign in to comment.