Reference
Svelte

API Reference (Svelte)

createAbby

Parameters

The createAbby function takes an object as a parameter. The object can contain the following properties:

NameTypeRequiredDescriptiondetails
projectIdstringThe ID of your project in Abby-
apiUrlstringThe URL of the Abby API. Defaults to the hosted version-
currentEnvironmentstringThe current environment of your applicationlink
testsobjectAn object containing your defined A/B Tests-
flagsarrayAn array containing your defined Feature Flags-
remoteConfigobjectAn object containing the name of your remote config and their type-
settingsobjectAn object with additional settings for Abby-

tests

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. They keys of the object represent the names of your predefined A/B tests. The values are objects containing the following properties:

NameTypeRequiredDescription
variantsArray<string>An array of strings containing the variants of the test
Example
const abby = createAbby({
  // ... your config
  tests: {
    "test-abtest": {
      variants: ["control", "variant-a", "variant-b"],
    },
  },
});

flags

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.

Example
const abby = createAbby({
  // ... your config
  flags: ["test-flag"],
});

settings

The settings property is an object containing additional settings for Abby. The following properties are available:

  • flags.defaultValue: Allows you to set a general default boolean value for each Feature Flag type.

    flags: {
      defaultValue: false,
    },
  • flags.devOverrides: An object containing the values of feature flags in development mode. The keys of the object represent the names of the flags.

  • remoteConfig.defaultValue: Allows you to set default values for the possible Remote Config types.

    remoteConfig: {
      defaultValues: {
        String: "",
        Number: 0,
        JSON: {},
      },
    },
  • remoteConfig.devOverrides: An object containing the values of Remote Configuration variables in development mode. The keys of the object represent the names of the flags. The value must be assignable to the type of the variable.

Return Values

useAbby

useAbby is a function providing acces to a store that is used to access the value of an A/B Test. Recurring users will always get the same value for a test. New users will get a random value for a test depending on the defined weights

Parameters
  • testName: The name of the test or flag, needs to be one of the defined tests.
  • lookupObject: An optional lookup object to automatically map the active variant to a custom value.
Return Values
  • variant: Store providing the variant of the test or the looked up value if you provided a lookupObject

  • onAct: A function to call when the user performs an action associated with the test Type: function

useFeatureFlag

useFeatureFlag is a function providing access to a store that is used to access the value of a Feature Flag.

Parameters

The name of the flag, needs to be one of the defined flags.

Return Value

A store providing the value of the flag Type: boolean

useRemoteConfig

useRemoteConfig is a function providing access to a store that is used to access the value of a Remote Configuration variable.

Parameters

The name of the Remote Configuration variable. This needs to be one of the defined keys in your abby.config.ts.

Return Value

A store providing the value of the Remote Configuration variable. The type will be looked up from your abby.config.ts.

AbbyProvider

A svelte component to wrap your application.

Props
  • children: The children of the component
  • initialData (optional): The data (weights, tests, etc). If not provided, the data will be fetched on the client.

getFeatureFlagValue

getFeatureFlagValue is a function to access the value of a feature flag. This can be called in a non-svelte scope (Regular Typescript, Edge Functions and API Routes)

Parameters

The name of the test or flag, needs to be one of the defined flags.

Return Value

The value of the flag Type: boolean

getRemoteConfig

getRemoteConfig is a function to access the value of a Remote Configuration variable. This can be called in a non-svelte scope (Regular Typescript, Edge Functions and API Routes)

Parameters

The name of the Remote Configuration variable, which needs to be one of the keys in your remoteConfig object in your abby.config.ts.

Return Value

The current value of the Remote Configuration variable. The type will be according to the specified type in the abby.config.ts

getABTestValue

getABTestValue is a function to access the users variant of an A/B Test. This can be called in a non-react scope. If the user is new, a random variant will be generated based on the weights, persisted in a cookie and returned. Otherwise the variant will be read from the cookie and returned.

Parameters
  • testName: The name of the test, needs to be one of the defined tests.
  • lookupObject: An optional lookup object to automatically map the active variant to a custom value.
Return Values

The variant of the test or the looked up value if you provided a lookupObject

__abby__

__abby__ is the Abby instance. It can be used to access the data of the current user. In most cases you will not need to use this.

withDevtools

withDevtools is a function providing a svelte component to enable the Devtools. The Devtools need to be within the 'AbbyProvider'.

Parameters

The Devtools component from @tryabby/devtools

Example
import { AbbyDevTools } from "@tryabby/devtools";
export const AbbyDevtools = withDevtools(AbbyDevTools);

withAbby

A function that enables Server Side Rendering within Sveltekit If you use this in your layout.server.ts, all occurances of useFeatureFlag will be SSR'd.

Example
// layout.server.ts
import { abby } from "$lib/abby";
 
export const load = abby.withAbby();

getABResetFunction

This is a function which returns a function that can be used to reset the stored variant for the current user. This means the cookie will be deleted and the user will get a new variant on the next page load.

Parameters

The name of the test, needs to be one of the defined tests.