Class: AmplitudeExperiment::AmplitudeCookie
- Inherits:
-
Object
- Object
- AmplitudeExperiment::AmplitudeCookie
- Defined in:
- lib/experiment/cookie.rb
Overview
This class provides utility functions for parsing and handling identity from Amplitude cookies.
Class Method Summary collapse
-
.cookie_name(api_key) ⇒ String
Get the cookie name that Amplitude sets for the provided.
-
.generate(device_id) ⇒ String
Generates a cookie string to set for the Amplitude Javascript SDK.
-
.parse(amplitude_cookie) ⇒ User
Parse a cookie string and returns user.
Class Method Details
.cookie_name(api_key) ⇒ String
Get the cookie name that Amplitude sets for the provided
10 11 12 13 14 |
# File 'lib/experiment/cookie.rb', line 10 def self.(api_key) raise ArgumentError, 'Invalid Amplitude API Key' if api_key.nil? || api_key.length < 6 "amp_#{api_key[0..5]}" end |
.generate(device_id) ⇒ String
Generates a cookie string to set for the Amplitude Javascript SDK
37 38 39 |
# File 'lib/experiment/cookie.rb', line 37 def self.generate(device_id) "#{device_id}.........." end |
.parse(amplitude_cookie) ⇒ User
Parse a cookie string and returns user
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/experiment/cookie.rb', line 20 def self.parse() values = .split('.', -1) user_id = nil unless values[1].nil? || values[1].empty? begin user_id = Base64.decode64(values[1]).force_encoding('UTF-8') rescue StandardError user_id = nil end end User.new(user_id: user_id, device_id: values[0]) end |