@hackler/react-sdk
TypeScript icon, indicating that this package has built-in type declarations

11.32.1 • Public • Published

Hackle React SDK

Install

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

Usage

initialize

import { createInstance, HackleProvider } from "@hackler/react-sdk";

const hackleClient = createInstance("YOUR_SDK_KEY")
const user = {
  id: "ae2182e0", 
  properties: {
    app_version: "1.0.1",
    age: 23,
    paying_customer: true
  } 
}
ReactDOM.render(
  <HackleProvider hackleClient={hackleClient} user={user} timeout={1000}>
    <YourApp />
  </HackleProvider>,
  document.getElementById('root')
);

Decide the variation

function App() {
  return (
    <HackleExperiment experimentKey={42}>
      <HackleVariation variation={"A"}>
        <OldBlueButton />
      </HackleVariation>
      <HackleVariation variation={"B"}>
        <NewRedButton />
      </HackleVariation>
    </HackleExperiment>
  )
}

Records the event

const track = useTrack()
const event = {
  key: "purchase",
  value: 5000,
  properties: {
    first_paying: false,
    item_count: 5
  }
}

<button onClick={() => track(event)}>Purchase</button>

Readme

Keywords

Package Sidebar

Install

npm i @hackler/react-sdk

Weekly Downloads

2,410

Version

11.32.1

License

ISC

Unpacked Size

351 kB

Total Files

30

Last publish

Collaborators

  • hackler