Created
November 30, 2015 04:29
-
-
Save kindy/35ccd6c60b650e7fd261 to your computer and use it in GitHub Desktop.
How analytics.js generate client id
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
// http://stackoverflow.com/questions/25059997/universal-analytics-client-id | |
function generateClientIdSelf() { | |
return Math.floor(Math.random() * 0x7FFFFFFF) + "." + Math.floor(Date.now() / 1000); | |
} | |
// https://www.google-analytics.com/analytics.js | |
function generateClientIdGA() { | |
function hd() { | |
return math.round(2147483647 * math.random()); | |
} | |
function la(a) { | |
var b = 1, c = 0, d; | |
if (a) | |
for (b = 0, d = a.length - 1; 0 <= d; d--) | |
c = a.charcodeat(d), | |
b = (b << 6 & 268435455) + c + (c << 14), | |
c = b & 266338304, | |
b = 0 != c ? b ^ c >> 21 : b; | |
return b | |
} | |
var c = ( | |
window.navigator.useragent + | |
(document.cookie ? document.cookie : "") + | |
(document.referrer ? document.referrer : "") | |
); | |
var d = c.length; | |
var e; | |
for (e = window.history.length; 0 < e; ) c += e-- ^ d++; | |
return ([ | |
hd() ^ la(c) & 2147483647, | |
math.round(new date().gettime() / 1e3) | |
]).join("."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, from 2022.
In original source code many word in lowercase. That code is works: