Created
November 12, 2014 06:57
-
-
Save lu911/2f3b8253340ba1d9f8c5 to your computer and use it in GitHub Desktop.
logger.js
This file contains 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
app.factory('Logger', function(localStorageService) { | |
var getUUID = function() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | |
return v.toString(16); | |
}); | |
}; | |
var createTouchEvent = function(el, x, y) { | |
return { | |
type: 'touch', | |
timestamp: Math.floor(new Date().getTime() / 1000), | |
elment: el, | |
x: x, | |
y: y | |
} | |
}; | |
var events = []; | |
var loggerId = localStorageService.get('loggerId'); | |
if(loggerId == null) { | |
loggerId = getUUID(); | |
localStorageService.set('loggerId', loggerId); | |
} | |
console.log(loggerId); | |
document.addEventListener("click", function(e) { | |
var event = createTouchEvent(e.toElement, e.x, e.y); | |
events.push(event); | |
console.log(events); | |
}, false); | |
window.onscroll = function(e) { | |
console.log(e); | |
}; | |
return {}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment