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
@@ -1,16 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module TrueandcoAnalytics
|
1
|
+
module TrueandcoAnalytics::Site
|
4
2
|
class ReceiverController < ApplicationController
|
5
|
-
|
3
|
+
|
6
4
|
def pull_user_statistic
|
7
5
|
data = JSON.parse(params[:user_metric])
|
8
6
|
userInfo = request.user_agent
|
9
7
|
page_path = request.url.match(/(?:\/\/.+?\/)(.+?)(?=\?|$)/)[1]
|
10
|
-
data = data.merge({
|
8
|
+
data = data.merge({page_path: page_path}).to_json
|
11
9
|
request_info = {
|
12
|
-
|
13
|
-
|
10
|
+
'remote_ip' => request.remote_ip,
|
11
|
+
'user_agent' => request.user_agent
|
14
12
|
}
|
15
13
|
SessionC::PutData.new(data, request_info, userInfo).execute
|
16
14
|
render nothing: true, status: 201, content_type: 'text/plain'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module TrueandcoAnalytics::Site::TrueandcoAnalyticsHelper
|
2
|
+
def track_user_behavior
|
3
|
+
pull_user_statistic_path = ::TrueandcoAnalytics::Engine.routes.url_helpers.receiver_pull_user_statistic_path
|
4
|
+
return unless @user_behavior.nil?
|
5
|
+
@user_behavior = 1
|
6
|
+
js_string = <<-USER_BEHAVIOR_TRACK
|
7
|
+
|
8
|
+
var statistics_url = "#{root_url.chomp('/')}#{pull_user_statistic_path}",
|
9
|
+
app_token = "#{form_authenticity_token}",
|
10
|
+
selector = "#{::TrueandcoAnalytics::Config::Params.buy_selector}",
|
11
|
+
time_survey = "#{::TrueandcoAnalytics::Config::Params.time_survey}";
|
12
|
+
|
13
|
+
analitics_in_point(statistics_url, app_token, selector, time_survey);
|
14
|
+
|
15
|
+
USER_BEHAVIOR_TRACK
|
16
|
+
javascript_tag js_string, defer: 'defer'
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module TrueandcoAnalytics::Site
|
2
|
+
class UserSessionMetricWorker
|
3
|
+
include Sidekiq::Worker
|
4
|
+
sidekiq_options queue: :user_metric
|
5
|
+
|
6
|
+
def perform(*args)
|
7
|
+
info_pages, info_request = args[0], args[1]
|
8
|
+
@redis = ::TrueandcoAnalytics::RedisConnect.get
|
9
|
+
user_session_data_json = @redis.lrange(info_pages, 0, -1)
|
10
|
+
return if user_session_data_json.nil?
|
11
|
+
user_session_data = ArrJsonsToArrHash.new(user_session_data_json).execute
|
12
|
+
return unless user_session_data.any?
|
13
|
+
first_point = user_session_data[0]
|
14
|
+
last_point = user_session_data[-1]
|
15
|
+
metric_user = UserC::CreateOrUpdateUserIfExist.new(info_request['user_agent'], last_point['time']['timestamp']).execute
|
16
|
+
session = SessionC::Create.new(metric_user, first_point, last_point['time']['timestamp'], info_request).execute
|
17
|
+
MetricC::AddList.new(metric_user, session, user_session_data).execute
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trueandco_analytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moroz Ivan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -175,45 +175,47 @@ files:
|
|
175
175
|
- MIT-LICENSE
|
176
176
|
- README.md
|
177
177
|
- Rakefile
|
178
|
+
- app/assets/javascripts/analitics_in_point.js
|
179
|
+
- app/assets/javascripts/analitics_script.js
|
178
180
|
- app/assets/javascripts/trueandco_analytics.js
|
179
|
-
- app/
|
180
|
-
- app/commands/trueandco_analytics/metric_c/add_list.rb
|
181
|
-
- app/commands/trueandco_analytics/report_c/generate.rb
|
182
|
-
- app/commands/trueandco_analytics/session_c/create.rb
|
183
|
-
- app/commands/trueandco_analytics/session_c/put_data.rb
|
184
|
-
- app/commands/trueandco_analytics/user_c/create_or_update_user_if_exist.rb
|
185
|
-
- app/controllers/trueandco_analytics/application_controller.rb
|
186
|
-
- app/controllers/trueandco_analytics/reciver_controller.rb
|
187
|
-
- app/models/trueandco_analytics/application_record.rb
|
188
|
-
- app/models/trueandco_analytics/metric_user.rb
|
189
|
-
- app/models/trueandco_analytics/metric_user_session.rb
|
190
|
-
- app/models/trueandco_analytics/metric_user_visit.rb
|
191
|
-
- app/views/trueandco_analytics/receiver/pull_user_statistic.erb
|
192
|
-
- app/workers/trueandco_analytics/user_session_metric_worker.rb
|
181
|
+
- app/views/trueandco_analytics/site/receiver/pull_user_statistic.erb
|
193
182
|
- config/routes.rb
|
194
183
|
- config/secrets.yml
|
195
184
|
- db/migrate/20170802133950_create_metric_users.rb
|
196
185
|
- db/migrate/20170802134044_create_metric_user_visits.rb
|
197
186
|
- db/migrate/20170802134059_create_metric_user_sessions.rb
|
198
187
|
- exe/trueandco_analytics
|
199
|
-
- lib/extension_string.rb
|
200
188
|
- lib/generators/trueandco_analytics/install_generator.rb
|
201
189
|
- lib/generators/trueandco_analytics/templates/trueandco_analytics.rb
|
202
190
|
- lib/trueandco_analytics.rb
|
203
|
-
- lib/trueandco_analytics/
|
204
|
-
- lib/trueandco_analytics/
|
191
|
+
- lib/trueandco_analytics/common/locales/en.yml
|
192
|
+
- lib/trueandco_analytics/common/models/application_record.rb
|
193
|
+
- lib/trueandco_analytics/common/models/metric_user.rb
|
194
|
+
- lib/trueandco_analytics/common/models/metric_user_session.rb
|
195
|
+
- lib/trueandco_analytics/common/models/metric_user_visit.rb
|
196
|
+
- lib/trueandco_analytics/common/modules/info.rb
|
197
|
+
- lib/trueandco_analytics/common/reports/application_report.rb
|
198
|
+
- lib/trueandco_analytics/common/reports/details_report.rb
|
199
|
+
- lib/trueandco_analytics/common/reports/page_buy_in_date_range_report.rb
|
200
|
+
- lib/trueandco_analytics/common/services/logger.rb
|
201
|
+
- lib/trueandco_analytics/common/services/redis_connect.rb
|
202
|
+
- lib/trueandco_analytics/common/services/reports.rb
|
203
|
+
- lib/trueandco_analytics/common/services/workers.rb
|
205
204
|
- lib/trueandco_analytics/config/params.rb
|
205
|
+
- lib/trueandco_analytics/console/cli/common.rb
|
206
|
+
- lib/trueandco_analytics/console/cli/report.rb
|
207
|
+
- lib/trueandco_analytics/console/commands/report_c/generate.rb
|
208
|
+
- lib/trueandco_analytics/console/extension_string.rb
|
206
209
|
- lib/trueandco_analytics/engine.rb
|
207
|
-
- lib/trueandco_analytics/
|
208
|
-
- lib/trueandco_analytics/
|
209
|
-
- lib/trueandco_analytics/
|
210
|
-
- lib/trueandco_analytics/
|
211
|
-
- lib/trueandco_analytics/
|
212
|
-
- lib/trueandco_analytics/
|
213
|
-
- lib/trueandco_analytics/
|
214
|
-
- lib/trueandco_analytics/
|
215
|
-
- lib/trueandco_analytics/
|
216
|
-
- lib/trueandco_analytics/services/workers.rb
|
210
|
+
- lib/trueandco_analytics/site/commands/arr_jsons_to_arr_hash.rb
|
211
|
+
- lib/trueandco_analytics/site/commands/metric_c/add_list.rb
|
212
|
+
- lib/trueandco_analytics/site/commands/session_c/create.rb
|
213
|
+
- lib/trueandco_analytics/site/commands/session_c/put_data.rb
|
214
|
+
- lib/trueandco_analytics/site/commands/user_c/create_or_update_user_if_exist.rb
|
215
|
+
- lib/trueandco_analytics/site/controllers/application_controller.rb
|
216
|
+
- lib/trueandco_analytics/site/controllers/reciver_controller.rb
|
217
|
+
- lib/trueandco_analytics/site/helpers/trueandco_analytics_helper.rb
|
218
|
+
- lib/trueandco_analytics/site/workers/user_session_metric_worker.rb
|
217
219
|
- lib/trueandco_analytics/version.rb
|
218
220
|
homepage: ''
|
219
221
|
licenses:
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module TrueandcoAnalytics
|
2
|
-
module MetricC
|
3
|
-
class AddList
|
4
|
-
|
5
|
-
def initialize(metric_user, session, user_session_data)
|
6
|
-
if metric_user.nil? || session.nil? || user_session_data.nil?
|
7
|
-
raise ArgumentError.new("#{self.to_s} metric_user=#{metric_user}
|
8
|
-
session=#{session} user_session_data=#{user_session_data}")
|
9
|
-
end
|
10
|
-
@metric_user = metric_user
|
11
|
-
@session = session
|
12
|
-
@user_session_data = user_session_data
|
13
|
-
end
|
14
|
-
|
15
|
-
def execute
|
16
|
-
uniq_pages = info_uniq_page
|
17
|
-
return if uniq_pages.nil?
|
18
|
-
uniq_pages.each do |page|
|
19
|
-
data = {
|
20
|
-
metric_user: metric_user,
|
21
|
-
metric_user_session: session,
|
22
|
-
page_path: page['page_path'],
|
23
|
-
user_action: page['clicks']['clickDetails'].to_json,
|
24
|
-
time_s: page['time']['timeOnPage'],
|
25
|
-
is_buy: page['clicks']['clickDetails'].length > 0
|
26
|
-
}
|
27
|
-
MetricUserVisit.create(data)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
attr_reader :metric_user, :session, :user_session_data
|
34
|
-
|
35
|
-
def info_uniq_page
|
36
|
-
length = user_session_data.length
|
37
|
-
return user_session_data if length < 2
|
38
|
-
results = []
|
39
|
-
page = user_session_data[0]['page_path']
|
40
|
-
clickDetails = []
|
41
|
-
index = 0
|
42
|
-
while index < length - 1
|
43
|
-
unless user_session_data[index]['clicks']['clickDetails'].empty?
|
44
|
-
clickDetails = user_session_data[index]['clicks']['clickDetails']
|
45
|
-
end
|
46
|
-
index += 1
|
47
|
-
unless page == user_session_data[index]['page_path']
|
48
|
-
data = user_session_data[index - 1]
|
49
|
-
data['clicks']['clickDetails'] = clickDetails
|
50
|
-
results << data
|
51
|
-
page = user_session_data[index]['page_path']
|
52
|
-
clickDetails = []
|
53
|
-
end
|
54
|
-
end
|
55
|
-
data = user_session_data[index]
|
56
|
-
unless data['clicks']['clickDetails'].empty?
|
57
|
-
clickDetails = data['clicks']['clickDetails']
|
58
|
-
end
|
59
|
-
data['clicks']['clickDetails'] = clickDetails
|
60
|
-
results << data
|
61
|
-
results
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module TrueandcoAnalytics
|
2
|
-
module ReportC
|
3
|
-
class Generate
|
4
|
-
include TrueandcoAnalytics::Modules::Info
|
5
|
-
|
6
|
-
def initialize(name: nil, format: nil, datetime_start: nil, datetime_end: nil, path: nil)
|
7
|
-
@name = name
|
8
|
-
@format = format
|
9
|
-
@datetime_start = datetime_start
|
10
|
-
@datetime_end = datetime_end
|
11
|
-
@path = path || CURRENT_PATH
|
12
|
-
end
|
13
|
-
|
14
|
-
def execute
|
15
|
-
report = ::TrueandcoAnalytics::Reports.get_report_obj(name, format, datetime_start, datetime_end)
|
16
|
-
return if report.nil? || report.data.empty?
|
17
|
-
@path += report.report_name if File.directory?(path)
|
18
|
-
dirname = File.dirname(path)
|
19
|
-
unless File.directory?(dirname)
|
20
|
-
FileUtils.mkdir_p(dirname)
|
21
|
-
end
|
22
|
-
File.open(path, 'w+') { |f| f.write(report.data) }
|
23
|
-
result(I18n.t('trueandco_analytics.result.done', path: path))
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
attr_reader :name, :format, :datetime_start, :datetime_end, :path
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
module TrueandcoAnalytics
|
2
|
-
module SessionC
|
3
|
-
class Create
|
4
|
-
|
5
|
-
def initialize(metric_user, first_point, timestamp_end, request_info)
|
6
|
-
|
7
|
-
if metric_user.nil? || first_point.nil? || timestamp_end.nil? ||request_info.nil?
|
8
|
-
raise ArgumentError.new("#{self.to_s} metric_user=#{metric_user}
|
9
|
-
first_point=#{first_point} timestamp_end=#{timestamp_end} request_info=#{request_info}")
|
10
|
-
end
|
11
|
-
|
12
|
-
@metric_user = metric_user
|
13
|
-
@ip = request_info['remote_ip']
|
14
|
-
@user_agent = request_info['user_agent']
|
15
|
-
@session_start = first_point['time']['timestamp']
|
16
|
-
@referer = first_point['userReferrer']
|
17
|
-
@live_time_s = timestamp_end - @session_start
|
18
|
-
end
|
19
|
-
|
20
|
-
def execute
|
21
|
-
Browser::Base.include(Browser::Aliases)
|
22
|
-
browser = Browser.new(user_agent, accept_language: "en-us")
|
23
|
-
data = {
|
24
|
-
metric_user: metric_user,
|
25
|
-
user_agent: user_agent,
|
26
|
-
referer: referer,
|
27
|
-
session_start: datetime_session_start,
|
28
|
-
live_time_s: 60,
|
29
|
-
ip_4: ip_v4(ip),
|
30
|
-
ip_6: ip_v6(ip),
|
31
|
-
browser: browser.name,
|
32
|
-
is_mobile: browser.mobile? || false
|
33
|
-
}
|
34
|
-
MetricUserSession.create(data)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
attr_reader :metric_user, :ip, :user_agent, :session_start, :live_time_s, :referer
|
40
|
-
|
41
|
-
def datetime_session_start
|
42
|
-
DateTime.strptime(session_start.to_s,'%s')
|
43
|
-
end
|
44
|
-
|
45
|
-
def ip_v4(ip)
|
46
|
-
ip_o = get_ip_object(ip)
|
47
|
-
result = 0
|
48
|
-
result = ip_o.to_i if ip_o.ipv4?
|
49
|
-
result
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def ip_v6(ip)
|
54
|
-
ip_o = get_ip_object(ip)
|
55
|
-
result = 0
|
56
|
-
result = ip_o.data if ip_o.ipv6?
|
57
|
-
result
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_ip_object(ip)
|
61
|
-
@ip_o ||= IPAddress.parse ip
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module TrueandcoAnalytics
|
2
|
-
module SessionC
|
3
|
-
class PutData
|
4
|
-
|
5
|
-
def initialize(json_data, request_info, userInfo)
|
6
|
-
@json_data = json_data
|
7
|
-
@userInfo = userInfo
|
8
|
-
@request_info = request_info
|
9
|
-
@redis = RedisConnect.get
|
10
|
-
@time_survey = Config::Params.time_survey
|
11
|
-
@time_dead_session = Config::Params.time_dead_session
|
12
|
-
end
|
13
|
-
|
14
|
-
def execute
|
15
|
-
1.times do
|
16
|
-
break if userInfo.nil? || userInfo.empty?
|
17
|
-
user_key = ::FNV.new.fnv1_32 userInfo.to_s
|
18
|
-
mange_job(user_key)
|
19
|
-
redis.rpush(user_key, json_data)
|
20
|
-
redis.expire(user_key, time_dead_session + 3)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
attr_reader :json_data, :userInfo, :request_info, :redis, :time_dead_session, :time_survey
|
27
|
-
|
28
|
-
def mange_job(user_key)
|
29
|
-
user_job_key = "#{user_key}:job_key"
|
30
|
-
unless redis.exists user_job_key
|
31
|
-
create_job(user_key, user_job_key)
|
32
|
-
end
|
33
|
-
if redis.ttl(user_job_key) < time_survey * 3
|
34
|
-
job_id = redis.get(user_job_key)
|
35
|
-
Sidekiq::ScheduledSet.new.find_job(job_id)&.delete
|
36
|
-
create_job(user_key, user_job_key)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def create_job(user_key, user_job_key)
|
41
|
-
job_id = UserSessionMetricWorker.perform_at(time_dead_session.seconds.from_now, user_key, request_info)
|
42
|
-
redis.setex(user_job_key, time_dead_session, job_id)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module TrueandcoAnalytics
|
2
|
-
module UserC
|
3
|
-
class CreateOrUpdateUserIfExist
|
4
|
-
|
5
|
-
def initialize(user_agent, timestamp_end)
|
6
|
-
if user_agent.nil? || timestamp_end.nil?
|
7
|
-
raise ArgumentError.new("#{self.to_s} user_agent=#{user_agent} timestamp_end=#{timestamp_end}")
|
8
|
-
end
|
9
|
-
@user_agent = user_agent
|
10
|
-
@timestamp_end = timestamp_end
|
11
|
-
@user_id = Config::Params.user_method&.id
|
12
|
-
end
|
13
|
-
|
14
|
-
def execute
|
15
|
-
user = nil
|
16
|
-
user = TrueandcoAnalytics::MetricUser.find_by(user_id: user_id) if user_id
|
17
|
-
user = TrueandcoAnalytics::MetricUser.find_by(hash_id: hash_id) if user.nil?
|
18
|
-
user = if user.nil?
|
19
|
-
TrueandcoAnalytics::MetricUser.create(user_id: user_id || 0, datetime_create: datetime_end,
|
20
|
-
last_active_datetime: datetime_end, hash_id: hash_id)
|
21
|
-
else
|
22
|
-
user.update_attribute(:last_active_datetime, datetime_end)
|
23
|
-
user
|
24
|
-
end
|
25
|
-
user
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
attr_reader :user_agent, :timestamp_end, :user_id
|
31
|
-
|
32
|
-
def datetime_end
|
33
|
-
DateTime.strptime(timestamp_end.to_s,'%s')
|
34
|
-
end
|
35
|
-
|
36
|
-
def hash_id
|
37
|
-
@hash_id ||= FNV.new.fnv1_32(user_agent)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module TrueandcoAnalytics
|
2
|
-
|
3
|
-
class UserSessionMetricWorker
|
4
|
-
include Sidekiq::Worker
|
5
|
-
sidekiq_options queue: :user_metric
|
6
|
-
|
7
|
-
def perform(*args)
|
8
|
-
info_pages,info_request = args[0],args[1]
|
9
|
-
@redis = RedisConnect.get
|
10
|
-
user_session_data_json = @redis.lrange(info_pages, 0, -1)
|
11
|
-
return if user_session_data_json.nil?
|
12
|
-
user_session_data = ArrJsonsToArrHash.new(user_session_data_json).execute
|
13
|
-
return unless user_session_data.any?
|
14
|
-
first_point = user_session_data[0]
|
15
|
-
last_point = user_session_data[-1]
|
16
|
-
metric_user = UserC::CreateOrUpdateUserIfExist.new(info_request['user_agent'], last_point['time']['timestamp']).execute
|
17
|
-
session = SessionC::Create.new(metric_user, first_point, last_point['time']['timestamp'], info_request).execute
|
18
|
-
MetricC::AddList.new(metric_user, session, user_session_data).execute
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|