Phuedx has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/325928 )
Change subject: {LINK,PREVIEW}_ABANDON_END logs an event ...................................................................... {LINK,PREVIEW}_ABANDON_END logs an event Since the user can dwell on a link, abandon it while moving to dwell on the preview and vice versa: * The time at which the link/preview was abandoned is recorded and can be updated. * The event can only be queued when the link/preview has definitely been abandoned. Reducer changes: * Make the eventLogging reducer: * Calculate the time it took to show the preview. * Mark the interaction as finished when the user abandons the link or the preview. * Queue a "dismissed" event if the preview hasn't been shown or a "dwelledButAbandoned" event if it has when the abandon has finalized. Bug: T152225 Change-Id: I6a254136f615484fc26e440fe5125289e74688a6 --- M resources/ext.popups/reducers.js M tests/qunit/ext.popups/reducers.eventLogging.test.js 2 files changed, 62 insertions(+), 12 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups refs/changes/28/325928/1 diff --git a/resources/ext.popups/reducers.js b/resources/ext.popups/reducers.js index 7f710a3..5ac80bc 100644 --- a/resources/ext.popups/reducers.js +++ b/resources/ext.popups/reducers.js @@ -182,6 +182,9 @@ previewCount: nextCount, baseData: nextState( state.baseData, { previewCountBucket: counts.getPreviewCountBucket( nextCount ) + } ), + interaction: nextState( state.interaction, { + timeToPreviewShow: action.timestamp - state.interaction.started } ) } ); @@ -202,6 +205,24 @@ } } ); + case mw.popups.actionTypes.LINK_ABANDON_START: + case mw.popups.actionTypes.PREVIEW_ABANDON_START: + return nextState( state, { + interaction: nextState( state.interaction, { + finished: action.timestamp + } ) + } ); + + case mw.popups.actionTypes.LINK_ABANDON_END: + case mw.popups.actionTypes.PREVIEW_ABANDON_END: + return nextState( state, { + event: { + action: state.interaction.timeToPreviewShow ? 'dismissed' : 'dwelledButAbandoned', + linkInteractionToken: state.interaction.token, + totalInteractionTime: Math.round( state.interaction.finished - state.interaction.started ) + } + } ); + default: return state; } diff --git a/tests/qunit/ext.popups/reducers.eventLogging.test.js b/tests/qunit/ext.popups/reducers.eventLogging.test.js index d114140..4f0e5c0 100644 --- a/tests/qunit/ext.popups/reducers.eventLogging.test.js +++ b/tests/qunit/ext.popups/reducers.eventLogging.test.js @@ -79,7 +79,6 @@ QUnit.test( 'PREVIEW_SHOW', function ( assert ) { var state, count = 22, - action, expectedCount = count + 1; state = { @@ -87,23 +86,27 @@ baseData: { previewCountBucket: counts.getPreviewCountBucket( count ) }, - queue: [] + + // state.interaction.started is used in this part of the reducer. + interaction: {} }; - action = { + state = mw.popups.reducers.eventLogging( state, { type: 'PREVIEW_SHOW' - }; + } ); + + assert.equal( + state.previewCount, + expectedCount, + 'It updates the user\'s preview count.' + ); assert.deepEqual( - mw.popups.reducers.eventLogging( state, action ), + state.baseData, { - previewCount: expectedCount, - baseData: { - previewCountBucket: counts.getPreviewCountBucket( expectedCount ) - }, - queue: [] + previewCountBucket: counts.getPreviewCountBucket( expectedCount ) }, - 'It increments the user\'s preview count and re-buckets that count.' + 'It re-buckets the user\'s preview count.' ); } ); @@ -114,7 +117,7 @@ action; state = { - interaction: {} + interaction: undefined }; action = { @@ -164,4 +167,30 @@ ); } ); + QUnit.test( 'PREVIEW_SHOW should update the perceived wait time of the interaction', function ( assert ) { + var state, + now = mw.now(); + + state = { + interaction: undefined + }; + + state = mw.popups.reducers.eventLogging( state, { + type: 'LINK_DWELL', + interactionToken: '0987654321', + timestamp: now + } ); + + state = mw.popups.reducers.eventLogging( state, { + type: 'PREVIEW_SHOW', + timestamp: now + 500 + } ); + + assert.deepEqual( state.interaction, { + token: '0987654321', + started: now, + timeToPreviewShow: 500 + } ); + } ); + }( mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/325928 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6a254136f615484fc26e440fe5125289e74688a6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Popups Gerrit-Branch: mpga Gerrit-Owner: Phuedx <samsm...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits