Skip to content

Instantly share code, notes, and snippets.

@jdcauley
Last active September 21, 2016 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdcauley/a0740c64058417945246b334219e779e to your computer and use it in GitHub Desktop.
Save jdcauley/a0740c64058417945246b334219e779e to your computer and use it in GitHub Desktop.
Trk
(function($, Cookies, undefined){
var dateObj = new Date(),
month = dateObj.getUTCMonth() + 1,
day = dateObj.getUTCDate(),
year = dateObj.getUTCFullYear(),
currentDate = year + "" + month + "" + day,
currentSession = {},
trimData = {},
visits = localStorage.getItem("foVisit");
uxtrkData.time = dateObj;
visits = JSON.parse(visits);
console.log(visits);
if(!visits){
console.log('no visits');
visits = Cookies.getJSON('foVisit');
}
for (var key in uxtrkData){
if(uxtrkData[key]){
trimData[key] = uxtrkData[key];
}
}
if(visits){
currentSession = visits;
}
if(typeof currentSession[currentDate] === 'undefined'){
currentSession[currentDate] = [];
}
currentSession[currentDate].push(trimData);
var sessionString = JSON.stringify(currentSession);
if(typeof Storage !== "undefined"){
localStorage.setItem('foVisit', sessionString);
} else {
Cookies.set('foVisit', currentSession, { expires: 90 });
}
$('html').on('submit', 'form', function(evt){
evt.preventDefault();
var input = document.createElement('input');
input.type = 'hidden';
input.name = 'leadPath';
input.value = sessionString;
this.appendChild(input);
this.submit();
});
})(jQuery, Cookies);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment