Gilles has uploaded a new change for review. https://gerrit.wikimedia.org/r/173515
Change subject: Track image "unviews" ...................................................................... Track image "unviews" Change-Id: I4441b6df511f99b73bfafea0d804171435e129d2 Mingle: https://wikimedia.mingle.thoughtworks.com/projects/multimedia/cards/998 --- M MultimediaViewer.php M resources/mmv/logging/mmv.logging.ActionLogger.js M resources/mmv/mmv.js M tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js 4 files changed, 48 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer refs/changes/15/173515/1 diff --git a/MultimediaViewer.php b/MultimediaViewer.php index ef9724e..a9abc28 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -1022,7 +1022,7 @@ $wgHooks['EventLoggingRegisterSchemas'][] = function( array &$schemas ) { $schemas += array( - 'MediaViewer' => 10308479, + 'MediaViewer' => 10536413, 'MultimediaViewerNetworkPerformance' => 7917896, 'MultimediaViewerDuration' => 8572641, 'MultimediaViewerAttribution' => 9758179, diff --git a/resources/mmv/logging/mmv.logging.ActionLogger.js b/resources/mmv/logging/mmv.logging.ActionLogger.js index c394570..1a7d937 100644 --- a/resources/mmv/logging/mmv.logging.ActionLogger.js +++ b/resources/mmv/logging/mmv.logging.ActionLogger.js @@ -113,37 +113,33 @@ 'options-open': 'User opened the enable/disable dialog.', 'options-close': 'User either canceled an enable/disable action or closed a confirmation window.', 'disable-about-link': 'User clicked on the "Learn more" link in the disable window.', - 'enable-about-link': 'User clicked on the "Learn more" link in the enable window.' + 'enable-about-link': 'User clicked on the "Learn more" link in the enable window.', + 'image-unview': 'User stopped looking at the current image.' }; /** * Logs an action * @param {string} action The key representing the action - * @param {boolean} skipEventLog True if we don't want the action to be recorded in the event log - * @param {Object} substitutions A list of variable subtitutions for parametrized action texts + * @param {boolean} forceEventLog True if we want the action to be logged regardless of the sampling factor * @returns {jQuery.Promise} */ - L.log = function ( action, skipEventLog, substitutions ) { - var translatedAction = this.logActions[action] || action, + L.log = function ( action, forceEventLog ) { + var actionText = this.logActions[action] || action, self = this; - if ( $.isPlainObject( substitutions ) ) { - $.each( substitutions, function( key, value ) { - translatedAction = translatedAction.replace( key, value ); - } ); - } + mw.log( actionText ); - mw.log( translatedAction ); - - if ( !skipEventLog && self.isInSample( action ) ) { + if ( forceEventLog || self.isInSample( action ) ) { return this.loadDependencies().then( function () { self.eventLog.logEvent( self.schema, { action : action, samplingFactor : self.getActionFactor( action ) } ); + + return true; } ); } else { - return $.Deferred().resolve(); + return $.Deferred().resolve( false ); } }; diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js index 46d440c..6e7aba8 100644 --- a/resources/mmv/mmv.js +++ b/resources/mmv/mmv.js @@ -104,6 +104,12 @@ /** @property {string} documentTitle base document title, MediaViewer will expand this */ this.documentTitle = document.title; + + /** + * Was the last image view logged or was logging skipped? + * @property {boolean} + */ + this.wasLastViewLogged = false; } MMVP = MultimediaViewer.prototype; @@ -385,6 +391,8 @@ * @param {number} loadTime Time it took to load the thumbnail */ MMVP.displayRealThumbnail = function ( thumbnail, imageElement, imageWidths, loadTime ) { + var viewer = this; + this.realThumbnailShown = true; this.setImage( this.ui, thumbnail, imageElement, imageWidths ); @@ -397,7 +405,16 @@ this.ui.canvas.unblur(); } - mw.mmv.actionLogger.log( 'image-view' ); + mw.mmv.actionLogger.log( 'image-view' ).then( function ( wasEventLogged ) { + viewer.wasLastViewLogged = wasEventLogged; + + $( window ).on( 'beforeunload.unview', function() { + if ( viewer.wasLastViewLogged ) { + viewer.wasLastViewLogged = false; + mw.mmv.actionLogger.log( 'image-unview', true ); + } + } ); + } ); }; /** @@ -771,6 +788,11 @@ * Opens the next image */ MMVP.nextImage = function () { + if ( this.wasLastViewLogged ) { + this.wasLastViewLogged = false; + mw.mmv.actionLogger.log( 'image-unview', true ); + } + mw.mmv.actionLogger.log( 'next-image' ); this.loadIndex( this.currentIndex + 1 ); }; @@ -779,6 +801,11 @@ * Opens the previous image */ MMVP.prevImage = function () { + if ( this.wasLastViewLogged ) { + this.wasLastViewLogged = false; + mw.mmv.actionLogger.log( 'image-unview', true ); + } + mw.mmv.actionLogger.log( 'prev-image' ); this.loadIndex( this.currentIndex - 1 ); }; @@ -787,7 +814,13 @@ * Handles close event coming from the lightbox */ MMVP.close = function () { - var windowTitle = this.createDocumentTitle( null ); + var windowTitle; + + if ( this.wasLastViewLogged ) { + mw.mmv.actionLogger.log( 'image-unview', true ); + } + + windowTitle = this.createDocumentTitle( null ); if ( comingFromHashChange === false ) { $( document ).trigger( $.Event( 'mmv-hash', { hash : '#', title: windowTitle } ) ); diff --git a/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js b/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js index 783dddf..e0620c4 100644 --- a/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js +++ b/tests/qunit/mmv/logging/mmv.logging.ActionLogger.test.js @@ -1,7 +1,7 @@ ( function ( mw, $ ) { QUnit.module( 'mmv.logging.ActionLogger', QUnit.newMwEnvironment() ); - QUnit.test( 'log()', 8, function ( assert ) { + QUnit.test( 'log()', 6, function ( assert ) { var fakeEventLog = { logEvent : this.sandbox.stub() }, logger = new mw.mmv.logging.ActionLogger(), action1key = 'test-1', @@ -29,15 +29,10 @@ assert.strictEqual( mw.log.getCall( 1 ).args[ 0 ], action1value, 'Log message is translated to its text' ); assert.strictEqual( fakeEventLog.logEvent.callCount, 2, 'event log has been recorded' ); + logger.samplingFactorMap = { 'default' : 0 }; logger.log( action1key, true ); assert.strictEqual( mw.log.getCall( 2 ).args[ 0 ], action1value, 'Log message is translated to its text' ); - assert.strictEqual( fakeEventLog.logEvent.callCount, 2, 'event log has been skipped' ); - - logger.log( action2key, false, { '$1' : 'X', '$2' : 'Y' } ); - - assert.strictEqual( mw.log.getCall( 3 ).args[ 0 ], 'Foo X Y bar', - 'Log message is translated to its text with substitutions' ); assert.strictEqual( fakeEventLog.logEvent.callCount, 3, 'event log has been recorded' ); } ); }( mediaWiki, jQuery ) ); -- To view, visit https://gerrit.wikimedia.org/r/173515 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4441b6df511f99b73bfafea0d804171435e129d2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/MultimediaViewer Gerrit-Branch: master Gerrit-Owner: Gilles <gdu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits