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

nuxt-ab-segment

v5.1.1

Published

NuxtJS module for A/B testing with Segment Analytics

Readme

Table of contents

Main features

  • Run multiple experiments simultaneously
  • TypeScript support
  • Cookies to persist variants across users
  • Force a specific variant via url or param. E.g. url?abs_experiment-x=1 or this.$abtest('experiment-x', true, true, 1);
  • Prevent automatic reporting of a/b test analytics. E.g. this.$abtest('experiment-x', true, false);
  • Avoid activating the a/b test anywhere. E.g. this.$abtest('experiment-x', false);
  • Disable all a/b tests by cookie (abs_disabled=1), which is useful for E2E tests in CI/CD pipelines

Dependencies

Setup

  1. Add nuxt-ab-segment dependency to your project:
npm install nuxt-ab-segment
  1. Add nuxt-ab-segment module and configuration to nuxt.config.js:
export default {
  // ...other config options
  modules: ["nuxt-ab-segment"];
  abSegment: {
    event: "AB Test", // optional
    experiments: '~/experiments.js', // optional
    debug: process.env.NODE_ENV !== 'production', // optional
  }
}
  1. Create the experiments.js in project's root with an array of your experiments. An example:
/**
 * {
 *  name: string; A name to identify the experiment on this.$abtest('NAME_HERE')
 *  maxAgeDays: number; Number of days to persist the cookie of user's active variant
 *  variants: number[] | Experiment[]; An array of variant weights or an array of nested experiments.
 * }
 */
module.exports = [
  {
    name: "experiment-x",
    maxAgeDays: 15,
    variants: [50, 50],
  },
  {
    name: "experiment-y", // Weights will be automatically calculated [50, 50]
    maxAgeDays: 15,
    variants: [
      {
        name: "parent-1", // Weights will be automatically calculated [34, 33, 33]
        maxAgeDays: 15,
        variants: [
          {
            name: "children-1",
            maxAgeDays: 15,
            variants: [50, 50],
          },
          {
            name: "children-2",
            maxAgeDays: 15,
            variants: [50, 50],
          },
          {
            name: "children-3",
            maxAgeDays: 15,
            variants: [50, 50],
          },
        ],
      },
      {
        name: "parent-2",
        maxAgeDays: 15,
        variants: [50, 50],
      }, 
    ],
  },
];
  1. (Optional) TypeScript support. Add nuxt-ab-segment to the types section of tsconfig.json:
{
  "compilerOptions": {
    "types": ["nuxt-ab-segment"]
  }
}

Options

event

  • Type: String
  • Default: AB Test

Event name reported to Segment.

experiments

  • Type: String
  • Default: ~/experiments.js

File path for your experiments definition.

debug

  • Type: Boolean
  • Default:
    • Development: true
    • Production: false

Enables or disables printing Segment reports to the console.

Usage

It can be used inside components like:

{
  data: () => ({
    payBtnLabel: null as string | null,
  }),
  mounted() {
    // Scenario: Determine an experiment variant and display a label accordingly.
    const expA = this.$abtest('experiment-a');
    if (expA === 0) {
      this.payBtnLabel = 'Place order';
    } else {
      this.payBtnLabel = 'Pay now!';
    }

    // Scenario: Force a specific variant programmatically.
    const expB = this.$abtest('experiment-b', { forceVariant: 1 });
    console.log('Variant for expB is always 1');

    // Scenario: Assign a variant and report it for analytics.
    const expC = this.$abtest('experiment-c', { reportVariant: true });
    console.log(`Variant for expC is ${expC}, and it was reported.`);

    // Scenario: Avoid activating an A/B test at a specific step.
    // (No variant assignment or reporting is done.)
    const expD = this.$abtest('experiment-d', { assignVariant: false });
    console.log('Variant for expD is always 0');

    // Scenario: Report analytics and append specific properties.
    // (experiment, but additional data is sent.)
    const expE = this.$abtest('experiment-e', { reportVariant: true, segment: { properties: { device: 'mobile' } } });
    console.log(`Variant for expE is ${expE}, and will include the properties: { experiment: 'experiment-e', variant: ${expE}, device: 'mobile' }`);

  }
}

An example of event properties reported to Segment:

{
  experiment: 'experiment-x',
  variant: 1
}

Credits

License

See the LICENSE file for license rights and limitations (MIT).