diff --git a/resources/skins.minerva.scripts/errorLogging.js b/resources/skins.minerva.scripts/errorLogging.js index 8bbd90e99..a7b7ce9cf 100644 --- a/resources/skins.minerva.scripts/errorLogging.js +++ b/resources/skins.minerva.scripts/errorLogging.js @@ -1,5 +1,10 @@ ( function ( M, requestIdleCallback, track, config, trackSubscribe, user, experiments ) { requestIdleCallback( function () { + /** + * Errors count in the current pageview + * @type {number} + */ + var errorsCount = 0; /** * Handle an error and log it if necessary * @param {string} errorMessage to be logged @@ -30,7 +35,7 @@ isAnon: user.isAnon(), revision: page.getRevisionId() }; - + errorsCount++; if ( isErrorLoggingEnabled ) { track( EVENT_CLIENT_ERROR_LOG, util.extend( { @@ -45,8 +50,10 @@ }, DEFAULT_ERROR_DATA ) ); } - if ( config.get( 'wgMinervaCountErrors' ) ) { - mw.track( 'counter.MediaWiki.minerva.WebClientError', 1 ); + } + function logErrorsCount() { + if ( errorsCount > 0 ) { + mw.track( 'counter.MediaWiki.minerva.WebClientError', errorsCount ); } } // track RL exceptions @@ -58,6 +65,9 @@ trackSubscribe( 'global.error', function ( topic, error ) { handleError( error.errorMessage, error.lineNumber, error.columnNumber, error.url ); } ); + if ( config.get( 'wgMinervaCountErrors' ) ) { + $( window ).on( 'beforeunload', logErrorsCount ); + } } ); }( mw.mobileFrontend,