class SnowplowRubyDuid::Cookie

Responsible for generating a cookie that emulates the Snowplow cookie as closely as possible Leverages the method used by ActionDispatch::Cookies::CookieJar to determine the top-level domain

Constants

See: github.com/snowplow/snowplow-javascript-tracker/blob/d3d10067127eb5c95d0054c8ae60f3bdccba619d/src/js/tracker.js#L156

See: github.com/snowplow/snowplow-javascript-tracker/blob/d3d10067127eb5c95d0054c8ae60f3bdccba619d/src/js/tracker.js#L142

DOMAIN_REGEXP

See: github.com/rails/rails/blob/b1124a2ac88778c0feb0157ac09367cbd204bf01/actionpack/lib/action_dispatch/middleware/cookies.rb#L214

Public Class Methods

new(host, domain_userid, request_created_at, options = {}) click to toggle source
# File lib/snowplow_ruby_duid/cookie.rb, line 14
def initialize(host, domain_userid, request_created_at, options = {})
  @host               = host
  @domain_userid      = domain_userid
  @request_created_at = request_created_at
  @secure             = options.fetch(:secure)
  @same_site          = options.fetch(:same_site)
end

Public Instance Methods

key() click to toggle source

See: github.com/snowplow/snowplow-javascript-tracker/blob/d3d10067127eb5c95d0054c8ae60f3bdccba619d/src/js/tracker.js#L358-L360 See: github.com/snowplow/snowplow-javascript-tracker/blob/d3d10067127eb5c95d0054c8ae60f3bdccba619d/src/js/tracker.js#L372-L374

# File lib/snowplow_ruby_duid/cookie.rb, line 24
def key
  domain = top_level_domain || @host
  KEY_PREFIX + '.' + Digest::SHA1.hexdigest(domain + COOKIE_PATH)[0..3]
end
value() click to toggle source
# File lib/snowplow_ruby_duid/cookie.rb, line 29
def value
  cookie_domain = ".#{top_level_domain}" unless top_level_domain.nil?

  base = {
    value: cookie_value,
    expires: cookie_expiration,
    domain: cookie_domain,
    path: COOKIE_PATH,
    same_site: @same_site
  }

  base.merge!(secure: true) if @secure

  base
end

Private Instance Methods

top_level_domain() click to toggle source

See: github.com/rails/rails/blob/b1124a2ac88778c0feb0157ac09367cbd204bf01/actionpack/lib/action_dispatch/middleware/cookies.rb#L286-L294

# File lib/snowplow_ruby_duid/cookie.rb, line 48
def top_level_domain
  $& if (@host !~ /^[\d.]+$/) && (@host =~ DOMAIN_REGEXP)
end