33module Heatmap
44 module Helper
55
6- def save_heatmap ( options = { } )
6+ def exact_route
7+ "#{ params [ :controller ] } /#{ params [ :action ] } "
8+ end
79
10+ def save_heatmap ( options = { } )
811 click = options [ :click ] || Heatmap ::Rails . options [ :click ]
912 move = options [ :move ] || Heatmap ::Rails . options [ :move ]
1013 scroll = options [ :scroll ] || Heatmap ::Rails . options [ :scroll ]
@@ -38,7 +41,7 @@ def save_heatmap(options = {})
3841 var element_height= event.target.getBoundingClientRect().height;
3942 offset_x_element = event.offsetX / element_width;
4043 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, };
4245
4346 scroll_array.push(pageCoords);
4447 if (scroll_array.length >= parseInt(#{ scroll } )) {
@@ -55,7 +58,7 @@ def save_heatmap(options = {})
5558 var element_height= ev.target.getBoundingClientRect().height;
5659 offset_x_element = ev.offsetX / element_width;
5760 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, };
5962
6063 var obj = move_array.find(function (obj) { return obj.xpath === xpath_element; });
6164 if (obj == null){
@@ -78,7 +81,7 @@ def save_heatmap(options = {})
7881 var element_height= ev.target.getBoundingClientRect().height;
7982 offset_x_element = ev.offsetX / element_width;
8083 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, };
8285 click_array.push(pageCoords);
8386 if (click_array.length >= parseInt(#{ click } ))
8487 {
@@ -153,14 +156,14 @@ def save_heatmap(options = {})
153156 html . respond_to? ( :html_safe ) ? html . html_safe : html
154157 end
155158
156- def show_heatmap ( path , type = false )
159+ def show_heatmap ( type = false )
157160 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
160163 type = type + 's'
161164 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
164167 type = 'heatmaps'
165168 end
166169 @data_points = [ ]
@@ -222,7 +225,7 @@ def show_heatmap(path,type = false)
222225 height = element.getBoundingClientRect().height;
223226 var x_coord = getOffset(path.xpath).x+ (width * path.offset_x);
224227 var y_coord = getOffset(path.xpath).y+ (height * path.offset_y);
225- delete path["xpath "];
228+ delete path["xpath_current "];
226229 delete path["offset_x"];
227230 delete path["offset_y"];
228231 path.x = Math.ceil(parseFloat(x_coord));
@@ -237,11 +240,8 @@ def show_heatmap(path,type = false)
237240 heatmapInstance.addData(data_xpath);
238241 var scroll = JSON.parse('#{ raw ( @scroll_data . to_json . html_safe ) } ');
239242 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;
245245 dot = document.createElement('div');
246246 dot.className = "dot";
247247 dot.style.left = (getOffset(element.xpath).x+ (width * element.offset_x)) + "px";
0 commit comments