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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@embeddables/experiments

v0.4.2

Published

Experiment assignment SDK for Embeddables funnels.

Readme

@embeddables/experiments

TypeScript-first client for sticky experiment assignment before render. Composes on @embeddables/core and calls the Embeddables experiments API when a configured experiment has no stored assignment yet.

Install

npm install @embeddables/experiments @embeddables/core

Quick start

import { initEmbeddables } from '@embeddables/core'
import { initExperiments } from '@embeddables/experiments'

const experimentsConfig = [
  {
    id: '00000000-0000-4000-8000-000000000099',
    key: 'hero_test',
    variants: ['control', 'variant_b'] as const,
  },
] as const

const embeddables = initEmbeddables({
  projectId: '00000000-0000-4000-8000-000000000001',
  publishableKey: 'pk_live_…',
  forms: [],
  experiments: experimentsConfig,
})

const experiments = initExperiments({ core: embeddables })

const hero = experiments.initExperiment({
  experimentId: '00000000-0000-4000-8000-000000000099',
})
const variantKey = await hero.getAssignedVariantKey()
const variantTitle = await hero.getAssignedVariantTitle()

getAssignedVariantKey() is typed from the configured variant list for that experiment id, so invalid variant keys fail at compile time. The first call for a missing assignment fetches from the API, persists locally, and returns the variant key; later calls read the sticky value without another network round-trip.

Server (SSR)

import { initEmbeddablesServer } from '@embeddables/core/server'
import { initExperimentsServer } from '@embeddables/experiments/server'

const server = initEmbeddablesServer({
  ...config,
  cookies: { get: (key) => req.cookies[key] ?? null },
})

const experiments = initExperimentsServer({ server })

const hero = experiments.initExperiment({
  experimentId: '00000000-0000-4000-8000-000000000099',
})
const variantKey = await hero.getAssignedVariantKey()

Sticky assignments are read from request cookies. To pre-seed the client with the variant the server resolved (so the first client render is synchronous and hydration doesn't flash), pass it as serverAssignments to initExperiments or experiments({ serverAssignments }) on the client.

React

Install the peer dependency:

npm install react

Register experiments through EmbeddablesProvider's modules prop, then use read-only hooks in the same tree.

Example:

import { EmbeddablesProvider } from '@embeddables/core/react'
import {
  experiments,
  useExperiment,
} from '@embeddables/experiments/react'
import { config } from './embeddables/_dist/config.ts'

function Hero() {
  // No type arguments: `em build` registers the experiment list for you.
  const { assignedVariantKey, assignedVariantTitle, status } = useExperiment({
    experimentId: '00000000-0000-4000-8000-000000000099',
  })

  if (status === 'pending') return <p>Loading…</p>

  return <h1>{assignedVariantTitle ?? assignedVariantKey}</h1>
}

function App() {
  return <Hero />
}

export function Root() {
  return (
    <EmbeddablesProvider
      config={config}
      modules={[experiments()]}
      experiments={{
        serverAssignments: { '00000000-0000-4000-8000-000000000099': 'control' },
      }}
    >
      <App />
    </EmbeddablesProvider>
  )
}

Example (CLI-generated modules):

import { modules } from './embeddables/_dist/modules.ts'

<EmbeddablesProvider
  config={config}
  modules={modules}
  experiments={{ serverAssignments }}
>
  <App />
</EmbeddablesProvider>
  • Pass serverAssignments through the provider's experiments prop for SSR hydration.
  • When analytics() is enabled, exposure is tracked automatically. Set excludeAnalyticsInModules={['experiments']} to keep assignment working while turning that tracking off.
  • useExperiment returns { assignedVariantKey, assignedVariantTitle, status, error }, with status in pending | ready | error. Passing the same serverAssignments used on the server makes the hook resolve synchronously on the first render — no variant flash across SSR hydration.

The order of modules does not matter: the provider initializes Analytics before Experiments on its own.

Which experiments are configured and which the page renders

Tools that sit on top of a page (such as @embeddables/workbench) read these from the client:

  • listExperiments() returns every configured experiment as { id, key, title, variants: [{ key, title }] }.
  • readRenderedExperimentIds() returns the ids a mounted useExperiment renders right now. An id leaves when its last hook unmounts. initExperiment alone does not add one.
  • subscribeRenderedExperiments(listener) calls listener whenever that set changes and returns an unsubscribe function.

Storage

Assignments are keyed by experiment id, not experiment key.

| Store | Key pattern | Value | | ----- | ----------- | ----- | | localStorage | EMBEDDABLES--{projectId}--EXPERIMENT-DATA | JSON { [experimentId]: variantKey } | | Cookie (each) | EMBEDDABLES--{projectId}--EXP--{experimentId} | variant key string |

Cookie values win over localStorage for the same experiment id.

Analytics

To track assignment events, install @embeddables/analytics and pass initAnalytics({ core }) as analytics on initExperiments.

import { initAnalytics } from '@embeddables/analytics'

const analytics = initAnalytics({ core: embeddables })

const experiments = initExperiments({
  core: embeddables,
  analytics,
})

When analytics is present, each newly fetched assignment emits one experiment:assigned event. Sticky assignments already in storage are not tracked again. A rejected trackEvent() never fails getAssignedVariantKey() — the assignment is persisted before tracking runs.

Options

initExperiments

| Option | Purpose | | ------ | ------- | | core | Initialized @embeddables/core instance (required) | | analytics | Optional analytics client for event tracking only | | serverAssignments | Pre-seed { [experimentId]: variantKey } for SSR (React: pass via experiments({ serverAssignments })) |

initExperimentsServer

| Option | Purpose | | ------ | ------- | | server | Initialized @embeddables/core/server instance (required) | | analytics | Optional analytics client for event tracking only | | cookieStorage | Optional override to read sticky assignments from a source other than request cookies |

Assigning on demand

useExperiment assigns as soon as it renders. When the exposure should be booked at a specific step instead, use useAssignExperiment:

import { useAssignExperiment } from '@embeddables/experiments/react'

function StartTrial() {
  const { assignExperiment, isPending } = useAssignExperiment()

  return (
    <button
      disabled={isPending}
      onClick={() => {
        void assignExperiment({ experimentId: 'exp-hero' }).then((assigned) => {
          if (assigned) console.log(assigned.variantKey, assigned.variantTitle)
        })
      }}
    >
      Start
    </button>
  )
}

The assignment is sticky, so a later useExperiment({ experimentId: 'exp-hero' }) reads it back without another request. assignExperiment resolves to undefined while the experiments module is not registered, and rejects when the request fails.