From 47c2df09d44c753ea1247e3e6f9f442cf463c313 Mon Sep 17 00:00:00 2001 From: jdlrobson Date: Mon, 17 Oct 2016 13:52:08 -0700 Subject: [PATCH] Display and hover events are logged but not recorded This adds two new events "display" and "hover" which are not recorded back to the server. The benefits of having these events is that they are important events in the lifecycle of a hovercard. This allows us to debug trackSubscribe and ensure we see the behaviour we expect to see and in a future patchset will allow us to use these events to drive the calculation of interaction time in one single location (Sneak preview: https://gerrit.wikimedia.org/r/316481 to get a feel for the why.) Change-Id: I58eefc29444179fd245cfd722093dedea19455e8 --- .../desktopRenderer.js | 4 ++++ .../ext.popups.schemaPopups.utils.js | 9 +++++++-- .../desktopTarget.js | 4 ++++ tests/qunit/ext.popups.schemaPopups.utils.test.js | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/resources/ext.popups.renderer.desktopRenderer/desktopRenderer.js b/resources/ext.popups.renderer.desktopRenderer/desktopRenderer.js index bd75005ee..469fd2bb4 100644 --- a/resources/ext.popups.renderer.desktopRenderer/desktopRenderer.js +++ b/resources/ext.popups.renderer.desktopRenderer/desktopRenderer.js @@ -222,6 +222,10 @@ namespaceIdHover: cache.settings.namespace, perceivedWait: Math.round( mw.now() - logData.dwellStartTime ) } ); + mw.track( 'ext.popups.schemaPopups', $.extend( {}, logData, { + action: 'display' + } ) + ); cache.process( link, $.extend( {}, logData ) ); diff --git a/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js b/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js index d8e8d46ca..ceb3ac53d 100644 --- a/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js +++ b/resources/ext.popups.schemaPopups.utils/ext.popups.schemaPopups.utils.js @@ -94,12 +94,17 @@ * @return {Object|boolean} */ function getMassagedData( data, previousLogData ) { + // We don't log hover and display events as they are not compatible with the schema + // but they are useful for debugging + var action = data.action; + if ( action && [ 'hover', 'display' ].indexOf( action ) > -1 ) { + return false; // Only one action is recorded per link interaction token... - if ( data.linkInteractionToken && + } else if ( data.linkInteractionToken && data.linkInteractionToken === previousLogData.linkInteractionToken ) { // however, the 'disabled' action takes two clicks by nature, so allow it - if ( data.action !== 'disabled' ) { + if ( action !== 'disabled' ) { return false; } } diff --git a/resources/ext.popups.targets.desktopTarget/desktopTarget.js b/resources/ext.popups.targets.desktopTarget/desktopTarget.js index 4b47d46fd..b7a638697 100644 --- a/resources/ext.popups.targets.desktopTarget/desktopTarget.js +++ b/resources/ext.popups.targets.desktopTarget/desktopTarget.js @@ -46,6 +46,10 @@ hovercardsSuppressedByGadget: isNavigationPopupsGadgetEnabled() }; + mw.track( 'ext.popups.schemaPopups', $.extend( {}, eventData, { + action: 'hover' + } ) + ); // Only enable Popups when the Navigation popups gadget is not enabled if ( !eventData.hovercardsSuppressedByGadget && mw.popups.enabled ) { if ( mw.popups.scrolled ) { diff --git a/tests/qunit/ext.popups.schemaPopups.utils.test.js b/tests/qunit/ext.popups.schemaPopups.utils.test.js index e47f15ff5..85d5d6f35 100644 --- a/tests/qunit/ext.popups.schemaPopups.utils.test.js +++ b/tests/qunit/ext.popups.schemaPopups.utils.test.js @@ -147,4 +147,19 @@ assert.ok( schemaPopups.getMassagedData( settingsEvent, thisEvent ) !== false, '... unless disabled event' ); assert.ok( thisEvent.dwellStartTime === 1, 'and no side effects' ); } ); + + QUnit.test( 'getMassagedData - returns false for hover and display events', 2, function ( assert ) { + var + hoverEvent = { + action: 'hover' + }, + displayEvent = { + action: 'display', + linkInteractionToken: 't' + }; + + assert.ok( schemaPopups.getMassagedData( hoverEvent ) === false ); + assert.ok( schemaPopups.getMassagedData( displayEvent ) === false ); + } ); + } )( jQuery, mediaWiki );