i_wonder 0.0.5 → 0.0.6
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.
@@ -10,7 +10,7 @@ module IWonder
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class Configuration
|
13
|
-
attr_accessor :keep_hits_for, :only_log_hits_on_200, :back_to_app_link, :app_name
|
13
|
+
attr_accessor :keep_hits_for, :only_log_hits_on_200, :back_to_app_link, :app_name, :return_visit_interval
|
14
14
|
attr_reader :controllers_to_ignore
|
15
15
|
|
16
16
|
def initialize
|
@@ -19,6 +19,7 @@ module IWonder
|
|
19
19
|
@only_log_hits_on_200 = true
|
20
20
|
@back_to_app_link = "/"
|
21
21
|
@app_name = "My App"
|
22
|
+
@return_visit_interval = 1.hour
|
22
23
|
end
|
23
24
|
|
24
25
|
def controllers_to_ignore=(new_controllers)
|
@@ -2,6 +2,7 @@ module IWonder
|
|
2
2
|
module Logging
|
3
3
|
class Middleware
|
4
4
|
NO_USER_KEY = "_no_user"
|
5
|
+
LAST_HIT_TIME = "_last_hit"
|
5
6
|
BOT_REGEX = /msnbot|yahoo|slurp|googlebot/
|
6
7
|
|
7
8
|
def initialize(app)
|
@@ -27,6 +28,7 @@ module IWonder
|
|
27
28
|
|
28
29
|
def process_env(env)
|
29
30
|
check_for_new_visitor(env) # this will set the i_wonder_session_id if blank. This session is needed later
|
31
|
+
check_for_return_visit(env)
|
30
32
|
log_hit(env)
|
31
33
|
merge_session_to_user(env)
|
32
34
|
generate_any_reported_events(env)
|
@@ -40,6 +42,20 @@ module IWonder
|
|
40
42
|
end
|
41
43
|
end
|
42
44
|
|
45
|
+
def check_for_return_visit(env)
|
46
|
+
env[ENV_KEY]["new_events"] ||= []
|
47
|
+
|
48
|
+
#is there a last_hit key
|
49
|
+
if cookies(env)[COOKIE_KEY+LAST_HIT_TIME]
|
50
|
+
previous_hit = Time.zone.parse(cookies(env)[COOKIE_KEY+LAST_HIT_TIME])
|
51
|
+
if previous_hit + IWonder.configuration.return_visit_interval < Time.zone.now
|
52
|
+
env[ENV_KEY]["new_events"] << {:event_type => "return_visit"}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
cookies(env).permanent[COOKIE_KEY+LAST_HIT_TIME] = Time.zone.now.to_s
|
57
|
+
end
|
58
|
+
|
43
59
|
def check_for_new_visitor(env)
|
44
60
|
if cookies(env)[COOKIE_KEY+SESSION_KEY_NAME].blank?
|
45
61
|
cookies(env).permanent[COOKIE_KEY+SESSION_KEY_NAME] = SecureRandom.hex(10) # this should swithc to something actually unique
|
data/lib/i_wonder/version.rb
CHANGED