jQuery Plugin For A/B Tests Using Google Analytics - easyAB

File Size: 6.7 KB
Views Total: 933
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
jQuery Plugin For A/B Tests Using Google Analytics - easyAB

easyAB is a lightweight and easy jQuery plugin that takes advantage of Google Analytics to implement A/B and multivariate tests for helping entrepreneurs and tech savvy building better landing pages for their projects and products.

How to use it:

1. The html

<div class="well text-center">
  <p>
  Check out my
  <b><span class="book-adjective">awesome</span>
  book</b>!
  <em>Only $4.99</em>
  </p>
  <button class="btn btn-success btn-large"
          id="purchase-button"
          onclick="_gaq.push(['_trackEvent',
              'Purchase actions',
              'Purchase']);">
    Get it now!
  </button>
</div>

2. Include jQuery library and jQuery easyAB plugin on the web page

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="easyab.min.js"></script>

3. The javascript

  /* set an Analytics custom var on the slot 1 */
  $('.book-adjective').easyab({
    'slot': 1,
    'name': 'gs-book-adjective',
    'alternatives': [{
      'alternative': 'award winning'
    }]
  });

  /* set an Analytics custom var on the slot 2 */
  $('#purchase-button').easyab({
    'slot': 2,
    'name': 'gs-purchase-button',
    'alternatives': [{
      'alternative':
        function($this) {
          $this
            .removeClass('btn-success')
            .addClass('btn-primary');
        }
    }]
  });

This awesome jQuery plugin is developed by srom. For more Advanced Usages, please check the demo page or visit the official website.