kalnyc67 / analytics-issues

Automatically exported from code.google.com/p/analytics-issues
0 stars 0 forks source link

Replace a function and save a characters in the tracing code #511

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If Google Analytics is used by more than 15M people, we should minimise the 
tracking code as much as possible. 

The original code:

<script>
  (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','//www.google-analytics.com/analytics.js','ga');

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

</script>

The prettified code:

(function (window, document, scriptString, path, shortcut) {
      window['GoogleAnalyticsObject'] = shortcut;
      window[shortcut] = window[shortcut] || function () {
          (window[shortcut].q = window[shortcut].q || []).push(arguments)
      }, window[shortcut].l = 1 * new Date();
      var a = document.createElement(scriptString),
      var m = document.getElementsByTagName(scriptString)[0];
      a.async = true;
      a.src = path;
      m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga')

Code --- 1 * new Date() --- is used as a short way for --- new 
Date().getTime(); --- 
but we can also use --- +new Date() --- to save a bit and get the same 
performance and the same browser compatibility. 

http://jsperf.com/timestamps-date

Original issue reported on code.google.com by sam...@ondrek.com on 9 Oct 2014 at 9:04

GoogleCodeExporter commented 9 years ago
Any progress in 3 months? Shall I make a pull request anywhere?

Original comment by sam...@ondrek.com on 26 Dec 2014 at 8:57