-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
87 lines (68 loc) · 1.93 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
(function () {
'use strict';
var html,
body,
data = [],
delay = false,
DELAY_TIME = 10,
USER_ID = new Date().getTime() + Math.random(),
MOUSE_MOVE_TYPE = 'mousemove',
MOUSE_CLICK_TYPE = 'click';
function LogMouseMove(e) {
if(!delay){
var log = {
timestamp: null,
x: null,
y: null,
type: null,
url: window.location.hostname + window.location.pathname
};
log.timestamp = new Date().getTime();
log.x = e.clientX;
log.y = e.clientY;
log.type = MOUSE_MOVE_TYPE;
data.push(log);
delay = true;
setTimeout( function() { delay = false; }, DELAY_TIME);
}
}
function LogClick(e) {
var log = {
timestamp: null,
x: null,
y: null,
type: null,
url: window.location.hostname + window.location.pathname
};
log.timestamp = new Date();
log.x = e.clientX;
log.y = e.clientY;
log.type = MOUSE_CLICK_TYPE;
data.push(log);
}
function LogOnBrowserExit(e) {
PushDataToServer();
}
function ShowUserHeatmap() {
var heatmap = h337.create({
container: html
});
heatmap.setData({
max: 25,
data: data
});
}
function setup() {
html = document.getElementsByTagName('html')[0];
body = document.getElementsByTagName('body')[0];
html.onmousemove = LogMouseMove;
html.onclick = LogClick;
window.onbeforeunload = LogOnBrowserExit;
var button = document.getElementById('mouseMove');
button.onclick = ShowUserHeatmap;
}
function PushDataToServer() {
//DO API CALL WITH UNIQUE USER_ID AND DATA THEN CLEAR DATA
}
setup();
}());