Last active
September 21, 2016 17:26
-
-
Save jdcauley/a0740c64058417945246b334219e779e to your computer and use it in GitHub Desktop.
Trk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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