Module: Shipeasy::SDK::AnonId
- Defined in:
- lib/shipeasy/sdk/anon_id.rb
Overview
Anonymous bucketing identity — the cross-SDK ‘__se_anon_id` cookie.
Gates and experiments bucket a unit with murmur3(salt:unit). For a logged-out visitor the unit is a stable anonymous id carried in a single first-party cookie that EVERY Shipeasy SDK (server + browser) reads and writes, so a server render and the browser bucket a fractional rollout identically. The cookie name + format are frozen across every language; see experiment-platform/18-identity-bucketing.md.
Constant Summary collapse
- COOKIE =
"__se_anon_id".freeze
- MAX_AGE =
1 year, in seconds
31_536_000- VALID_RX =
The cookie value is client-controllable and feeds bucketing, so a tampered value is treated as absent and a fresh id is minted. UUIDs satisfy this charset.
/\A[A-Za-z0-9_-]{1,64}\z/.freeze
- THREAD_KEY =
:shipeasy_anon_id
Class Method Summary collapse
-
.current ⇒ Object
The anon id RackMiddleware resolved for the current request, or nil when no middleware ran (e.g. a background job).
- .current=(value) ⇒ Object
-
.mint ⇒ Object
A fresh opaque bucketing id (UUIDv4).
- .valid?(value) ⇒ Boolean
Class Method Details
.current ⇒ Object
The anon id RackMiddleware resolved for the current request, or nil when no middleware ran (e.g. a background job). FlagsClient falls back to this as the default anonymous_id, so evaluations need no per-call wiring.
38 39 40 |
# File 'lib/shipeasy/sdk/anon_id.rb', line 38 def current Thread.current[THREAD_KEY] end |
.current=(value) ⇒ Object
42 43 44 |
# File 'lib/shipeasy/sdk/anon_id.rb', line 42 def current=(value) Thread.current[THREAD_KEY] = value end |
.mint ⇒ Object
A fresh opaque bucketing id (UUIDv4).
27 28 29 |
# File 'lib/shipeasy/sdk/anon_id.rb', line 27 def mint SecureRandom.uuid end |
.valid?(value) ⇒ Boolean
31 32 33 |
# File 'lib/shipeasy/sdk/anon_id.rb', line 31 def valid?(value) value.is_a?(String) && VALID_RX.match?(value) end |