Class: TrackRelay::ClientId::Ga
- Inherits:
-
Object
- Object
- TrackRelay::ClientId::Ga
- Defined in:
- lib/track_relay/client_id/ga.rb
Overview
Resolver that extracts the GA4-shaped ‘client_id` from the host app’s ‘_ga` cookie.
Default position-0 entry in TrackRelay::Configuration#client_id_resolvers. Reproduces Phase 01’s ‘_track_relay_client_id_from_cookie` parser bit-for-bit so existing behavior is preserved when the resolver chain is enabled.
## ‘_ga` cookie format
The ‘_ga` cookie ships with format `GA1.<version>.<random_int>.<unix_ts>` (four dot-separated segments). The GA4 Measurement Protocol expects the client_id to be the last two segments joined with a dot — e.g. cookie `“GA1.2.860784081.1732738496”` yields client_id `“860784081.1732738496”`.
The parser always takes the last two segments (‘parts`) rather than the 3rd/4th, so it is robust against:
- Custom server-side cookie writers that prepend extra segments
- Future Google rollouts that change the prefix segment count
Cookies with fewer than four segments are treated as malformed and yield ‘nil` (callers should fall through to the next resolver in the chain).
Instance Method Summary collapse
-
#call(controller:) ⇒ String?
The parsed GA4 client_id, or ‘nil` when the cookie is missing/empty/malformed.
Instance Method Details
#call(controller:) ⇒ String?
Returns the parsed GA4 client_id, or ‘nil` when the cookie is missing/empty/malformed.
37 38 39 40 41 42 43 44 45 |
# File 'lib/track_relay/client_id/ga.rb', line 37 def call(controller:, **) = controller&.request&.&.[]("_ga") return nil if .nil? || .empty? parts = .split(".") return nil if parts.size < 4 "#{parts[-2]}.#{parts[-1]}" end |