@kiwicom/darwin
AB testing tool 2.0. :monkey:
Last updated 9 days ago by oreqizer .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @kiwicom/darwin 
SYNC missed versions from official npm registry.

Darwin

Our shiny new AB testing tool! :monkey:

yarn add @kiwicom/darwin

API

Download the test configuration file. On a request take:

  • the config object
  • request's userAgent
  • request's language code in ISO 639-1 with the country postfix — xx-XX
  • some salt — usually user's ID

getConfigTest

Feed the config object function together with the userAgent, language and the salt:

import { Config, Test, getConfigTest } from "@kiwicom/darwin";

const config: Config = {/* ... */};

// Returns either a `Test` object, or `null` for reference group or no active test
const test: Test | null = getConfigTest({
  config,
  userAgent: req.headers["User-Agent"],
  language: "en-GB",
  salt: "some-user-id-string",
});

This object has no functions and thus is serializable — send it to the client encoded as JSON.

DarwinProvider

Server:

Use the test object in your provider. Pass it a server prop to avoid session-related side effects:

import { DarwinProvider } from "@kiwicom/darwin";

// ...
return ReactDOMServer.renderToString(
  <DarwinProvider test={test} features={features} server>
    <Root />
  </DarwinProvider>
);

Client:

Take the test and features sent from the server and feed it to the provider.

Avoid sending the whole downloaded configuration file to the client to save bundle size and avoid leaking test information.

import { DarwinProvider } from "@kiwicom/darwin";

const { test, features } = window.__DARWIN__;

// ...
ReactDOM.hydrate(
  <DarwinProvider test={test} features={features}>
    <Root />
  </DarwinProvider>,
  document.getElementById("root"),
);

useTest hook

Checks if the queried test is running and returns its value, null for reference group.

It also saves the queried test to session data if it returned a non-null result.

import { useTest } from "@kiwicom/darwin";

const version = useTest("valdoge");
if (version === "g") {
  // ...
}

You can then retrieve the session data with loadSession;

useFeature hook

Tells you if a feature is on / off.

import { useFeature } from "@kiwicom/darwin";

const hasNavbar = useFeature("navbar");

loadSession

Loads the session test data:

  • type Test if a test is active
  • null for reference group

Only use on the client!

Useful mainly for logging.

import { loadSession } from "@kiwicom/darwin";

logger.log("Stuff has happened", {
  ab: loadSession(),
});

Development

Clone and yarn.

For updating dev stuff, run yarn reactizer update --app lib and revert any undesired changes.

Commits

Follow @commitlint/conventional with a mandatory scope of:

  • dev for non-production things like CI or tests
  • types for adjusting .js.flow files or type signatures
  • src for library changes, features, patches...

Examples:

  • docs(dev): document commits
  • feat(src): add new hook
  • chore(types): new spread syntax

Release

  • yarn release
  • yarn publish

License

MIT

Current Tags

  • 0.0.12                                ...           latest (9 days ago)

11 Versions

  • 0.0.12                                ...           9 days ago
  • 0.0.11                                ...           6 months ago
  • 0.0.10                                ...           9 months ago
  • 0.0.9                                ...           9 months ago
  • 0.0.8                                ...           9 months ago
  • 0.0.7                                ...           9 months ago
  • 0.0.6                                ...           9 months ago
  • 0.0.5                                ...           9 months ago
  • 0.0.3                                ...           9 months ago
  • 0.0.1                                ...           9 months ago
  • 0.0.0                                ...           9 months ago

Copyright 2014 - 2016 © taobao.org |