Reformatting Google Analytics code

Original code:

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-00000000-1', 'auto');
ga('send', 'pageview');

Prettified code:

(function () {
  window['GoogleAnalyticsObject'] = 'ga';
  window['ga'] = window['ga'] || function () {
    (window['ga'].q = window['ga'].q || []).push(arguments)
  },
  window['ga'].l = 1 * new Date();
  var scriptElement = document.createElement('script'),
      firstScriptElement = document.getElementsByTagName('script')[0];

  scriptElement.async = 1;
  scriptElement.src = 'https://www.google-analytics.com/analytics.js';
  firstScriptElement.parentNode.insertBefore(scriptElement, firstScriptElement)
})();

Now we can see what's really going on. In order:

See also Google's explanation of the unminified version.

Note: analysing the external file is out of scope for this article. I will post a separate article for that file.

Reformatted code:

((M,R,P,a,p,e,r,c,u,t,с,o,m)=>{
  P[a]=p,
  P[p]=(...a)=>P[p].q[m](a),
  P[p].q=[],
  P[p].l=+new Date;

  a=e[u](r)[0],
  e=e[c](r);

  e[M]=!+[],
  e[R]=t;

  a[с][o](e,a)
})('async','src',window,'GoogleAnalyticsObject','ga',document,'script','createElement',
'getElementsByTagName','https://www.google-analytics.com/analytics.js','parentNode','insertBefore','push');

Please note: the above examples uses 2 c's, the first one a normal latin C (charCode 99) and the second is a russian cyrillic C (charCode 1089)

Pros and cons of custom Google Analytics code

Pros:

Cons: