npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@s-ui/abtesting-hooks

v1.12.0

Published

Useful hooks to be used for AB Testing.

Downloads

1,233

Readme

AbtestingHooks

Useful hooks to be used for AB Testing.

Installation

$ npm install @s-ui/abtesting-hooks --save

Available hooks

useExperiment

Depending on the params, this hook can assume the following two different roles.

⎡🧪👂⎦ Experiment Context Consumer

const {isActive, isDefault, isVariation, ...} = useExperiment('myexperiment')

When it's used in some of the children of OptimizelyXExperiment (down in the rendering hierarchy) and only a name is given as a param, it just receives the context from an upper experiment component in the hierarchy.

See OptimizelyXExperiment's readme to see advanced examples about consuming the experiment context: Advanced Usage → Experiment Context.

⎡🧪⚙️⎦ Experiment Core Runner

const {isActive, isDefault, isVariation, ...} = useExperiment({
  name: 'myexperiment',
  experimentId: 40000,
  variations: [
    {id: 700000, isDefault: true},
    {id: 700001},
    {id: 700002}
  ]
})

When experimentId and variations are given as params, it runs an experiment itself so a decision from Optimizely is received and experiment data returned by the hook is updated accordingly.

It behaves in a similar way OptimizelyXExperiment does because they share the same core. The only differences are:

  • It's a hook, not a component, so it's not limited to be used within the render nor having specific effect over a concrete area of the render.
  • The response from Optimizely causes an update of the returned experiment data, not a render swapping which sometimes leads to undesired reference losings in the DOM.
  • OptimizelyXExperiment performs a render task for each variation, so you may have performance gainings by using the hook instead (especially for huge experiments).

Also, you may be wondering how to provide experiment context in order to be consumed down in the render hierarchy when the experiment is ran by the hook. Well, you can just feed the OptimizelyXExperiment component with the experiment data, and it will only act as a context provider:

// Run experiment
const experimentData = useExperiment({
  name: 'myexperiment',
  experimentId: 40000,
  variations: [
    {id: 700000, isDefault: true},
    {id: 700001},
    {id: 700002}
  ]
})

// Use experimentData for anything you like
const {isActive, isDefault, isVariation, ...} = experimentData

// Wrap within OptimizelyXExperiment any area of the render you'd like to
// provide experiment context for.
return (
  <OptimizelyXExperiment feed={experimentData}>
    ...
    All the components rendered here are reached by the experiment context,
    which can be consumed by `useExperiment('myexperiment')` as well.
    ...
  </OptimizelyXExperiment>
)

To learn more about the experiment experience and how the core works, please read OptimizelyXExperiment's readme since that is already well covered there.

Find full description and more examples in the demo page.