Variant JavaScript Client

Variant AIM ServerResourcesDocumentation0.9Clients ⟫ JavaScript

Variant JavaScript Client ∷ Guide

Version 0.9, June 2018.

Table of Contents

1 Overview
2 Reference

1Overview

Variant.js is a JavaScript library, which enables the Web browser tier of a Web application communicate with Variant server. It presents to the host application’s JavaScript domain an intuitive native API.

As of version 0.8, variant.js is a partial client, in that it does not yet expose all of Variant server’s functionality. You will likely find variant.js particulalry useful for triggering browser-side events, such as clicks or form errors, which could later be used in experiment analysis.

Variant.js requires jQuery .

Variant.js is available at http://www.getvariant.com/js/variant-0.8.0.js.

2Reference

2.1Top Level Methods

variant.boot(properties:Object)
Boot Variant library. properties argument may contain the following properties:

{
  url:String,
  sid:String,
  error:function(jqXHR)
}
  • url: The Variant server URL.
  • sid: User’s Variant session ID.
  • error: Global error callback function. Will be called by Varaint.js on unsuccessful completion of every server call. The sole argument is the jqXHR object .

variant.Event Class

Constructor
variant.Event(name:String, value:String, params:Object)
Construct a new custom event to be passed to Variant server.

  • name: Event’s name.
  • value: Event’s value.
  • params: A map of key-value pairs that will be passed without interpretation to event’s parameter map.
Methods
.send()
Send this event to Variant server for logging.

Example

variant.boot({
   url:"http://my.domain.com:5377/variant",
   sid:"6BDFA64CB9726034",
   error: function(jqXHR) {
      throw Error("Bad response from Variant server: " + jqXHR.status + " " + jqXHR.statusText + ": " + jqXHR.responseText);
   }
});
   
$(document).ready(function() {
   
   $(':submit').click(function() {
      new variant.Event("CLICK", $(this).html()).send();   
   });
      
});

Variant is booted on lines 1-7. We then attach a click handler to all submit buttons in the DOM, which creates a new Variant event with the name “CLICK” and the value of the content of the HTML element which triggered the click event.