trailguide 0.1.23 → 0.1.24
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/config/initializers/trailguide.rb +22 -0
- data/lib/trail_guide/adapters/participants/unity.rb +2 -0
- data/lib/trail_guide/catalog.rb +2 -1
- data/lib/trail_guide/config.rb +2 -1
- data/lib/trail_guide/participant.rb +27 -24
- data/lib/trail_guide/unity.rb +5 -0
- data/lib/trail_guide/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11e84a1721748ce5766e400941e5802dcc549cc7dc343172ea4379fbcc0b9aca
|
4
|
+
data.tar.gz: 7d7327e04519bc5998108c020792b4f646d525f3336ec0ebd3d865700895ea1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2170a96f4c9d24a440607c7691b43ae10cb783c53fcb11cc06e641ef98871e9d7a116379593a7569d3230980fd5d21a4d78504df1db2e0e8cc75fc876c068920
|
7
|
+
data.tar.gz: 31e9785970eb3710dc9f56a3525112031e7fa03b70178def7799d4e521179471d4c1d506e24b69199463ec991bfccf9b4d4294956a94e1c91d329c910f596ae8
|
@@ -48,6 +48,28 @@ TrailGuide.configure do |config|
|
|
48
48
|
# logged in/out sessions and across devices
|
49
49
|
config.adapter = :cookie
|
50
50
|
|
51
|
+
# whether or not to clean up any old/inactive experiments for participants
|
52
|
+
# regularly as part of the experiment flow - this is very fast, and only adds
|
53
|
+
# a couple milliseconds to participant initialization, but isn't strictly
|
54
|
+
# necessary, since expired enrollment will never affect future experiment
|
55
|
+
# participation - it might be good practice if you're using redis to store
|
56
|
+
# participant data without expiration
|
57
|
+
#
|
58
|
+
# true will clean up any old/inactive experiment keys for each
|
59
|
+
# participant the first time they're encountered during a script
|
60
|
+
# execution (web request, etc.)
|
61
|
+
# false will skip the cleanup process entirely
|
62
|
+
config.cleanup_participant_experiments = true
|
63
|
+
|
64
|
+
# the ttl (in seconds) for unity session unification keys - only applicable if
|
65
|
+
# you're using the unity adapter and/or are leveraging unity outside of
|
66
|
+
# trailguide experiments - particularly useful if you want to use something
|
67
|
+
# like the volatile-lru eviction policy for your redis instance
|
68
|
+
#
|
69
|
+
# nil no expiration for unity session unification keys
|
70
|
+
# 31556952 1 year (in seconds) expiration for unity keys
|
71
|
+
config.unity_ttl = nil
|
72
|
+
|
51
73
|
# callback when your participant adapter fails to initialize, and trailguide
|
52
74
|
# falls back to the anonymous adapter
|
53
75
|
config.on_adapter_failover = -> (adapter, error) do
|
@@ -14,11 +14,13 @@ module TrailGuide
|
|
14
14
|
config.user_adapter = TrailGuide::Adapters::Participants::Redis.configure do |config|
|
15
15
|
config.namespace = 'unity:users'
|
16
16
|
config.lookup = -> (user_id) { user_id }
|
17
|
+
config.expiration = 1.year.seconds
|
17
18
|
end
|
18
19
|
|
19
20
|
config.visitor_adapter = TrailGuide::Adapters::Participants::Redis.configure do |config|
|
20
21
|
config.namespace = 'unity:visitors'
|
21
22
|
config.lookup = -> (visitor_id) { visitor_id }
|
23
|
+
config.expiration = 1.year.seconds
|
22
24
|
end
|
23
25
|
|
24
26
|
config.anonymous_adapter = TrailGuide::Adapters::Participants::Anonymous
|
data/lib/trail_guide/catalog.rb
CHANGED
@@ -184,7 +184,8 @@ module TrailGuide
|
|
184
184
|
|
185
185
|
class DSL
|
186
186
|
def self.experiment(name, **opts, &block)
|
187
|
-
|
187
|
+
klass = opts.delete(:class) || TrailGuide::Experiment
|
188
|
+
Class.new(klass) do
|
188
189
|
configure opts.merge({name: name}), &block
|
189
190
|
end
|
190
191
|
end
|
data/lib/trail_guide/config.rb
CHANGED
@@ -3,7 +3,8 @@ module TrailGuide
|
|
3
3
|
DEFAULT_KEYS = [
|
4
4
|
:redis, :disabled, :override_parameter, :allow_multiple_experiments,
|
5
5
|
:adapter, :on_adapter_failover, :filtered_ip_addresses,
|
6
|
-
:filtered_user_agents, :request_filter, :include_helpers
|
6
|
+
:filtered_user_agents, :request_filter, :include_helpers,
|
7
|
+
:cleanup_participant_experiments, :unity_ttl
|
7
8
|
].freeze
|
8
9
|
|
9
10
|
def initialize(*args, **opts, &block)
|
@@ -1,35 +1,38 @@
|
|
1
1
|
module TrailGuide
|
2
2
|
class Participant
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :context
|
4
4
|
delegate :key?, :keys, :[], :[]=, :delete, :destroy!, :to_h, to: :adapter
|
5
5
|
|
6
6
|
def initialize(context, adapter: nil)
|
7
|
-
@
|
8
|
-
|
7
|
+
@context = context
|
8
|
+
@adapter = adapter.new(context) if adapter.present?
|
9
|
+
cleanup_inactive_experiments! if TrailGuide.configuration.cleanup_participant_experiments
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
12
|
+
def adapter
|
13
|
+
@adapter ||= begin
|
14
|
+
config_adapter = TrailGuide.configuration.adapter
|
15
|
+
case config_adapter
|
16
|
+
when :cookie
|
17
|
+
config_adapter = TrailGuide::Adapters::Participants::Cookie
|
18
|
+
when :session
|
19
|
+
config_adapter = TrailGuide::Adapters::Participants::Session
|
20
|
+
when :redis
|
21
|
+
config_adapter = TrailGuide::Adapters::Participants::Redis
|
22
|
+
when :anonymous
|
23
|
+
config_adapter = TrailGuide::Adapters::Participants::Anonymous
|
24
|
+
when :multi
|
25
|
+
config_adapter = TrailGuide::Adapters::Participants::Multi
|
26
|
+
else
|
27
|
+
config_adapter = config_adapter.constantize if config_adapter.is_a?(String)
|
28
|
+
end
|
29
|
+
config_adapter.new(context)
|
30
|
+
rescue => e
|
31
|
+
[TrailGuide.configuration.on_adapter_failover].flatten.compact.each do |callback|
|
32
|
+
callback.call(config_adapter, e)
|
33
|
+
end
|
34
|
+
TrailGuide::Adapters::Participants::Anonymous.new(context)
|
31
35
|
end
|
32
|
-
TrailGuide::Adapters::Participants::Anonymous
|
33
36
|
end
|
34
37
|
|
35
38
|
def variant(experiment)
|
data/lib/trail_guide/unity.rb
CHANGED
@@ -55,6 +55,11 @@ module TrailGuide
|
|
55
55
|
return false unless valid?
|
56
56
|
TrailGuide.redis.set(user_key, visitor_id)
|
57
57
|
TrailGuide.redis.set(visitor_key, user_id)
|
58
|
+
if TrailGuide.configuration.unity_ttl
|
59
|
+
TrailGuide.redis.expire(user_key, TrailGuide.configuration.unity_ttl)
|
60
|
+
TrailGuide.redis.expire(visitor_key, TrailGuide.configuration.unity_ttl)
|
61
|
+
end
|
62
|
+
true
|
58
63
|
end
|
59
64
|
|
60
65
|
def delete!
|
data/lib/trail_guide/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailguide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|