Last active
March 11, 2016 12:03
-
-
Save Jayin/39ad1e72dcb53345424f to your computer and use it in GitHub Desktop.
统计当前页面访问的duration
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
| var pf = window.webkitPerformance ? window.webkitPerformance : window.msPerformance; | |
| pf = (pf ? pf : window.performance); | |
| function sendVisitDuration() { | |
| var pfTime = pf ? pf.timing.domComplete : nowTime; | |
| var time = new Date().getTime() - pfTime; | |
| time = Math.ceil(time / 1000); | |
| if (time > 0) { | |
| var category = '0-2s'; | |
| if (time > 2 && time < 5) { | |
| category = '2-5s'; | |
| } else if (time > 5 && time < 10) { | |
| category = '5-10s'; | |
| } else if (time > 10 && time < 15) { | |
| category = '10-15s'; | |
| } else if (time > 15 && time < 30) { | |
| category = '15-30s'; | |
| } else if (time > 30 && time < 60) { | |
| category = '30-60s'; | |
| } else if (time > 60 && time < 120) { | |
| category = '60-120s'; | |
| } else if (time > 120 && time < 300) { | |
| category = '120-300s'; | |
| } else if (time > 300) { | |
| category = '>300s'; | |
| } | |
| } | |
| } | |
| //当页面要跳转是触发统计(离开,例如刷新当前页,or点击链接到另外一页) | |
| addEvent(window, "pagehide", sendVisitDuration); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment