@hackler/javascript-sdk
v11.37.1
Published
JavaScript SDK For Hackle
Downloads
20,004
Maintainers
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);