LoginSignup
8

More than 5 years have passed since last update.

AngularJS: GA でexception をtracking する

Posted at

GA 側

Angular 側

app.factory('$exceptionHandler', ['$window', '$log', function($window, $log) {
    return function(exception, cause) {
      $log.error.apply($log, arguments);
      if ( $window.ga) {
        $window.ga( 'send', 'exception', {
          'exDescription': exception.stack,
          'exFatal': true,
          'appName': 'Compathy',
          'appVersion': '0.3'
        });
      }
    };
  }])
  • ちなみに、exception をそのまま渡すと、exception.message のみがtoString() されてしまい、エラー箇所(ファイルや行番号) が抜けてしまうので、あえてexception.stack を指定している

確認

  • まずブラウザから、exception が発生したときに、GA への送信がされていることを確認する

    • Develper Console のNetwork で"collect" でフィルタするとよい
  • 次に、GA のカスタムレポートで、レポートが見えることを確認する

    • リアルタイムでは見れないので、少し待つ必要あり

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8