trueandco_analytics 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -6
- data/app/assets/javascripts/analitics_in_point.js +28 -0
- data/app/assets/javascripts/analitics_script.js +165 -0
- data/app/assets/javascripts/trueandco_analytics.js +2 -169
- data/app/views/trueandco_analytics/{receiver → site/receiver}/pull_user_statistic.erb +0 -0
- data/config/routes.rb +1 -1
- data/db/migrate/20170802133950_create_metric_users.rb +1 -1
- data/exe/trueandco_analytics +1 -10
- data/lib/generators/trueandco_analytics/templates/trueandco_analytics.rb +3 -3
- data/lib/trueandco_analytics.rb +44 -26
- data/lib/trueandco_analytics/{locales → common/locales}/en.yml +0 -0
- data/{app/models/trueandco_analytics → lib/trueandco_analytics/common/models}/application_record.rb +0 -0
- data/{app/models/trueandco_analytics → lib/trueandco_analytics/common/models}/metric_user.rb +0 -0
- data/{app/models/trueandco_analytics → lib/trueandco_analytics/common/models}/metric_user_session.rb +0 -0
- data/lib/trueandco_analytics/common/models/metric_user_visit.rb +8 -0
- data/lib/trueandco_analytics/{modules → common/modules}/info.rb +0 -0
- data/lib/trueandco_analytics/{reports → common/reports}/application_report.rb +0 -0
- data/lib/trueandco_analytics/{reports → common/reports}/details_report.rb +0 -0
- data/lib/trueandco_analytics/{reports → common/reports}/page_buy_in_date_range_report.rb +0 -0
- data/lib/trueandco_analytics/{services → common/services}/logger.rb +0 -0
- data/lib/trueandco_analytics/{services → common/services}/redis_connect.rb +0 -0
- data/lib/trueandco_analytics/{services → common/services}/reports.rb +1 -6
- data/lib/trueandco_analytics/{services → common/services}/workers.rb +0 -0
- data/lib/trueandco_analytics/config/params.rb +7 -7
- data/lib/trueandco_analytics/{cli → console/cli}/common.rb +0 -0
- data/lib/trueandco_analytics/{cli → console/cli}/report.rb +0 -0
- data/lib/trueandco_analytics/console/commands/report_c/generate.rb +29 -0
- data/lib/{extension_string.rb → trueandco_analytics/console/extension_string.rb} +0 -0
- data/lib/trueandco_analytics/engine.rb +2 -6
- data/{app/commands/trueandco_analytics → lib/trueandco_analytics/site/commands}/arr_jsons_to_arr_hash.rb +1 -1
- data/lib/trueandco_analytics/site/commands/metric_c/add_list.rb +63 -0
- data/lib/trueandco_analytics/site/commands/session_c/create.rb +63 -0
- data/lib/trueandco_analytics/site/commands/session_c/put_data.rb +49 -0
- data/lib/trueandco_analytics/site/commands/user_c/create_or_update_user_if_exist.rb +39 -0
- data/{app/controllers/trueandco_analytics → lib/trueandco_analytics/site/controllers}/application_controller.rb +2 -2
- data/{app/controllers/trueandco_analytics → lib/trueandco_analytics/site/controllers}/reciver_controller.rb +5 -7
- data/lib/trueandco_analytics/site/helpers/trueandco_analytics_helper.rb +18 -0
- data/lib/trueandco_analytics/site/workers/user_session_metric_worker.rb +20 -0
- data/lib/trueandco_analytics/version.rb +1 -1
- metadata +31 -29
- data/app/commands/trueandco_analytics/metric_c/add_list.rb +0 -65
- data/app/commands/trueandco_analytics/report_c/generate.rb +0 -31
- data/app/commands/trueandco_analytics/session_c/create.rb +0 -65
- data/app/commands/trueandco_analytics/session_c/put_data.rb +0 -46
- data/app/commands/trueandco_analytics/user_c/create_or_update_user_if_exist.rb +0 -41
- data/app/models/trueandco_analytics/metric_user_visit.rb +0 -8
- data/app/workers/trueandco_analytics/user_session_metric_worker.rb +0 -21
- data/lib/trueandco_analytics/helpers/trueandco_analytics_helper.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1241ce35d2d3abe849c6b93ab9ae68c6abfbfe10
|
4
|
+
data.tar.gz: e407cff3d27269307768b9014d717e94e9d7977d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b64cab1b28523f03e4fa8cdf9bdbbc9d8251c14a49b901611ca6b60b99220e8c424c8630697447eb1ecd88da3eed97aaaafa87968b8af7f6b54afeb63575652
|
7
|
+
data.tar.gz: 402681d71bfbef8c7fb13050a2145a68fb2e6f28e519d65bfde32f12f5fd6b54a5cc06182c7eec339c00e1e726099219d929d733b56fb465a0262bd424ac19ae
|
data/README.md
CHANGED
@@ -68,10 +68,7 @@ Many systems analysts do not provide data about the specific user. This gem allo
|
|
68
68
|
```ruby
|
69
69
|
bundle exec sidekiq --queue=user_metric
|
70
70
|
```
|
71
|
-
|
72
|
-
```ruby
|
73
|
-
config.eager_load = true
|
74
|
-
```
|
71
|
+
|
75
72
|
The application must have a route `root`
|
76
73
|
|
77
74
|
For use of the console mode. it is necessary to specify the current database.
|
@@ -124,8 +121,8 @@ Many systems analysts do not provide data about the specific user. This gem allo
|
|
124
121
|
* Specify the method available in the ApplicationController to the receiving user object. Containing id, email.
|
125
122
|
`config.user_method = 'current_user'`
|
126
123
|
|
127
|
-
* Specify css the selector
|
128
|
-
`config.
|
124
|
+
* Specify css the selector for the button purchase
|
125
|
+
`config.buy_selector = '.buy'`
|
129
126
|
|
130
127
|
* Specify the database where redis will store the statistics for the session user
|
131
128
|
```ruby
|
@@ -0,0 +1,28 @@
|
|
1
|
+
function analitics_in_point(statistics_url, app_token, selector, time_survey) {
|
2
|
+
function push_data_info() {
|
3
|
+
userLog.init({
|
4
|
+
clickCount: true,
|
5
|
+
clickDetails: true,
|
6
|
+
actionItem: {
|
7
|
+
processOnAction: !isEmpty(selector),
|
8
|
+
selector: selector,
|
9
|
+
event: 'click'
|
10
|
+
},
|
11
|
+
processTime: time_survey,
|
12
|
+
processData: function (results) {
|
13
|
+
var xhr = new XMLHttpRequest();
|
14
|
+
xhr.open('POST', statistics_url, true);
|
15
|
+
xhr.setRequestHeader('X-CSRF-Token', app_token);
|
16
|
+
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
17
|
+
var data = "user_metric=" + JSON.stringify(results);
|
18
|
+
xhr.send(data);
|
19
|
+
},
|
20
|
+
});
|
21
|
+
}
|
22
|
+
|
23
|
+
function isEmpty(str) {
|
24
|
+
return (!str || 0 === str.length);
|
25
|
+
}
|
26
|
+
|
27
|
+
push_data_info();
|
28
|
+
}
|
@@ -0,0 +1,165 @@
|
|
1
|
+
var userLog = (function(){
|
2
|
+
//
|
3
|
+
// Private variables
|
4
|
+
//
|
5
|
+
var defaults = {
|
6
|
+
|
7
|
+
// Available functionality
|
8
|
+
clickCount: true,
|
9
|
+
clickDetails: true,
|
10
|
+
|
11
|
+
// Action Item
|
12
|
+
actionItem: {
|
13
|
+
processOnAction: false,
|
14
|
+
selector: '',
|
15
|
+
event: ''
|
16
|
+
},
|
17
|
+
processTime: 15,
|
18
|
+
processData: function(results){
|
19
|
+
},
|
20
|
+
},
|
21
|
+
// End results, what is shown to the site
|
22
|
+
results = {
|
23
|
+
userReferrer: '',
|
24
|
+
time: {
|
25
|
+
totalTime: 0,
|
26
|
+
timeOnPage: 0,
|
27
|
+
timestamp: 0
|
28
|
+
},
|
29
|
+
clicks: {
|
30
|
+
clickCount:0,
|
31
|
+
clickDetails: []
|
32
|
+
},
|
33
|
+
|
34
|
+
},
|
35
|
+
support = !!document.querySelector && !!document.addEventListener,
|
36
|
+
settings;
|
37
|
+
|
38
|
+
// Helper Functions
|
39
|
+
var helperActions = {
|
40
|
+
|
41
|
+
userReferrer: function (){
|
42
|
+
result = document.referrer;
|
43
|
+
results.userReferrer = 10;
|
44
|
+
},
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Detect the X,Y coordinates of the mouse movement
|
48
|
+
* @private
|
49
|
+
*/
|
50
|
+
mouseMovement: function(){
|
51
|
+
document.addEventListener('mousemove', function(){
|
52
|
+
results.mouseMovements.push({
|
53
|
+
timestamp: Date.now(),
|
54
|
+
x: event.pageX,
|
55
|
+
y: event.pageY
|
56
|
+
});
|
57
|
+
});
|
58
|
+
},
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Merge defaults with options
|
63
|
+
* @private
|
64
|
+
* @param {Object} default settings
|
65
|
+
* @param {Object} user options
|
66
|
+
* @returns {Object} merged object
|
67
|
+
*/
|
68
|
+
function getSettings(defaults, options){
|
69
|
+
var option;
|
70
|
+
for(option in options){
|
71
|
+
if(options.hasOwnProperty(option)){
|
72
|
+
defaults[option] = options[option];
|
73
|
+
}
|
74
|
+
}
|
75
|
+
return defaults;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Initialize the event listeners
|
80
|
+
* @public
|
81
|
+
* @param {Object} user options
|
82
|
+
*/
|
83
|
+
function init(options){
|
84
|
+
if(!support) return;
|
85
|
+
|
86
|
+
// Extend default options
|
87
|
+
if (options && typeof options === "object") {
|
88
|
+
settings = getSettings(defaults, options);
|
89
|
+
}
|
90
|
+
|
91
|
+
document.addEventListener('DOMContentLoaded', function() {
|
92
|
+
|
93
|
+
// Countdown Timer
|
94
|
+
window.setInterval(function(){
|
95
|
+
if(document['visibilityState'] === 'visible'){
|
96
|
+
results.time.timeOnPage++;
|
97
|
+
}
|
98
|
+
results.time.totalTime++;
|
99
|
+
// Check if we need to process results
|
100
|
+
if(settings.processTime > 0 && results.time.totalTime % settings.processTime === 0){
|
101
|
+
processResults();
|
102
|
+
}
|
103
|
+
},1000);
|
104
|
+
results.time.timestamp = (function() {
|
105
|
+
return Math.round((+new Date())/1000);
|
106
|
+
})();
|
107
|
+
|
108
|
+
// Click registration, increment click counter and save click time+position
|
109
|
+
if(settings.clickCount || settings.clickDetails){
|
110
|
+
document.addEventListener('mouseup', function(){
|
111
|
+
if(settings.clickCount){
|
112
|
+
results.clicks.clickCount++;
|
113
|
+
}
|
114
|
+
if(settings.clickDetails){
|
115
|
+
results.clicks.clickDetails.push({
|
116
|
+
timestamp: Date.now(),
|
117
|
+
node: event.target.outerHTML,
|
118
|
+
x: event.pageX,
|
119
|
+
y: event.pageY
|
120
|
+
});
|
121
|
+
}
|
122
|
+
});
|
123
|
+
}
|
124
|
+
|
125
|
+
// Mouse movements
|
126
|
+
if(settings.mouseMovement){
|
127
|
+
helperActions.mouseMovement();
|
128
|
+
}
|
129
|
+
|
130
|
+
// referral
|
131
|
+
if(settings.userReferrer){
|
132
|
+
helperActions.userReferrer();
|
133
|
+
}
|
134
|
+
|
135
|
+
// Event Listener to porcess
|
136
|
+
if(settings.actionItem.processOnAction){
|
137
|
+
var node = document.querySelector(settings.actionItem.selector);
|
138
|
+
if(!!!node) throw new Error('Selector was not found.');
|
139
|
+
node.addEventListener(settings.actionItem.event, function(){
|
140
|
+
return processResults();
|
141
|
+
})
|
142
|
+
}
|
143
|
+
});
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Calls provided function with results as parameter
|
148
|
+
* @public
|
149
|
+
*/
|
150
|
+
function processResults(){
|
151
|
+
if(settings.hasOwnProperty('processData')){
|
152
|
+
var result = settings.processData.call(undefined, results);
|
153
|
+
results.clicks.clickDetails = []
|
154
|
+
return result;
|
155
|
+
}
|
156
|
+
return false;
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
// Module pattern, only expose necessary methods
|
161
|
+
return {
|
162
|
+
init: init,
|
163
|
+
processResults: processResults,
|
164
|
+
};
|
165
|
+
})();
|
@@ -1,170 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
// Private variables
|
4
|
-
//
|
5
|
-
var defaults = {
|
1
|
+
//= require analitics_script
|
2
|
+
//= require analitics_in_point
|
6
3
|
|
7
|
-
// Available functionality
|
8
|
-
clickCount: true,
|
9
|
-
clickDetails: true,
|
10
|
-
|
11
|
-
// Action Item
|
12
|
-
actionItem: {
|
13
|
-
processOnAction: false,
|
14
|
-
selector: '',
|
15
|
-
event: ''
|
16
|
-
},
|
17
|
-
processTime: 15,
|
18
|
-
processData: function(results, statistics_url){
|
19
|
-
console.log(results);
|
20
|
-
},
|
21
|
-
},
|
22
|
-
// End results, what is shown to the user
|
23
|
-
results = {
|
24
|
-
userReferrer: '',
|
25
|
-
time: {
|
26
|
-
totalTime: 0,
|
27
|
-
timeOnPage: 0,
|
28
|
-
timestamp: 0
|
29
|
-
},
|
30
|
-
clicks: {
|
31
|
-
clickCount:0,
|
32
|
-
clickDetails: []
|
33
|
-
},
|
34
|
-
|
35
|
-
},
|
36
|
-
support = !!document.querySelector && !!document.addEventListener,
|
37
|
-
data_receiver = '',
|
38
|
-
app_token = '',
|
39
|
-
settings;
|
40
|
-
|
41
|
-
// Helper Functions
|
42
|
-
var helperActions = {
|
43
|
-
|
44
|
-
userReferrer: function (){
|
45
|
-
result = document.referrer;
|
46
|
-
results.userReferrer = 10;
|
47
|
-
},
|
48
|
-
|
49
|
-
/**
|
50
|
-
* Detect the X,Y coordinates of the mouse movement
|
51
|
-
* @private
|
52
|
-
*/
|
53
|
-
mouseMovement: function(){
|
54
|
-
document.addEventListener('mousemove', function(){
|
55
|
-
results.mouseMovements.push({
|
56
|
-
timestamp: Date.now(),
|
57
|
-
x: event.pageX,
|
58
|
-
y: event.pageY
|
59
|
-
});
|
60
|
-
});
|
61
|
-
},
|
62
|
-
}
|
63
|
-
|
64
|
-
/**
|
65
|
-
* Merge defaults with options
|
66
|
-
* @private
|
67
|
-
* @param {Object} default settings
|
68
|
-
* @param {Object} user options
|
69
|
-
* @returns {Object} merged object
|
70
|
-
*/
|
71
|
-
function getSettings(defaults, options){
|
72
|
-
var option;
|
73
|
-
for(option in options){
|
74
|
-
if(options.hasOwnProperty(option)){
|
75
|
-
defaults[option] = options[option];
|
76
|
-
}
|
77
|
-
}
|
78
|
-
return defaults;
|
79
|
-
}
|
80
|
-
|
81
|
-
/**
|
82
|
-
* Initialize the event listeners
|
83
|
-
* @public
|
84
|
-
* @param {Object} user options
|
85
|
-
*/
|
86
|
-
function init(statistics_url, token, options){
|
87
|
-
if(!support) return;
|
88
|
-
data_receiver = statistics_url;
|
89
|
-
app_token = token;
|
90
|
-
|
91
|
-
// Extend default options
|
92
|
-
if (options && typeof options === "object") {
|
93
|
-
settings = getSettings(defaults, options);
|
94
|
-
}
|
95
|
-
|
96
|
-
document.addEventListener('DOMContentLoaded', function() {
|
97
|
-
|
98
|
-
// Countdown Timer
|
99
|
-
window.setInterval(function(){
|
100
|
-
if(document['visibilityState'] === 'visible'){
|
101
|
-
results.time.timeOnPage++;
|
102
|
-
}
|
103
|
-
results.time.totalTime++;
|
104
|
-
// Check if we need to process results
|
105
|
-
if(settings.processTime > 0 && results.time.totalTime % settings.processTime === 0){
|
106
|
-
processResults();
|
107
|
-
}
|
108
|
-
},1000);
|
109
|
-
results.time.timestamp = (function() {
|
110
|
-
return Math.round((+new Date())/1000);
|
111
|
-
})();
|
112
|
-
|
113
|
-
// Click registration, increment click counter and save click time+position
|
114
|
-
if(settings.clickCount || settings.clickDetails){
|
115
|
-
document.addEventListener('mouseup', function(){
|
116
|
-
if(settings.clickCount){
|
117
|
-
results.clicks.clickCount++;
|
118
|
-
}
|
119
|
-
if(settings.clickDetails){
|
120
|
-
results.clicks.clickDetails.push({
|
121
|
-
timestamp: Date.now(),
|
122
|
-
node: event.target.outerHTML,
|
123
|
-
x: event.pageX,
|
124
|
-
y: event.pageY
|
125
|
-
});
|
126
|
-
}
|
127
|
-
});
|
128
|
-
}
|
129
|
-
|
130
|
-
// Mouse movements
|
131
|
-
if(settings.mouseMovement){
|
132
|
-
helperActions.mouseMovement();
|
133
|
-
}
|
134
|
-
|
135
|
-
// referral
|
136
|
-
if(settings.userReferrer){
|
137
|
-
helperActions.userReferrer();
|
138
|
-
}
|
139
|
-
|
140
|
-
// Event Listener to porcess
|
141
|
-
if(settings.actionItem.processOnAction){
|
142
|
-
var node = document.querySelector(settings.actionItem.selector);
|
143
|
-
if(!!!node) throw new Error('Selector was not found.');
|
144
|
-
node.addEventListener(settings.actionItem.event, function(){
|
145
|
-
return processResults();
|
146
|
-
})
|
147
|
-
}
|
148
|
-
});
|
149
|
-
}
|
150
|
-
|
151
|
-
/**
|
152
|
-
* Calls provided function with results as parameter
|
153
|
-
* @public
|
154
|
-
*/
|
155
|
-
function processResults(){
|
156
|
-
if(settings.hasOwnProperty('processData')){
|
157
|
-
var result = settings.processData.call(undefined, results, data_receiver, app_token);
|
158
|
-
results.clicks.clickDetails = []
|
159
|
-
return result;
|
160
|
-
}
|
161
|
-
return false;
|
162
|
-
}
|
163
|
-
|
164
|
-
|
165
|
-
// Module pattern, only expose necessary methods
|
166
|
-
return {
|
167
|
-
init: init,
|
168
|
-
processResults: processResults,
|
169
|
-
};
|
170
|
-
})();
|
File without changes
|
data/config/routes.rb
CHANGED
@@ -7,7 +7,7 @@ class CreateMetricUsers < ActiveRecord::Migration.try(:send, '[]', '5.1')
|
|
7
7
|
t.timestamp :last_active_datetime, null: false
|
8
8
|
end
|
9
9
|
|
10
|
-
add_column :metric_users, :hash_id, 'integer unsigned', null: false
|
10
|
+
add_column :metric_users, :hash_id, 'integer unsigned', null: false, unique: true
|
11
11
|
|
12
12
|
add_index(:metric_users, :user_id)
|
13
13
|
add_index(:metric_users, :hash_id)
|
data/exe/trueandco_analytics
CHANGED
@@ -6,20 +6,11 @@ require 'bundler/setup'
|
|
6
6
|
require 'i18n'
|
7
7
|
require 'optparse'
|
8
8
|
require 'fileutils'
|
9
|
-
require 'trueandco_analytics'
|
10
|
-
require 'trueandco_analytics/cli/common'
|
11
|
-
require 'trueandco_analytics/cli/report'
|
12
|
-
require "#{ENGINE_ROOT}/app/commands/trueandco_analytics/report_c/generate"
|
13
9
|
require 'active_record'
|
14
10
|
require 'mysql2'
|
11
|
+
require 'trueandco_analytics'
|
15
12
|
require "#{CURRENT_PATH}config/initializers/trueandco_analytics"
|
16
13
|
|
17
|
-
models_dir = "#{ENGINE_ROOT}/app/models/trueandco_analytics/"
|
18
|
-
require "#{models_dir}application_record.rb"
|
19
|
-
Dir["#{models_dir}/*.rb"].each do |f|
|
20
|
-
require f
|
21
|
-
end
|
22
|
-
|
23
14
|
connect_db = TrueandcoAnalytics::Config::Params.connect_db
|
24
15
|
1.times do
|
25
16
|
break if connect_db.nil?
|
@@ -2,13 +2,13 @@ TrueandcoAnalytics.setup do |config|
|
|
2
2
|
# Time survey Analytics seconds
|
3
3
|
config.time_survey = 15
|
4
4
|
|
5
|
-
# Specify the method available in the ApplicationController to the receiving
|
5
|
+
# Specify the method available in the ApplicationController to the receiving site object. Containing id, email.
|
6
6
|
#config.user_method = 'current_user'
|
7
7
|
|
8
8
|
# Specify css the selector class for the button purchase
|
9
|
-
config.
|
9
|
+
config.buy_selector = '.buy'
|
10
10
|
|
11
|
-
# Specify the database where redis will store the statistics for the session
|
11
|
+
# Specify the database where redis will store the statistics for the session site
|
12
12
|
config.connect_redis = {
|
13
13
|
#url: "redis://your_host:6379",
|
14
14
|
#redis_password: '',
|