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.
<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>
<script src="https://apicdn.lazysauce.com/"></script>
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.
/* <![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;/* ]]> */
var pkey = lazy_pkey;var hash = lazy_hash;
This API call is used to log custom actions by the client. It is fired through javascript by the client on action events.
| 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 |
'Hash' = String id for the action
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, '',);
});
lazysauce_action({name:'exampleAction2',engagement:'0',variant:'1'});
This API call is used to assign revenue to the last action or the action that matches the passed hash
| 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' |
lazysauce_sale({revenue:"100.50",logstring:"log revenue post red button action"});
This API call is designed for clients to assign their own custom tracking values to Users.
| Parameter Name | Paramter Type | Required ? | Default | Example |
|---|---|---|---|---|
| action | Boolean | NO | 0 | 1 |
| name | String | YES | 'Unique' | |
| value | String | YES | 'true' |
lazysauce_param({action:1,name:"redButton",value:"true"});
$('#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"});
}