Baby Jesus Cries Every Day This Code Is Here

Found something amusing here.
Having read about crap like this on dailywtf but to actually encounter it myself is...interesting.

  <script type="text/javascript">
      var _kmq = _kmq || [];
      var _kmk = _kmk || '543704820507c2a323f44ddcbcd60ad6d5a8ae95';
      function _kms(u){
        setTimeout(function(){
          var d = document, f = d.getElementsByTagName('script')[0],
          s = d.createElement('script');
          s.type = 'text/javascript'; s.async = true; s.src = u;
          f.parentNode.insertBefore(s, f);
        }, 1);
      }
      _kms('//i.kissmetrics.com/i.js');
      _kms('//doug1izaerwt3.cloudfront.net/' + _kmk + '.1.js');

      //TODO: TEMPORAL CODE. UGLY HACK. BREAKS EVERY KNOWN PRINCIPLE OF A GOOD ARCHITECTURE OR DESIGN
      //TODO: I MEAN IT, BABY JESUS CRIES EVERY DAY THIS CODE IS HERE.
      // Instead of getting and waiting for a cosmetrics user id, replicate the cosmetrics client logic to generate it...
      // Make sure analytics cookie is set by using a callback called when GA is ready.
      _streemalytics.ready(function(){
        _gaq.push(function(){
          var value = document.cookie.match('(?:^|;)\\s*' + '__utma' + '=([^;]*)');
          var cookie =  (value) ? decodeURIComponent(value[1]) : null;
          if(cookie){
            var userId = cookie.split('.')[1];
            _kmq.push(['identify', userId]);
            console.log("Pushing in kissmetrics user id: "+userId);
          } else {
            console.log("Getting user id: No google analytics cookie.");
          }
        });
      })

    </script>

Comments

Popular posts from this blog

Asp.net Publishing Broke Site - "App_WebReferences is not allowed because the application is precompiled"

Telerik - Custom Group Footers In RadGrid

Bootstrap Modal Popup is Grayed Out