heatmap-rails 0.1.1 → 0.1.2
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 +1 -1
- data/README.md +25 -20
- data/Rakefile +0 -4
- data/app/controllers/points_controller.rb +6 -6
- data/bin/console +1 -1
- data/heatmap-rails.gemspec +2 -2
- data/lib/generators/heatmap_rails/templates/initializer.rb +2 -0
- data/lib/heatmap/rails.rb +12 -0
- data/lib/heatmap/rails/engine.rb +11 -0
- data/lib/heatmap/{helper.rb → rails/helper.rb} +42 -13
- data/lib/heatmap/rails/version.rb +5 -0
- data/spec/heatmap_rails_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -1
- metadata +7 -7
- data/lib/heatmap-rails.rb +0 -12
- data/lib/heatmap/engine.rb +0 -9
- data/lib/heatmap/version.rb +0 -3
- data/spec/heatmap_rb_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87094bab47af8ff7d11ffa1ad7859bfd676663f0
|
4
|
+
data.tar.gz: b29655825150001bb58b16a34730967a674d113f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b73c339204943ab57d3581404621c0e40df06b887756845f74e12918753d3b6e431a06ab5cd81d2e3916abf5dc39ff045e1029bb805901842562ee98926ed220
|
7
|
+
data.tar.gz: d1d14d96f0a6168e02df4389680407713dc8921c642056cef95d239dd2bac112e50391963714785ea62c39da972fbd0a2da49f8bf675c6f22694e5b21e3e704a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,11 @@
|
|
1
|
-
|
1
|
+
[](https://badge.fury.io/rb/heatmap-rails)
|
2
|
+
|
3
|
+
# Heatmap-Rails
|
2
4
|
|
3
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.
|
4
6
|
Helping in gathering analytics to find out what works on the web, what attracts most of the users.
|
5
7
|
View user interactions and make your application more amazing! :sparkles:
|
6
|
-
|
7
|
-
## Local Testing
|
8
|
-
|
9
|
-
Use
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'heatmap-rails', git: 'https://github.com/Qbatch/heatmap-rails.git'
|
13
|
-
```
|
8
|
+
[Demo](https://heatmap-rails.herokuapp.com/)
|
14
9
|
|
15
10
|
## Installation
|
16
11
|
|
@@ -31,7 +26,8 @@ Or install it yourself as:
|
|
31
26
|
## Usage
|
32
27
|
|
33
28
|
1. Install the gem
|
34
|
-
|
29
|
+
|
30
|
+
2. Run the command to generate a migration to save heatmaps data:
|
35
31
|
```console
|
36
32
|
$ rails g heatmap_rails:install
|
37
33
|
```
|
@@ -50,8 +46,13 @@ $ rake db:migrate
|
|
50
46
|
```erb
|
51
47
|
<%= show_heatmap(request.path) %>
|
52
48
|
```
|
49
|
+
6. Before adding headmap.js in the application install **jquery-rails** gem and require it in application.js file
|
50
|
+
```js
|
51
|
+
//= require jquery
|
52
|
+
```
|
53
|
+
|
53
54
|
|
54
|
-
|
55
|
+
7. In respective JS file, Require HeatMap.Js to show the heatmap:
|
55
56
|
```js
|
56
57
|
//= require heatmap.js
|
57
58
|
```
|
@@ -69,43 +70,47 @@ The viewing can be done in multiple ways, for example if you want only the admin
|
|
69
70
|
<% end %>
|
70
71
|
```
|
71
72
|
|
72
|
-
Another way can be using some
|
73
|
+
Another way can be using some param in the URL. For example if you want to use URL like:
|
73
74
|
|
74
75
|
```url
|
75
|
-
www.website.com
|
76
|
+
www.website.com/?see_heatmap
|
76
77
|
```
|
77
78
|
|
78
79
|
You can use:
|
79
80
|
|
80
81
|
```erb
|
81
|
-
<% if request.
|
82
|
+
<% if request.query_parameters.include?("see_heatmap") %>
|
82
83
|
<%= show_heatmap(request.path) %>
|
83
84
|
<% end %>
|
84
85
|
```
|
85
86
|
|
86
|
-
And there can be multiple ways!
|
87
87
|
### Options
|
88
88
|
|
89
|
-
You can customize:
|
89
|
+
You can customize the max stack limits before the data is sent to server side via http request. We understand for different application the average user interactions time on a specific page varies. You can set these values w.r.t to your application's needs:
|
90
90
|
```erb
|
91
91
|
<%= save_heatmap({click: 3, move: 50}) %>
|
92
92
|
```
|
93
|
-
|
93
|
+
The default values for clicks is `3`. For mouse movements tracking its `50`.
|
94
|
+
|
95
|
+
```erb
|
96
|
+
<%= save_heatmap({click: 3, move: 50, html_element: 'body'}) %>
|
97
|
+
```
|
98
|
+
you can even restrict heatmap generation to a specific DOM element. Default value for DOM element is `body` element. This can be change to any `.class` or any '#id'.
|
94
99
|
|
95
|
-
## Development
|
100
|
+
## Development
|
96
101
|
|
97
102
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
103
|
|
99
104
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
105
|
|
101
106
|
## Credits
|
102
|
-
heatmap-rails uses [HeatMap.Js](https://www.patrick-wied.at/static/heatmapjs/) to generated
|
107
|
+
heatmap-rails uses [HeatMap.Js](https://www.patrick-wied.at/static/heatmapjs/) to show generated data in form of heatmaps.
|
103
108
|
|
104
109
|
## Contributing :construction:
|
105
110
|
|
106
111
|
1. [Bug reports](https://github.com/Qbatch/heatmap-rails/issues) are always welcome.
|
107
112
|
2. [Pull Requests](https://github.com/Qbatch/heatmap-rails/pulls). Suggest or Update.
|
108
113
|
|
109
|
-
## License
|
114
|
+
## License
|
110
115
|
|
111
116
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -3,14 +3,14 @@ class PointsController < ApplicationController
|
|
3
3
|
skip_before_action :verify_authenticity_token
|
4
4
|
|
5
5
|
def create
|
6
|
-
if params[:
|
7
|
-
for i in 0..
|
8
|
-
|
6
|
+
if params[:click_data].present? && params[:total_clicks].to_i > 0
|
7
|
+
for i in 0..params[:total_clicks].to_i-1
|
8
|
+
HeatMap.create(path: params[:click_data]["#{i}"][:path], click_type: 'click',xpath: params[:click_data]["#{i}"][:xpath], offset_x: params[:click_data]["#{i}"][:offset_x], offset_y: params[:click_data]["#{i}"][:offset_y])
|
9
9
|
end
|
10
10
|
end
|
11
|
-
if params[:move_data].present?
|
12
|
-
for i in 0..
|
13
|
-
HeatMap.create(path: params[:move_data]["#{i}"][:path], click_type: '
|
11
|
+
if params[:move_data].present? && params[:total_moves].to_i > 0
|
12
|
+
for i in 0..params[:total_moves].to_i-1
|
13
|
+
HeatMap.create(path: params[:move_data]["#{i}"][:path], click_type: 'move',xpath: params[:move_data]["#{i}"][:xpath], offset_x: params[:move_data]["#{i}"][:offset_x], offset_y: params[:move_data]["#{i}"][:offset_y])
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/bin/console
CHANGED
data/heatmap-rails.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require "heatmap/version"
|
4
|
+
require "heatmap/rails/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "heatmap-rails"
|
8
|
-
spec.version = Heatmap::VERSION
|
8
|
+
spec.version = Heatmap::Rails::VERSION
|
9
9
|
spec.authors = ["Hassan"]
|
10
10
|
spec.email = ["hassan@qbatch.com"]
|
11
11
|
|
@@ -7,17 +7,21 @@ module Heatmap
|
|
7
7
|
|
8
8
|
click = options[:click] || Heatmap::Rails.options[:click]
|
9
9
|
move = options[:move] || Heatmap::Rails.options[:move]
|
10
|
-
|
10
|
+
html_element = options[:html_element] || Heatmap::Rails.options[:html_element]
|
11
11
|
html = ""
|
12
12
|
|
13
13
|
js = <<JS
|
14
14
|
<script type="text/javascript">
|
15
15
|
$( document ).ready(function() {
|
16
16
|
var move_array = [];
|
17
|
-
document.querySelector('
|
17
|
+
document.querySelector('#{html_element}').onmousemove = function(ev) {
|
18
18
|
var xpath_element = xpathstring(ev);
|
19
|
-
var
|
20
|
-
|
19
|
+
var element_width = ev.target.getBoundingClientRect().width;
|
20
|
+
var element_height= ev.target.getBoundingClientRect().height;
|
21
|
+
offset_x_element = ev.offsetX / element_width;
|
22
|
+
offset_y_element = ev.offsetY / element_height;
|
23
|
+
var pageCoords = { path: window.location.pathname, type: 'move', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
|
24
|
+
|
21
25
|
var obj = move_array.find(function (obj) { return obj.xpath === xpath_element; });
|
22
26
|
if (obj == null){
|
23
27
|
move_array.push(pageCoords);
|
@@ -25,21 +29,28 @@ $( document ).ready(function() {
|
|
25
29
|
if (move_array.length >= parseInt(#{move}))
|
26
30
|
{
|
27
31
|
var coordinates = move_array;
|
28
|
-
sendRequest({'move_data': coordinates});
|
32
|
+
sendRequest({'move_data': coordinates,'total_moves': #{move} });
|
29
33
|
move_array = [];
|
30
34
|
}
|
35
|
+
|
36
|
+
|
31
37
|
};
|
32
38
|
var click_array = [];
|
33
|
-
document.querySelector('
|
39
|
+
document.querySelector('#{html_element}').onclick = function(ev) {
|
34
40
|
|
35
41
|
var xpath_element= xpathstring(ev);
|
36
|
-
var
|
42
|
+
var element_width = ev.target.getBoundingClientRect().width;
|
43
|
+
var element_height= ev.target.getBoundingClientRect().height;
|
44
|
+
offset_x_element = ev.offsetX / element_width;
|
45
|
+
offset_y_element = ev.offsetY / element_height;
|
46
|
+
var pageCoords = { path: window.location.pathname, type: 'click', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
|
37
47
|
click_array.push(pageCoords);
|
38
48
|
if (click_array.length >= parseInt(#{click}))
|
39
49
|
{
|
40
50
|
var coordinates = click_array;
|
41
|
-
sendRequest({'
|
51
|
+
sendRequest({'click_data': coordinates, 'total_clicks': #{click} });
|
42
52
|
click_array = [];
|
53
|
+
|
43
54
|
}
|
44
55
|
};
|
45
56
|
function sendRequest(coordinates_data){
|
@@ -113,7 +124,7 @@ JS
|
|
113
124
|
@data_points = []
|
114
125
|
@data_xpaths = []
|
115
126
|
heatmap.each do |coordinate|
|
116
|
-
@data_xpaths.push({xpath: coordinate.xpath,
|
127
|
+
@data_xpaths.push({xpath: coordinate.xpath, offset_x: coordinate.offset_x, offset_y:coordinate.offset_y, value: 100})
|
117
128
|
end
|
118
129
|
html = ""
|
119
130
|
js = <<JS
|
@@ -122,13 +133,31 @@ JS
|
|
122
133
|
container: document.querySelector('body'),
|
123
134
|
radius: 40
|
124
135
|
});
|
136
|
+
function getOffset( path ) {
|
137
|
+
el = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
138
|
+
var _x = 0;
|
139
|
+
var _y = 0;
|
140
|
+
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
|
141
|
+
_x += el.offsetLeft - el.scrollLeft;
|
142
|
+
_y += el.offsetTop - el.scrollTop;
|
143
|
+
el = el.offsetParent;
|
144
|
+
}
|
145
|
+
return { y: _y, x: _x };
|
146
|
+
}
|
147
|
+
function getElement(xpath){
|
148
|
+
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
149
|
+
}
|
125
150
|
var xpath = JSON.parse('#{raw(@data_xpaths.to_json.html_safe)}');
|
126
151
|
var data_xpath = xpath.map(function(path){
|
127
|
-
|
128
|
-
|
152
|
+
width = getElement(path.xpath).getBoundingClientRect().width;
|
153
|
+
height = getElement(path.xpath).getBoundingClientRect().height;
|
154
|
+
var x_coord = getOffset(path.xpath).x+ (width * path.offset_x);
|
155
|
+
var y_coord = getOffset(path.xpath).y+ (height * path.offset_y);
|
129
156
|
delete path["xpath"];
|
130
|
-
path
|
131
|
-
path
|
157
|
+
delete path["offset_x"];
|
158
|
+
delete path["offset_y"];
|
159
|
+
path.x = Math.ceil(parseFloat(x_coord));
|
160
|
+
path.y = Math.ceil(parseFloat(y_coord));
|
132
161
|
return path;
|
133
162
|
});
|
134
163
|
heatmapInstance.addData(data_xpath);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'heatmap/rails/helper'
|
3
|
+
|
4
|
+
RSpec.describe Heatmap do
|
5
|
+
it "has a version number" do
|
6
|
+
expect(Heatmap::Rails::VERSION).not_to be nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.describe Heatmap::Helper do
|
11
|
+
def run_save_heatmap
|
12
|
+
Heatmap::Helper.save_heatmap({move: 10, click: 2, html_element: '#test'})
|
13
|
+
end
|
14
|
+
let(:processed_message) { run_save_heatmap() }
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,11 +76,11 @@ files:
|
|
76
76
|
- heatmap-rails.gemspec
|
77
77
|
- lib/generators/heatmap_rails/install_generator.rb
|
78
78
|
- lib/generators/heatmap_rails/templates/initializer.rb
|
79
|
-
- lib/heatmap
|
80
|
-
- lib/heatmap/engine.rb
|
81
|
-
- lib/heatmap/helper.rb
|
82
|
-
- lib/heatmap/version.rb
|
83
|
-
- spec/
|
79
|
+
- lib/heatmap/rails.rb
|
80
|
+
- lib/heatmap/rails/engine.rb
|
81
|
+
- lib/heatmap/rails/helper.rb
|
82
|
+
- lib/heatmap/rails/version.rb
|
83
|
+
- spec/heatmap_rails_spec.rb
|
84
84
|
- spec/spec_helper.rb
|
85
85
|
homepage: https://github.com/Qbatch/heatmap-rails
|
86
86
|
licenses:
|
data/lib/heatmap-rails.rb
DELETED
data/lib/heatmap/engine.rb
DELETED
data/lib/heatmap/version.rb
DELETED