Link Search Menu Expand Document

Installation

This page explains how to add AppFlags to a JavaScript application.

Add the SDK to your project

The SDK can be added to your project as an NPM module or from a CDN.

  • Install the appflags npm package and save it to your package.json file:

    npm install appflags --save
    

    Import AppFlags in your JavaScript files:

    import AppFlags from "appflags";
    
  • Add the following script tag to the <head> section of your site.

    <script src="https://unpkg.com/appflags@1.0.0/bundle/appflags.js"></script>
    

    Loading this script adds the global variable AppFlags to your site.

Initialize the client

When to initialize

You should initialize the AppFlags client as soon as your application launches. The client initialization is async and will not block your application from loading.

The AppFlags client makes a request to our servers to initialize, which takes around 100ms. Initializing the client when the application launches ensures that you can utilize feature flags without any noticeable delay to your users.

Providing a user key

You need to provide a unique key for the user when initializing the AppFlags client. You should use an identifier that will not change, like an account ID or email address.

The AppFlags client determines which variation a user receives based on their key, so it is important that each user has a unique and unchanging key.

Client key

The AppFlags client is initialized with a client key, which configures the client for the appropriate environment in your account. For more information see SDK client keys.

Each environment (e.g. production or staging) in your account has a different client key. Ensure you are using the correct client key corresponding to your application’s environment.

Code sample

const user = {
    key: "UNIQUE_USER_KEY"  // e.g. email, account id, etc
}
AppFlags.initialize("YOUR_CLIENT_KEY", user);

© 2020 AppFlags