Documented, including the official unminified source, in Google's analytics.js reference: <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/tracking-snippet-reference" rel="nofollow">https://developers.google.com/analytics/devguides/collection...</a>
The reason why the arguments spell isogram is because you can't have two arguments with the same letter. So they chose the most meta isogram, "isogram." Surprised the author missed that and assumed it was just reference to the script itself.
Something that has always puzzled me is why only GA follows the saner approach to push all the function calls in an array which the async loaded script can pick up later. Many of the popular analytics solutions (like, Segment, Mixpanel) create a factory function that initialises all API calls with a generic body. It seems rather unnecessary and only adds to the boilerplate. Take a look at the GA's init code and compare it with Segment's [1].<p>[1]: <a href="https://prnt.sc/fpj9ec" rel="nofollow">https://prnt.sc/fpj9ec</a>
Anyone not wanting to use the JS might be interested to know that the Google Analytics Measurement Protocol is fully documented, and you can create your own front-end implementation, should you wish:<p><a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/" rel="nofollow">https://developers.google.com/analytics/devguides/collection...</a>
I wrote almost the same post, with almost the same title a couple of years ago - <a href="https://www.ignoredbydinosaurs.com/posts/239-deconstructing-the-google-analytics-tag" rel="nofollow">https://www.ignoredbydinosaurs.com/posts/239-deconstructing-...</a><p>I like mine better :)
It is pretty obvious that the snippet loads the real script. I expected this article to be about what the actual google analytics tracking script does rather than the tracking script loader.
Tried to search but nothing obvious showed up. What's the purpose of the 1 in '1 * new Date()'?<p>Edit: found it. Gets the timestamp[1]<p>1. <a href="https://stackoverflow.com/questions/24182317/multiplication-with-date-object-javascript" rel="nofollow">https://stackoverflow.com/questions/24182317/multiplication-...</a>
On a related note, there is an open source Google Analytics alternative in the works:<p><a href="https://github.com/vesparny/fair-analytics" rel="nofollow">https://github.com/vesparny/fair-analytics</a><p>Hope it comes along; there is surprisingly not much else in the way of Node/JS based open source web stats/analytics solutions.
I have minimised it in my own case to just this (using ga.js instead of analytics.js because this part is shorter—regardless of the fact that ga.js itself is longer—and not worrying about any fanciness that I don’t need):<p><pre><code> <script>_gaq=[['_setAccount','UA-????????-?'],['_trackPageview']]</script><script async src=//ssl.google-analytics.com/ga.js></script>
</code></pre>
With analytics.js:<p><pre><code> <script>ga={q:[['create','UA-????????-?','auto'],['send','pageview']],l:+new Date}</script><script async src=//www.google-analytics.com/analytics.js></script></code></pre>
The reason it is a function that calls itself is to not pollute the global namespace. The rewritten expanded example leaks "gaScript" to the global namespace which is a little rude if you are injecting your script onto a third-party page and using a random or long function name is not as clean a solution since it still leaves dirt and takes more bytes.
Another interesting aspect of Google Analytics is understanding how fraudsters sneak by, and the discussions here on HN whenever this comes up.<p>Examples:<p>· Hackers Make $5M a Day by Faking 300M Video Views | <a href="https://news.ycombinator.com/item?id=13219871" rel="nofollow">https://news.ycombinator.com/item?id=13219871</a> (6 months ago)<p>· Uncovering an advertising fraud scheme | <a href="https://news.ycombinator.com/item?id=2333824" rel="nofollow">https://news.ycombinator.com/item?id=2333824</a> (6 years ago)<p>Discussions:<p>· Alleged $7.5B fraud in online advertising | <a href="https://news.ycombinator.com/item?id=9796102" rel="nofollow">https://news.ycombinator.com/item?id=9796102</a> (2 years ago)<p>· Inside Google's Secret War Against Ad Fraud | <a href="https://news.ycombinator.com/item?id=9628967" rel="nofollow">https://news.ycombinator.com/item?id=9628967</a> (2 years ago)
Here's something fun for people who wan't to customize what it says instead of 'isogram' (a fun little easter egg)<p><a href="https://isogrammer.com/" rel="nofollow">https://isogrammer.com/</a>
> <i>Interestingly, the arguments passed to the function spell out i, s, o, g, r, a, m, is a “term for a word or phrase without a repeating letter” (source), which I guess makes sense, given that the script looks like it has the bare minimum of characters possible.</i><p>I thought that was a kind of recursive joke (not necessarily a very witty one) : if they want to make the parameters spell out a word, the word <i>has</i> to be an isogram, otherwise you'd define a parameter twice. And since "isogram" is an isogram, maybe the temptation was too great..
> It seems like a and m are optional arguments.
> Now those unused parameters a and m come in handy. No writing var in this script.<p>Precisely. A trick to reduce the character count, nothing more. Love doing this kind of thing (<a href="http://gabrielgambetta.com/tiny_raytracer.html" rel="nofollow">http://gabrielgambetta.com/tiny_raytracer.html</a>).<p>> Making a.async truthy ensures<p>"Truthy"???
A tool that generates tracking codes with a customised isogram as parameters: <a href="https://github.com/shinnn/isogram" rel="nofollow">https://github.com/shinnn/isogram</a><p>Example:
(function(i, s, o, g, r, a, m) {...})
->
(function(y, c, o, m, b, i) {...})
I'm not sure if it's actually intentional, but given the command-queue nature of the ga function, i[r].q's resemblance to IRQ could be a cute reference. (Assuming i and r were fixed, p=1/26 for using q... science!)<p>(Originally noted in some old article that I can't find right now.)
I also liked this deconstruction: <a href="http://code.stephenmorley.org/javascript/understanding-the-google-analytics-tracking-code/" rel="nofollow">http://code.stephenmorley.org/javascript/understanding-the-g...</a>
> An unminified and less convoluted version of the script might look like this:<p>(references to undefined variables `a` and `m` in some sort of IIIFE)