amplitude-experiment 1.2.2 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/experiment/cookie.rb +34 -5
- data/lib/experiment/local/client.rb +7 -3
- data/lib/experiment/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: 63ef7a08ffb4bb4b179da3f088c12598d2212ba7edd35a2f48ebb029420f33c0
|
4
|
+
data.tar.gz: c46a6553343175e1bda5287907f565009217b58a97b611684eb5afe073ea58ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f127b8d728912018fa3d4f2a96c091f474f71b38d5f4d72ca06076f52204c6999511a2e65f2f43ba1ad7ab4f92906ba3c827343bf7c1af0085d766b46df6f8ba
|
7
|
+
data.tar.gz: 29d5c170df67401d9f43f8a2fa5c689693ef535cb4977aa799fc6c3d61194df304d203f2dfd5b921a8cb3ff0b32defeaa4b064d370886b410f2e4bc1260f03cb
|
data/lib/experiment/cookie.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'base64'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
module AmplitudeExperiment
|
4
5
|
# This class provides utility functions for parsing and handling identity from Amplitude cookies.
|
@@ -6,9 +7,17 @@ module AmplitudeExperiment
|
|
6
7
|
# Get the cookie name that Amplitude sets for the provided
|
7
8
|
#
|
8
9
|
# @param [String] api_key The Amplitude API Key
|
10
|
+
# @param [Boolean] new_format True if the cookie is in the Browser SDK 2.0 format
|
9
11
|
# @return [String] The cookie name that Amplitude sets for the provided
|
10
|
-
def self.cookie_name(api_key)
|
11
|
-
raise ArgumentError, 'Invalid Amplitude API Key' if api_key.nil?
|
12
|
+
def self.cookie_name(api_key, new_format: false)
|
13
|
+
raise ArgumentError, 'Invalid Amplitude API Key' if api_key.nil?
|
14
|
+
|
15
|
+
if new_format
|
16
|
+
raise ArgumentError, 'Invalid Amplitude API Key' if api_key.length < 10
|
17
|
+
|
18
|
+
return "AMP_#{api_key[0..9]}"
|
19
|
+
end
|
20
|
+
raise ArgumentError, 'Invalid Amplitude API Key' if api_key.length < 6
|
12
21
|
|
13
22
|
"amp_#{api_key[0..5]}"
|
14
23
|
end
|
@@ -16,8 +25,20 @@ module AmplitudeExperiment
|
|
16
25
|
# Parse a cookie string and returns user
|
17
26
|
#
|
18
27
|
# @param [String] amplitude_cookie A string from the amplitude cookie
|
28
|
+
# @param [Boolean] new_format True if the cookie is in the Browser SDK 2.0 format
|
19
29
|
# @return [User] a Experiment User context containing a device_id and user_id
|
20
|
-
def self.parse(amplitude_cookie)
|
30
|
+
def self.parse(amplitude_cookie, new_format: false)
|
31
|
+
if new_format
|
32
|
+
begin
|
33
|
+
decoding = Base64.decode64(amplitude_cookie).force_encoding('UTF-8')
|
34
|
+
json_data = URI.decode_www_form_component(decoding)
|
35
|
+
user_session_hash = JSON.parse(json_data)
|
36
|
+
return User.new(user_id: user_session_hash['userId'], device_id: user_session_hash['deviceId'])
|
37
|
+
rescue StandardError => e
|
38
|
+
puts "Error parsing the Amplitude cookie: #{e.message}"
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
end
|
21
42
|
values = amplitude_cookie.split('.', -1)
|
22
43
|
user_id = nil
|
23
44
|
unless values[1].nil? || values[1].empty?
|
@@ -33,9 +54,17 @@ module AmplitudeExperiment
|
|
33
54
|
# Generates a cookie string to set for the Amplitude Javascript SDK
|
34
55
|
#
|
35
56
|
# @param [String] device_id A device id to set
|
57
|
+
# @param [Boolean] new_format True if the cookie is in the Browser SDK 2.0 format
|
36
58
|
# @return [String] A cookie string to set for the Amplitude Javascript SDK to read
|
37
|
-
def self.generate(device_id)
|
38
|
-
"#{device_id}.........."
|
59
|
+
def self.generate(device_id, new_format: false)
|
60
|
+
return "#{device_id}.........." unless new_format
|
61
|
+
|
62
|
+
user_session_hash = {
|
63
|
+
'deviceId' => device_id
|
64
|
+
}
|
65
|
+
json_data = JSON.generate(user_session_hash)
|
66
|
+
encoded_json = URI.encode_www_form_component(json_data)
|
67
|
+
Base64.strict_encode64(encoded_json)
|
39
68
|
end
|
40
69
|
end
|
41
70
|
end
|
@@ -88,9 +88,13 @@ module AmplitudeExperiment
|
|
88
88
|
|
89
89
|
def run
|
90
90
|
@is_running = true
|
91
|
-
|
92
|
-
|
93
|
-
@
|
91
|
+
begin
|
92
|
+
flags = @fetcher.fetch_v1
|
93
|
+
@flags_mutex.synchronize do
|
94
|
+
@flags = flags
|
95
|
+
end
|
96
|
+
rescue StandardError => e
|
97
|
+
@logger.error("[Experiment] Flag poller - error: #{e.message}")
|
94
98
|
end
|
95
99
|
@poller_thread = Thread.new do
|
96
100
|
sleep(@config.flag_config_polling_interval_millis / 1000.to_f)
|
data/lib/experiment/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amplitude-experiment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amplitude
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|