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

google-analytics-ab

v0.2.2

Published

Function to create tests AB using analytics

Downloads

4

Readme

Google Analytics AB

Version Build Status Code Climate HitCount

Lib tool in javascript to create A/B tests using Google Analytics events in easy way. With a simple configuration you can edit your page and get metrics.

Getting started

NPM

To install using npm you must run.

$ npm i --save google-analytics-ab

And use require to get the lib.

var googleAnalyticsAB = require('googleAnalyticsAB');

# Or with ecma6

import googleAnalyticsAB from 'googleAnalyticsAB'

Bower

To install using Bower you must run.

$ bower install google-analytics-ab

You can get in folder dist the compressed file (/dist/google-analytics-ab.min.js).

Dependencies

  • Google Analytics script (obvios?)

Create your own first test

You must have GA script in your page.

To make a simple test, you can call:

.....
<script src="https://rawgit.com/tacnoman/googleAnalyticsAB/master/dist/google-analytics-ab.min.js"></script>
.....

  # Example of AB change button color. Green or Red.
  googleAnalyticsAB.create({
    name: 'MY_TEST', // Name of your first test
    percentage: 80, // Percentage of users to run in this test (Default is 80)

    // Alternatives
    options: [
      {
        name: 'green-button', // Name of your alternative
        weight: 1, // weight of your alternative (optional, default is 1)
      },
      {
        name: 'red-button',
        weight: 1,
      }
    ],

    // Method called when AB is sorted
    run: function(option) { // Current option
      var myButton = document.getElementById('myButton'); // Getting some button
      myButton.style.background = option.name === 'green-button' ? '#0F0' : '#F00'; // Change color using the label

      // Event onClick in button tested
      myButton.addEventListener('click', function(ev) {
        option.convert(); // Option has a method called convert. Use to convert :D
      });
    }
  });

How to see the results

Open your Google Analytics account and go to:

Behavior > Events > Overview

In Event category, go to googleAnalyticsAB.

Click in Event Action.

Now, you will see all A/B tests running. Click in your current A/B test.

Now, you will see your options, check all and click in Plot rows.

See your test result :D

Ps: If you cannot see the events, you need change the date and add the current day.

Bugs? Tacnoman <[email protected]>.