I am stuck with the an issue in which I have to track a time spend by user on particular page and save data in database using mongodb. I have seen one answer about the same but I am confused where to add that piece of code as I am using angularjs. Do I have to keep this code in controller of that particular page or to the index where I am rendering all code using ui-view.
Code from How to measure a time spent on a page?
var start;
$(document).ready(function() {
start = Date.getTime();
$(window).unload(function() {
end = Date.getTime();
$.ajax({
url: "log.php",
data: {'timeSpent': end - start}
})
});
});
thnx in advance.