Skip to content

Commit 607b0e8

Browse files
author
Syed Usama Nasir
committed
New feature added
View of heatmap according to action and controller
1 parent 295a951 commit 607b0e8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

lib/heatmap/rails/helper.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
module 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));

0 commit comments

Comments
 (0)