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/pde

v2.31.0

Published

> An adapter based tool to handle feature toggles, progressive rollouts and A/B Testing services in our products

Downloads

9,655

Readme

sui-pde

An adapter based tool to handle feature toggles, progressive rollouts and A/B Testing services in our products

Installation

$ npm install @s-ui/pde

About

This is a tool that abstracts from:

  • PDE tools like Optimizely, Houston, Target, Unleash, ...
  • Integration with third party analytics tools like Segment
  • User id management
  • User consents management
  • Common audiences and segments

In order to abstract from progressive delivery and experimentation (PDE) tools like Optimizely, sui-pde provides a JS class which requires an adapter that connects directly to one of those tools. We did implement the Optimizely Full Stack adapter.

Optimizely adapter

React context

Setup the tool's own react context in your context factory like this:

import {PDE, PdeContext} from '@s-ui/pde'
import OptimizelyAdapter from '@s-ui/pde/lib/adapters/optimizely'

// all options here https://docs.developers.optimizely.com/full-stack/docs/initialize-sdk-javascript-node, but for now only 3 of them are available
const optimizelyInstance = OptimizelyAdapter.createOptimizelyInstance({
  sdkKey: MY_API_KEY,  // optimizely sdk api key
  options, // optional, datafileOptions
  datafile // optional
})

const optimizelyAdapter = new OptimizelyAdapter({
  optimizely: optimizelyInstance,
  userId: // mandatory,
  hasUserConsents,  // if false, the user won't be part of the A/B test,
  applicationAttributes: {   // optional, global application attributes that must be send on every experiment activation
    site: 'coches.net',
    environment: 'development'
  }
})

const pde = new PDE({
  adapter: optimizelyAdapter,
  hasUserConsents: true // Kept because of legacy reasons, pass it by the OptimizelyAdapter constructor
})

// app.js
<PdeContext.Provider value={{pde}}>
  // children
</PdeContext.Provider>

SSR considerations

When client-side rendering, sui-pde will load the datafile saved as window.__INITIAL_CONTEXT_VALUE__.pde as initial datafile. Therefore, you'll need to inject the output of the pde.getInitialContextData() function in your html when server side rendering.

Feature Test

Feature tests are similar to A/B/n tests that allow you to control whether for each variation the associated feature is on or off via feature flags (aka feature toggles). It also allows you to control the feature variable values for the various variables associated with the feature.

The useDecision hook retrieves the result for a given decision, based on logic from the decision-making tool you are using (e.g., Optimizely).

import {useDecision} from '@s-ui/pde'

function Component() {
  const decision = useDecision('feature_test', {})

  return (
    <>
      {decision.enabled && <p>My feature is enabled</p>}
      {!decision.enabled && <p>My feature is disabled</p>}
      {decision.variationKey === 'variantion_a' && <p>Current Variation</p>}
      {decision.variationKey === 'variantion_b' && <p>Better Variation</p>}
    </>
  );
}

You can also use the Decision component:

import {Decision} from '@s-ui/pde'

const MyComponent = () => {
  return (
    <Decision name="feature_test">
      {({enabled}) => enabled ? <p>My feature is enabled</p> : <p>My feature is disabled</p>}
    </Decision>
  )
}

And the function to call elsewhere, like getInitialProps:

import {getDecision} from '@s-ui/pde'

Page.getInitialProps = async ({context}) => {
  const {decide} = getDecision(pde)
  const {enabled} = decide('ff_web_my_flag')
}

Attributes

You can pass additional attributes to refine your decision logic:

import {useDecision} from '@s-ui/pde'

const MyComponent = () => {
  const {enabled, variationKey} = useDecision('feature_test', {
    attributes: {
      isLoggedIn: true
    }
  })
}

Forcing a decision

You can force specific decision outcomes during testing by adding a query parameter.

  • http://www.fotocasa.es/es?suipde_example=on will enable the example feature test
  • http://www.fotocasa.es/es?suipde_example=off will disable the example feature test
  • http://www.fotocasa.es/es?suipde_example=variation_a will enable the example feature test and will force the variation variation_a