Created
July 29, 2010 22:25
-
-
Save jwarchol/499417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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