|
| 1 | +# API Reference (Remix) |
| 2 | + |
| 3 | +## createAbby |
| 4 | + |
| 5 | +### Parameters |
| 6 | + |
| 7 | +The `createAbby` function takes an object as a parameter. The object can contain the following properties: |
| 8 | + |
| 9 | +| Name | Type | Required | Description | details | |
| 10 | +| ------------------ | -------- | :------: | ------------------------------------------------------------------ | --------------------- | |
| 11 | +| projectId | `string` | ✅ | The ID of your project in Abby | - | |
| 12 | +| apiUrl | `string` | | The URL of the Abby API. Defaults to the hosted version | - | |
| 13 | +| currentEnvironment | `string` | ✅ | The current environment of your application | [link](/environments) | |
| 14 | +| tests | `object` | | An object containing your defined A/B Tests | - | |
| 15 | +| flags | `array` | | An array containing your defined Feature Flags | - | |
| 16 | +| remoteConfig | `object` | | An object containing the name of your remote config and their type | - | |
| 17 | +| settings | `object` | | An object with additional settings for Abby | - | |
| 18 | + |
| 19 | +#### tests |
| 20 | + |
| 21 | +The tests property is an object containing your defined A/B Tests. You probably want to use the Copy Button in your dashboard to copy the tests object. |
| 22 | +They keys of the object represent the names of your predefined A/B tests. The values are objects containing the following properties: |
| 23 | + |
| 24 | +| Name | Type | Required | Description | |
| 25 | +| -------- | --------------- | :------: | ------------------------------------------------------- | |
| 26 | +| variants | `Array<string>` | ✅ | An array of strings containing the variants of the test | |
| 27 | + |
| 28 | +##### Example |
| 29 | + |
| 30 | +```ts |
| 31 | +const abby = createAbby({ |
| 32 | + // ... your config |
| 33 | + tests: { |
| 34 | + "test-abtest": { |
| 35 | + variants: ["control", "variant-a", "variant-b"], |
| 36 | + }, |
| 37 | + }, |
| 38 | +}); |
| 39 | +``` |
| 40 | + |
| 41 | +#### flags |
| 42 | + |
| 43 | +The flags property is an array containing your defined Feature Flags. You probably want to use the Copy Button in your dashboard to copy the flags array. |
| 44 | + |
| 45 | +##### Example |
| 46 | + |
| 47 | +```ts |
| 48 | +const abby = createAbby({ |
| 49 | + // ... your config |
| 50 | + flags: ["test-flag"], |
| 51 | +}); |
| 52 | +``` |
| 53 | + |
| 54 | +#### settings |
| 55 | + |
| 56 | +The settings property is an object containing additional settings for Abby. The following properties are available: |
| 57 | + |
| 58 | +- `flags.defaultValue`: Allows you to set a general default boolean value for each Feature Flag type. |
| 59 | + |
| 60 | + ```json |
| 61 | + flags: { |
| 62 | + defaultValue: false, |
| 63 | + }, |
| 64 | + ``` |
| 65 | + |
| 66 | +- `flags.devOverrides`: An object containing the values of feature flags in development mode. The keys of the object represent the names of the flags. |
| 67 | + |
| 68 | +- `remoteConfig.defaultValue`: Allows you to set default values for the possible Remote Config types. |
| 69 | + |
| 70 | + ```json |
| 71 | + remoteConfig: { |
| 72 | + defaultValues: { |
| 73 | + String: "", |
| 74 | + Number: 0, |
| 75 | + JSON: {}, |
| 76 | + }, |
| 77 | + }, |
| 78 | + ``` |
| 79 | + |
| 80 | +- `remoteConfig.devOverrides`: An object containing the values of Remote Configuration variables in development mode. |
| 81 | + The keys of the object represent the names of the flags. The value must be assignable to the type of the variable. |
| 82 | + |
| 83 | +### Return Values |
| 84 | + |
| 85 | +#### useAbby |
| 86 | + |
| 87 | +`useAbby` is a react hook that used to access the value of an A/B Test. |
| 88 | +Recurring users will always get the same value for a test. |
| 89 | +New users will get a random value for a test depending on the defined weights |
| 90 | + |
| 91 | +##### Parameters |
| 92 | + |
| 93 | +- `name`: The name of the test or flag, needs to be one of the defined tests. |
| 94 | +- `lookupObject`: An optional lookup object to automatically map the active variant to a custom value. |
| 95 | + |
| 96 | +##### Return Values |
| 97 | + |
| 98 | +- `variant` : The variant of the test or the looked up value if you provided a `lookupObject` |
| 99 | + |
| 100 | +- `onAct`: A function to call when the user performs an action associated with the test _Type: `function`_ |
| 101 | + |
| 102 | +#### useFeatureFlag |
| 103 | + |
| 104 | +`useFeatureFlag` is a react hook that used to access the value of a Feature Flag. |
| 105 | + |
| 106 | +##### Parameters |
| 107 | + |
| 108 | +The name of the flag, needs to be one of the defined flags. |
| 109 | + |
| 110 | +##### Return Value |
| 111 | + |
| 112 | +The value of the flag _Type: `boolean`_ |
| 113 | + |
| 114 | +#### useFeatureFlags |
| 115 | + |
| 116 | +`useFeatureFlags` is a React hook that is used to access all existing feature flags. |
| 117 | + |
| 118 | +##### Parameters |
| 119 | + |
| 120 | +The name of the flag, needs to be one of the defined flags. |
| 121 | + |
| 122 | +##### Return Value |
| 123 | + |
| 124 | +An Array of all feature flags. Includes the name and the value. The value will be a boolean. |
| 125 | + |
| 126 | +#### useRemoteConfig |
| 127 | + |
| 128 | +`useRemotConfig` is a React hook that is used to access the value of a Remote Configuration variable. |
| 129 | + |
| 130 | +##### Parameters |
| 131 | + |
| 132 | +The name of the Remote Configuration variable, which needs to be one of the keys in your `remoteConfig` object in your `abby.config.ts`. |
| 133 | + |
| 134 | +##### Return Value |
| 135 | + |
| 136 | +The current value of the Remote Configuration variable. The type will be according to the specified type in the `abby.config.ts` |
| 137 | + |
| 138 | +#### useRemoteConfigVariables |
| 139 | + |
| 140 | +`useRemoteConfigVariables` is a React hook that is used to access all existing Remote Configuration variables. |
| 141 | + |
| 142 | +##### Parameters |
| 143 | + |
| 144 | +None |
| 145 | + |
| 146 | +##### Return Value |
| 147 | + |
| 148 | +An Array of all remote config variables. Includes the name and the value. The type will be according to the specified type in the `abby.config.ts` |
| 149 | + |
| 150 | +#### AbbyProvider |
| 151 | + |
| 152 | +A react component to wrap your application. |
| 153 | + |
| 154 | +##### Props |
| 155 | + |
| 156 | +- `children`: The children of the component |
| 157 | +- `initialData (optional)`: The data (weights, tests, etc). If not provided, the data will be fetched on the client. |
| 158 | + |
| 159 | +#### getFeatureFlagValue |
| 160 | + |
| 161 | +`getFeatureFlagValue` is a function to access the value of a feature flag. This can be called in a non-react scope (Regular Typescript, Edge Functions and API Routes) |
| 162 | + |
| 163 | +##### Parameters |
| 164 | + |
| 165 | +The name of the test or flag, needs to be one of the defined flags. |
| 166 | + |
| 167 | +##### Return Value |
| 168 | + |
| 169 | +The value of the flag _Type: `boolean`_ |
| 170 | + |
| 171 | +#### getRemoteConfig |
| 172 | + |
| 173 | +`getRemoteConfig` is a function to access the value of a Remote Configuration variable. This can be called in a non-react scope (Regular Typescript, Edge Functions and API Routes) |
| 174 | + |
| 175 | +##### Parameters |
| 176 | + |
| 177 | +The name of the Remote Configuration variable, which needs to be one of the keys in your `remoteConfig` object in your `abby.config.ts`. |
| 178 | + |
| 179 | +##### Return Value |
| 180 | + |
| 181 | +The current value of the Remote Configuration variable. The type will be according to the specified type in the `abby.config.ts` |
| 182 | + |
| 183 | +#### getABTestValue |
| 184 | + |
| 185 | +`getABTestValue` is a function to access the users variant of an A/B Test. This can be called in a non-react scope. |
| 186 | +If the user is new, a random variant will be generated based on the weights, persisted in a cookie and returned. |
| 187 | +Otherwise the variant will be read from the cookie and returned. |
| 188 | + |
| 189 | +##### Parameters |
| 190 | + |
| 191 | +- `testName`: The name of the test, needs to be one of the defined tests. |
| 192 | +- `lookupObject`: An optional lookup object to automatically map the active variant to a custom value. |
| 193 | + |
| 194 | +##### Return Values |
| 195 | + |
| 196 | +The variant of the test or the looked up value if you provided a `lookupObject` |
| 197 | + |
| 198 | +#### \_\_abby\_\_ |
| 199 | + |
| 200 | +`__abby__` is the Abby instance. It can be used to access the data of the current user. |
| 201 | +In most cases you will not need to use this. |
| 202 | + |
| 203 | +#### withDevtools |
| 204 | + |
| 205 | +`withDevtools` is a higher order function to wrap the Devtools from [`@tryabby/devtools`](/devtools) for usage within Reacts. |
| 206 | + |
| 207 | +##### Parameters |
| 208 | + |
| 209 | +The Devtools component from `@tryabby/devtools` |
| 210 | + |
| 211 | +##### Example |
| 212 | + |
| 213 | +```jsx |
| 214 | +import { AbbyDevTools } from "@tryabby/devtools"; |
| 215 | +export const AbbyDevtools = withDevtools(AbbyDevTools); |
| 216 | +``` |
| 217 | + |
| 218 | +#### getAbbyData |
| 219 | + |
| 220 | +A function used to get the required data to server side render the application with Abby. |
| 221 | +This should be called in the `loader` function one of your routes or inside of the root. |
| 222 | + |
| 223 | +##### Example |
| 224 | + |
| 225 | +```jsx |
| 226 | +import { AbbyProvider, getAbbyData } from "../lib/abby"; |
| 227 | + |
| 228 | +export const loader = async (ctx) => { |
| 229 | + return json({ |
| 230 | + ...(await getAbbyData(ctx)), |
| 231 | + }); |
| 232 | +}; |
| 233 | +``` |
0 commit comments