LazySauce JSAPI Documentation



Our new LazySauce tracking is built to work through javascript! In order to meet the demands of the analytics world and our clients we have revamped LazySauce tracking to be loaded through a single javascript file that contains all the needed functions.

These instructions will get you a copy of the project up and running on your website for development and live purposes.

  • Prerequisites


  • In order to use the tracking software you must be a confirmed client with a license key. Only supported clients and their domains will be accepted by the tracking software.
  • Please contact the LazySauce team if you have not approved your domains or registered with us.

  • Setup


  • In order for JSAPI to work, your website will need to have jQuery loaded onto it.
  • Along with that if you wish for it to work on older versions of Internet Explorer(6-8) you should have a 1.x version of jQuery
  • If you wish to use the javascipt promise functionality to recieve action hashes (described below) then you should load bluebird to support Internet Explorer.
  • Below are the our two recommended source codes for jQuery and Bluebird to load along with the Lazysauce JSAPI if you decide you need the IE functionality.

Setup Sources


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/bluebird/3.4.7/bluebird.min.js"></script>

JSAPI Source

The JSAPI source file always needs to be loaded on every page of the website. This should be loaded right before the closing </body> tag
<script src="https://apicdn.lazysauce.com/"></script>

  • Lazysauce Hit


   This API call is the default call made by JSAPI on load. It will log the visitor and assign a Unique Visitor ID(pkey) and action ID(hash) for the page view.

  • If this is the first page the User has visited that has JSAPI loaded on it JSAPI will assign a unique visitor idea (pkey) and build a profile for the visitor including Geolocation, device information, channel/subchannel/target data, and more
  • Channel, Subchannel, and Target data are passed through the domain with the GET paramaters 'lz_c', 'lz_s', and 'lz_t' respectively in the url
  • Offer variant, Hit Action Name, Action logstring, and whether the page action should be recorded can be set in javascript variables before JSAPI is loaded on the page. (see javascript code below for example)
Example 1(set action name, variant, and logstring of page hit):/* <![CDATA[ */var lazy_variant = 7; var lazy_logstring="logstring"; var lazy_action ="Home Page";/* ]]> */
Example 2(do not record the page hit as an action):/* <![CDATA[ */var lazy_dnt=1;/* ]]> */

Response


  • Once JSAPI has loaded and trackhit has run there will be no return value. However, you can grab the newly assigned pkey and hash values stored as lazy_pkey and lazy_hash.
    var pkey = lazy_pkey;
    var hash = lazy_hash;

  • Lazysauce Action


   This API call is used to log custom actions by the client. It is fired through javascript by the client on action events.

  • Lazysauce_action is built as a javascript promise for users that need to recieve the action hash back before their next javascript command. You can set how long you want this promise to wait for using executeTime (if the timer is reached before the action has written to the database lazysauce_action will return the last action's hash)(example 1)
  • If you just want to log an action and do not need to store the hash for future use you can call lazysauce_action with the parameters only, ignoring the promise code(example 2)
  • Lazysauce_Action can save revenue if needed, however you can also use lazysauce_Sale(explained below) that will retroactively update the action revenue.
  • By default all actions logged are considered as user engagement, however you can customize this with the engagement parameter if you do not want the action to mark engagement. (This is useful for reporting and your domains engagament rate)
  • An action call with the same name as the last action will be ignored(this is to prevent page refresh issues). If you call an action on page load that has the same name as the title of the page, it will be ignored as well.

lazysauce_action();

Parameters

Parameter Name Paramter Type Required ? Default Example
name String NO Page Title 'Red Button CLick'
variant Integer NO 1 567
engagement Boolean NO 1 0
log String NO '' 'The user clicked the red button on variant 567 for $4.50'
revenue Double NO 0 4.50
executeTime Integer NO 450(milliseconds) 800

Response


   'Hash' = String id for the action

Example 1


var logstring="example action was triggered, keeping hash";
lazysauce_action({name:'exampleAction',engagement:'1',variant:'4',log:logstring,revenue='1.00',executeTime:500})
.then(
//Action recored fine and hash was passed back
function(successhash){
     exampleFunction(tempParameter, successhash);
},
//timer expired, use last action hash
function(oldhash){
     exampleFunction(tempParameter, oldhash);
})
//catch any error just in case
.catch(function(e) {
     exampleFunction(tempParameter, '',);
});

Example 2


lazysauce_action({name:'exampleAction2',engagement:'0',variant:'1'});

  • Lazysauce Sale


   This API call is used to assign revenue to the last action or the action that matches the passed hash

  • Lazysauce_sale is a function call to log revenue to an action that has already occured, calls are asynchronous so the logic of the calls should take advantage of lazysauce_action promises or be set up in a way where the action has to have finished before calling sale.

lazysauce_sale();

Parameters

Parameter Name Paramter Type Required ? Default Example
hash String NO Last action's hash '202_MDA0NDIw0ce'
revenue Double YES 50.50
logstring String NO '' 'log revenue post red button action'

Response


No returned value

Example


lazysauce_sale({revenue:"100.50",logstring:"log revenue post red button action"});

  • Lazysauce Parameter


   This API call is designed for clients to assign their own custom tracking values to Users.

  • lazysauce_param is a function call to assign unique parameter names and values to a user, these are very flexible and can be used to meet a list of requirements for clients.
  • Parameters can be assigned to users based on their user ID(pkey) or it can be assigned the them based on their last action(hash), this is set with the 'action' parameter. If this is the case then lazysauce_param should be called in the lazysauce_action promise return.

lazysauce_param();

Parameters

Parameter Name Paramter Type Required ? Default Example
action Boolean NO 0 1
name String YES 'Unique'
value String YES 'true'

Response


No returned value

Example


lazysauce_param({action:1,name:"redButton",value:"true"});

  • Chaining Examples


$('#redButton').on('click', function(e){
    lazysauce_action({name:'red button buy_click',engagement:'1',executeTime:500})
    .then(
    //Action recored fine and hash was passed back
    function(successhash){
         redButtonFired(successhash);
    },
    //timer expired, use last action hash
    function(oldhash){
         redButtonFired(oldhash);
    })
    //catch any error just in case
    .catch(function(e) {
         console.log('network error');
    });
});

function redButtonFired(hash){
    lazysauce_param({action:1,name:"redButton",value:"true"});
    lazysauce_param({name:"blueButton",value:"false"});
    lazysauce_sale({hash:hash,revenue:"2.33"});
}

  • Versioning


We will update all clients with a new readme and instructions when new versions are released. The current version is '4.4'

  • Authors


The LazySauce Inc. Team

  • License


All LazySauce tracking code is the intellectual property of LazySauce Inc. Any reproduction or misuse of this documentation and/or code is a violation of our terms of use. Please contact the LazySauce team if you wish to implement tracking onto your websites.