Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@hackler/javascript-sdk

hackler9.2kISC11.44.0TypeScript support: included

JavaScript SDK For Hackle

hackle, sdk, abtest, feature flags

readme

Hackle JavaScript SDK

Install

npm install @hackler/javascript-sdk --save
yarn add @hackler/javascript-sdk

Usage

Install & Decide the variation

const http = require("http");
const Hackle = require("@hackler/javascript-sdk");

const hackleClient = Hackle.createInstance("YOUR_SDK_KEY");

http.createServer((req, res) => {
    const user = {
      id: USER_ID
    }   
    const variation = hackleClient.variation(AB_TEST_KEY, user);

    if (variation === "A") {
      // AS-IS Code
    } else if (variation === "B") {
      // TO-BE Code
    }

    res.end(`Hello ${variation}!`)
}).listen(8080)

Records the event

hackleClient.track(EVENT_KEY, user);

or

const event = {
  key: EVENT_KEY,
  value: 5000,
  properties: {
    app_version: "1.0.0",
    first_paying: false,
    item_count: 5
  }
}
hackleClient.track(event, user);