javascript - Need to Find the Duration between PageLoad and Click for Next Page in AngularJS -


I'm new to AngularJS and I want to write a simple function that the number of seconds users spend on the page If I click on the 'next' button to load the page, I basically need to know how much time the user has spent on each page. Can anyone help me write this function in AngularJS?

Place it in your J.J.S. file, where your app is implied. To do this, you need to add a listener for $ injecting and '$ locationChangeStart'. Whatever is left is just doing some math and logging when I open one page for more than .02, then I Added additional code to log in only. Kangaroo was doing some routing which I was entering with trial and error with Ileiveive logging. By doing it from this perspective, it is cleaner that you have to keep it in all controllers.

  var mainApp = angular.module ('mainApp', [.....]); MainApp.run (function ($ rootScope, $ location) {$ rootScope.currentPage = ""; $ rootScope.pageLoadedTime = "" $ rootScope. $ ('$ LocationChangeStart', function (event) {if ($ rootScope current page ! = "") {Var second = (New Date) GetTime () - $ rootScope.pageLoadedTime.getTime ()) / 1000; if (seconds> .02) console.log ("Page:", $ RootScope.currentPage, "Seconds spent on page:", seconds);} $ rootsecope. Pageloaded time = new date ($); $ Rootscope currentPage = $ location.url ();});});  

Comments