3
3
module Heatmap
4
4
module Helper
5
5
6
- def save_heatmap ( options = { } )
6
+ def exact_route
7
+ "#{ params [ :controller ] } /#{ params [ :action ] } "
8
+ end
7
9
10
+ def save_heatmap ( options = { } )
8
11
click = options [ :click ] || Heatmap ::Rails . options [ :click ]
9
12
move = options [ :move ] || Heatmap ::Rails . options [ :move ]
10
13
scroll = options [ :scroll ] || Heatmap ::Rails . options [ :scroll ]
@@ -38,7 +41,7 @@ def save_heatmap(options = {})
38
41
var element_height= event.target.getBoundingClientRect().height;
39
42
offset_x_element = event.offsetX / element_width;
40
43
offset_y_element = event.offsetY / element_height;
41
- var pageCoords = { path: window.location.pathname , type: 'scroll', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
44
+ var pageCoords = { path: " #{ exact_route } " , type: 'scroll', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
42
45
43
46
scroll_array.push(pageCoords);
44
47
if (scroll_array.length >= parseInt(#{ scroll } )) {
@@ -55,7 +58,7 @@ def save_heatmap(options = {})
55
58
var element_height= ev.target.getBoundingClientRect().height;
56
59
offset_x_element = ev.offsetX / element_width;
57
60
offset_y_element = ev.offsetY / element_height;
58
- var pageCoords = { path: window.location.pathname , type: 'move', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
61
+ var pageCoords = { path: " #{ exact_route } " , type: 'move', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
59
62
60
63
var obj = move_array.find(function (obj) { return obj.xpath === xpath_element; });
61
64
if (obj == null){
@@ -78,7 +81,7 @@ def save_heatmap(options = {})
78
81
var element_height= ev.target.getBoundingClientRect().height;
79
82
offset_x_element = ev.offsetX / element_width;
80
83
offset_y_element = ev.offsetY / element_height;
81
- var pageCoords = { path: window.location.pathname , type: 'click', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
84
+ var pageCoords = { path: " #{ exact_route } " , type: 'click', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
82
85
click_array.push(pageCoords);
83
86
if (click_array.length >= parseInt(#{ click } ))
84
87
{
@@ -153,14 +156,14 @@ def save_heatmap(options = {})
153
156
html . respond_to? ( :html_safe ) ? html . html_safe : html
154
157
end
155
158
156
- def show_heatmap ( path , type = false )
159
+ def show_heatmap ( type = false )
157
160
if type
158
- heatmap = HeatMap . where ( path : path . to_s , click_type : type )
159
- heatmap_count = HeatMap . where ( path : path . to_s , click_type : type ) . count
161
+ heatmap = HeatMap . where ( path : exact_route . to_s , click_type : type )
162
+ heatmap_count = HeatMap . where ( path : exact_route . to_s , click_type : type ) . count
160
163
type = type + 's'
161
164
else
162
- heatmap = HeatMap . where ( path : path . to_s )
163
- heatmap_count = HeatMap . where ( path : path . to_s ) . count
165
+ heatmap = HeatMap . where ( path : exact_route . to_s )
166
+ heatmap_count = HeatMap . where ( path : exact_route . to_s ) . count
164
167
type = 'heatmaps'
165
168
end
166
169
@data_points = [ ]
@@ -222,7 +225,7 @@ def show_heatmap(path,type = false)
222
225
height = element.getBoundingClientRect().height;
223
226
var x_coord = getOffset(path.xpath).x+ (width * path.offset_x);
224
227
var y_coord = getOffset(path.xpath).y+ (height * path.offset_y);
225
- delete path["xpath "];
228
+ delete path["xpath_current "];
226
229
delete path["offset_x"];
227
230
delete path["offset_y"];
228
231
path.x = Math.ceil(parseFloat(x_coord));
@@ -237,11 +240,8 @@ def show_heatmap(path,type = false)
237
240
heatmapInstance.addData(data_xpath);
238
241
var scroll = JSON.parse('#{ raw ( @scroll_data . to_json . html_safe ) } ');
239
242
var scroll_data = scroll.map(function(element){
240
- var element = getElement(element.xpath);
241
- if (!element)
242
- return;
243
- width = element.getBoundingClientRect().width;
244
- height = element.getBoundingClientRect().height;
243
+ width = getElement(element.xpath).getBoundingClientRect().width;
244
+ height = getElement(element.xpath).getBoundingClientRect().height;
245
245
dot = document.createElement('div');
246
246
dot.className = "dot";
247
247
dot.style.left = (getOffset(element.xpath).x+ (width * element.offset_x)) + "px";
0 commit comments