Skip to content

Instantly share code, notes, and snippets.

@jwarchol
Created July 29, 2010 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwarchol/499417 to your computer and use it in GitHub Desktop.
Save jwarchol/499417 to your computer and use it in GitHub Desktop.
# Calculates the domain hash part of a Google Analytics __utma cookie's value.
def domain_hash(domain_name)
domain_hash = 0
g = 0
(domain_name.size - 1).downto(0) do |i|
c = domain_name[i]
domain_hash = ((domain_hash << 6) & 268435455) + c + (c << 14)
g = (domain_hash & 266338304)
if g != 0
domain_hash = (domain_hash ^ (g >> 21))
end
end
domain_hash
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment