Skip to content

Instantly share code, notes, and snippets.

@philcon93
Created November 29, 2017 03:27
Show Gist options
  • Save philcon93/c74adae619fdb9095ddf492b85c750d6 to your computer and use it in GitHub Desktop.
Save philcon93/c74adae619fdb9095ddf492b85c750d6 to your computer and use it in GitHub Desktop.

Neto Checkout Input Logging

JS

checkoutlog = {
"site_vertical":"",
"total_time_spent":0,
"time_spent_on_inputs": 0,
"inputs":{},
"shipping":{
"available_methods": [],
"selected_method":"",
"time_selected":0
},
"payment":{
"available_methods": [],
"selected_method":"",
"time_selected":0
}
}
function selectedPaymentMethod(){
var param = $.getCheckoutCache();
var payRef = $('#payment').val();
var $paySelected = $('.'+param['prefix']+'payicon[ref='+payRef+']').parent();
return $paySelected;
};
function updateInput(inputName, item, value){
checkoutlog.inputs[inputName][item] = value;
}
function updateShipping(){
checkoutlog.shipping.available_methods = [];
$('#_jstl_shipping_options table input[type=radio][name*=ship]').each(function(i){
checkoutlog.shipping.available_methods.push($(this).siblings("h4").text().replace(/\s/g,''));
});
checkoutlog.shipping.selected_method = $('#_jstl_shipping_options table input[type=radio][name*=ship]:checked').siblings("h4").text().replace(/\s/g,'');
checkoutlog.shipping.time_selected = window.performance.now();
};
function updatePayments(){
checkoutlog.payment.available_methods = [];
$('#paymentMethods ._cpy_payicon').each(function(i){
checkoutlog.payment.available_methods.push($(this).attr('ref2'));
});
var $paymentMethod = selectedPaymentMethod();
checkoutlog.payment.selected_method = $paymentMethod.find('a').attr('ref2');
checkoutlog.payment.time_selected = window.performance.now();
};
$(document).ready(function(){
updateShipping();
updatePayments();
});
$('input').on('focus',function(e){
if (e.target.name in checkoutlog.inputs){
if(checkoutlog.inputs[e.target.name].first_focus == 0){
updateInput(e.target.name, "first_focus", window.performance.now());
}
updateInput(e.target.name, "last_focused", window.performance.now());
}else{
checkoutlog.inputs[e.target.name] = {
"first_focus": window.performance.now(),
"total_time_spent": 0,
"failed_attempts": 0,
"last_focused": window.performance.now()
}
}
});
$('input').on('blur',function(e){
var timeSpent = window.performance.now() - checkoutlog.inputs[e.target.name].last_focused;
updateInput(e.target.name, "total_time_spent", timeSpent);
}),
$('#checkout_shipping').on('click', 'table input[type=radio][name*=ship]', updateShipping);
$('#paymentMethods').on('click', '._cpy_payicon', updatePayments);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment