heatmap-rails 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +14 -5
- data/lib/heatmap/rails/helper.rb +18 -15
- data/lib/heatmap/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614bf4dc520980f64a0a7dc2c8eab0ab556b05d6
|
4
|
+
data.tar.gz: f0ccb04bf341f3f4426850028c14bab4c1af2aef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 810febcfbe9154d4b4c77d6eacdb3569b0451ae41a622960eb2faa1fdf0fa4a4dba6434028ab12b683cd9bd13fa20a5cf539ae92fe038741866842bb7f7c8b69
|
7
|
+
data.tar.gz: 2f265ded295eb4b9bcd47c371c55bb39178c1b36263b625c9f7ab6998f3ac593a1cef7914e39e907439e19e198e896a57e32156e43bdf075b08b50ae3235339c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,16 @@
|
|
5
5
|
Integrate heatmaps in your web application to see on which part the user spends most time on your web application. Where does users click on the page.
|
6
6
|
Helping in gathering analytics to find out what works on the web, what attracts most of the users.
|
7
7
|
View user interactions and make your application more amazing! :sparkles:
|
8
|
-
|
8
|
+
|
9
|
+
[Try the demo](https://heatmap-rails.herokuapp.com/)
|
10
|
+
|
11
|
+
Quick Demo of HeatMap Generation
|
12
|
+
|
13
|
+

|
14
|
+
|
15
|
+
Heatmap-Rails Works Perfectly in any Screen Size.
|
16
|
+
|
17
|
+

|
9
18
|
|
10
19
|
## Installation
|
11
20
|
|
@@ -44,7 +53,7 @@ $ rake db:migrate
|
|
44
53
|
|
45
54
|
5. Include where to show the heatmap:
|
46
55
|
```erb
|
47
|
-
<%= show_heatmap
|
56
|
+
<%= show_heatmap %>
|
48
57
|
```
|
49
58
|
6. Before adding headmap.js in the application install **jquery-rails** gem and require it in application.js file
|
50
59
|
```js
|
@@ -59,14 +68,14 @@ $ rake db:migrate
|
|
59
68
|
## Viewing Heat Maps
|
60
69
|
Use the helper
|
61
70
|
```erb
|
62
|
-
<%= show_heatmap
|
71
|
+
<%= show_heatmap %>
|
63
72
|
```
|
64
73
|
The argument is the path of current page. This way the helper will only display the respective heatmap.
|
65
74
|
The viewing can be done in multiple ways, for example if you want only the admin users to view heatmap, you can do something like:
|
66
75
|
|
67
76
|
```erb
|
68
77
|
<% if admin_user_signed_in? %>
|
69
|
-
<%= show_heatmap
|
78
|
+
<%= show_heatmap %>
|
70
79
|
<% end %>
|
71
80
|
```
|
72
81
|
|
@@ -80,7 +89,7 @@ You can use:
|
|
80
89
|
|
81
90
|
```erb
|
82
91
|
<% if request.query_parameters.include?("see_heatmap") %>
|
83
|
-
<%= show_heatmap
|
92
|
+
<%= show_heatmap %>
|
84
93
|
<% end %>
|
85
94
|
```
|
86
95
|
|
data/lib/heatmap/rails/helper.rb
CHANGED
@@ -3,8 +3,11 @@ require "erb"
|
|
3
3
|
module Heatmap
|
4
4
|
module Helper
|
5
5
|
|
6
|
-
def
|
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 @@ $( document ).ready(function() {
|
|
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:
|
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 @@ $( document ).ready(function() {
|
|
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:
|
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 @@ $( document ).ready(function() {
|
|
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:
|
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
|
{
|
@@ -99,9 +102,8 @@ $( document ).ready(function() {
|
|
99
102
|
});
|
100
103
|
|
101
104
|
function xpathstring(event) {
|
102
|
-
var
|
103
|
-
|
104
|
-
path = xpath(e, '');;
|
105
|
+
var e = event.srcElement || event.originalTarget,
|
106
|
+
path = xpath(e, '');
|
105
107
|
return path
|
106
108
|
}
|
107
109
|
function xpath(element, suffix) {
|
@@ -154,14 +156,14 @@ JS
|
|
154
156
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
155
157
|
end
|
156
158
|
|
157
|
-
def show_heatmap(
|
159
|
+
def show_heatmap(type = false)
|
158
160
|
if type
|
159
|
-
heatmap = HeatMap.where(path:
|
160
|
-
heatmap_count = HeatMap.where(path:
|
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
|
161
163
|
type = type + 's'
|
162
164
|
else
|
163
|
-
heatmap = HeatMap.where(path:
|
164
|
-
heatmap_count = HeatMap.where(path:
|
165
|
+
heatmap = HeatMap.where(path: exact_route.to_s)
|
166
|
+
heatmap_count = HeatMap.where(path: exact_route.to_s).count
|
165
167
|
type = 'heatmaps'
|
166
168
|
end
|
167
169
|
@data_points = []
|
@@ -214,8 +216,8 @@ JS
|
|
214
216
|
function getElement(xpath){
|
215
217
|
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
216
218
|
}
|
217
|
-
var
|
218
|
-
var data_xpath =
|
219
|
+
var xpath_current = JSON.parse('#{raw(@data_xpaths.to_json.html_safe)}');
|
220
|
+
var data_xpath = xpath_current.map(function(path){
|
219
221
|
if (path != null) {
|
220
222
|
element = getElement(path.xpath);
|
221
223
|
if (element != null){
|
@@ -223,7 +225,7 @@ JS
|
|
223
225
|
height = element.getBoundingClientRect().height;
|
224
226
|
var x_coord = getOffset(path.xpath).x+ (width * path.offset_x);
|
225
227
|
var y_coord = getOffset(path.xpath).y+ (height * path.offset_y);
|
226
|
-
delete path["
|
228
|
+
delete path["xpath_current"];
|
227
229
|
delete path["offset_x"];
|
228
230
|
delete path["offset_y"];
|
229
231
|
path.x = Math.ceil(parseFloat(x_coord));
|
@@ -261,6 +263,7 @@ JS
|
|
261
263
|
document.body.appendChild(dot);
|
262
264
|
});
|
263
265
|
|
266
|
+
scroll_data = scroll_data.filter(function(val){ return val!==undefined; });
|
264
267
|
</script>
|
265
268
|
JS
|
266
269
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heatmap-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.6.
|
105
|
+
rubygems_version: 2.6.14
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: HeatMap Gem
|