Merge "playground/client: add exception logging to GA"
diff --git a/client/browser/exception-logger.js b/client/browser/exception-logger.js
new file mode 100644
index 0000000..bbd0139
--- /dev/null
+++ b/client/browser/exception-logger.js
@@ -0,0 +1,26 @@
+// Copyright 2015 The Vanadium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+var window = require('global/window');
+var UA = window.navigator ? window.navigator.userAgent : '';
+
+module.exports = init;
+
+function init() {
+  window.addEventListener('error', onerror);
+}
+
+function onerror(event) {
+  var ga = window.ga || noop;
+  var category = 'JavaScript Error';
+  var action = event.message;
+  var label = UA + ' \n' + event.error.stack;
+
+  // SEE: http://goo.gl/IIgLdL
+  ga('send', 'event', category, action, label);
+}
+
+function noop() {
+
+}
diff --git a/client/browser/index.js b/client/browser/index.js
index 18e3b72..32badb1 100644
--- a/client/browser/index.js
+++ b/client/browser/index.js
@@ -2,6 +2,11 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// Enabale a global exception logger
+var exceptionLogger = require('./exception-logger');
+
+exceptionLogger.init();
+
 var debug = require('debug')('app');
 var domready = require('domready');
 var window = require('global/window');
diff --git a/client/public/index.html b/client/public/index.html
index a7a6a15..bb27a22 100644
--- a/client/public/index.html
+++ b/client/public/index.html
@@ -42,8 +42,8 @@
   <meta name="msapplication-TileImage" content="/favicons/mstile-144x144.png">
 
   <!-- NOTE: Avoid the async attribute to prevent a brief flash of un-styled content -->
-  <script src="/bundle.js"></script>
   <script src="/analytics.js"></script>
+  <script src="/bundle.js"></script>
 </head>
 <body></body>
 </html>