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

nuxt-goptimize

v2.0.1

Published

NuxtJS module for A/B testing with Google Optimize

Downloads

21

Readme

Note: Google Optimize is used for reporting (only).

Table of contents

Main features

  • Run multiple experiments simultaneously
  • TypeScript support
  • Cookies to persist variants across users
  • Event handlers ga or dataLayer
  • Force a specific variant via url or param. E.g. url?gopt_experiment-x=1 or this.$abtest('experiment-x', true, 1);
  • Avoid activating the a/b test anywhere. E.g. this.$abtest('experiment-x', false);
  • Disable all a/b tests by cookie (gopt_disabled=1), which can be useful for E2E tests in CI/CD pipelines

Dependencies

You can choose one of the following options which injects Google Analytics into your application:

Setup

Google Optimize

  1. Create a new experiment:
Name: Experiment X
Type of experience: A/B test
  1. Add variants names:
Original: this.$abtest('my_experiment') = 0
Variant A: this.$abtest('my_experiment') = 1
Variant B: this.$abtest('my_experiment') = 2
  1. Define a page targeting:

WHEN URL equals SERVER_SIDE

  1. Define experiment's objectives.

Nuxt.js Module

  1. Add nuxt-goptimize dependency to your project:
npm install nuxt-goptimize
  1. Add nuxt-goptimize module and configuration to nuxt.config.js:
export default {
  // ...other config options
  modules: ["nuxt-goptimize"];
  googleOptimize: {
    experiments: '~/experiments.js', // 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')
 *  id: string; Experiment ID of Google Optimize
 *  maxAgeDays: number; Number of days to persist the cookie of user's active variant
 *  variants: number[]; An array of variants weights
 * }
 */
module.exports = [
  {
    name: "experiment-x",
    id: "IUhKJR2MSTiPMVGAwJDFBL",
    maxAgeDays: 15,
    variants: [50, 50],
  },
];
  1. (Optional) TypeScript support. Add nuxt-goptimize to the types section of tsconfig.json:
{
  "compilerOptions": {
    "types": ["nuxt-goptimize"]
  }
}

Options

experiments

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

File path for your experiments definition.

eventHandler

  • Type: String
  • Default: ga
  • Values: ga, dataLayer

Event handler to let Google know about variants in-use.

Usage

It can be used inside components like:

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

    // Scenario: We want to force a specific variant programmatically.
    const expB = this.$abtest('experiment-b', true, 1);
    console.log('expB is always 1');

    // Scenario: We have steps and we want to avoid activating the a/b test in any step
    // (meaning.. avoid assigning a variant and reporting it).
    const expC = this.$abtest('experiment-c', false)
    console.log('expC is always 0');
  }
}

Credits

License

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