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

@testit-sdk/nuxt

v1.0.2

Published

AB Testing Nuxt

Downloads

15

Readme

🧬 Test It for Nuxt

npm version npm downloads

A powerful and easy-to-use A/B testing module for Nuxt.js applications, powered by Test It.

📚 Table of Contents

✨ Features

  • 🚀  Easy integration with Nuxt.js projects
  • 🔧  Automatic variant assignment
  • 📊  Built-in event tracking

💻 Installation

Install the module using your preferred package manager:

# Using npm
npm install test-it-nuxt

# Using yarn
yarn add test-it-nuxt

# Using pnpm
pnpm add test-it-nuxt

🚀 Usage

Basic Setup

  1. Add the module to your nuxt.config.ts:
export default defineNuxtConfig({
  modules: ["test-it-nuxt"],

  public: {
    abTesting: {
      projectId: "your-project-id",
    },
  },
});

Creating an Experiment

Use the useExperiment composable in your Vue component:

<script setup>
import { useExperiment } from "#app";

const experiment = useExperiment("66b035275d5278173af744xx");

experiment.setVariants([
  { id: "66b035275d5278173af744xx", name: "blue", weight: 0.5 },
  { id: "66b035275d5278173af744xx", name: "red", weight: 0.5 },
]);
</script>

Checking Variants

Check which variant the user is assigned to:

You can use experiment.isVariant to check if the user is in a specific variant.

It works in both template and script setup.

// script setup
<script setup>
const buttonColor = experiment.isVariant("blue") ? "blue" : "red";
</script>
// template
<template>
  <button v-if="experiment.isVariant('blue')" class="bg-blue-500">
    Click me
  </button>
  <button v-else class="bg-red-500">Click me</button>
</template>

Tracking Events

Track conversion events using the trackExperimentEvent composable:

<script setup>
function handleClick() {
  trackExperimentEvent("66b035275d5278173af744xx");
}
</script>

<template>
  <button @click="handleClick">Click me</button>
</template>

📘 API Reference

useExperiment(experimentId: string)

Creates an experiment instance.

  • setVariants(variants: Variant[]): void - Sets the variants for the experiment
  • isVariant(variantName: string): boolean - Checks if the current variant matches the given name
  • currentVariant: Ref<Variant | null> - The current variant for the user

trackExperimentEvent(eventId: string, data?: object)

Tracks a custom event for the experiment. Optionally pass data to track.

⚙️ Configuration

Configure the module in your nuxt.config.ts:

export default defineNuxtConfig({
  // ... other config
  abTesting: {
    projectId: "your-project-id",
    cookieKey: "experiments",
  },
});

IMO it's better to manually track page views using the trackExperimentEvent composable. It's not an analytics app, so only track what you need.

🤝 Contributing

If you do have suggestions for improvements, let me know!