jenkins-bot has submitted this change and it was merged. Change subject: Track clicks on suggestions, etc., in "Did you mean" results ......................................................................
Track clicks on suggestions, etc., in "Did you mean" results Add wprov=cirrusDYM-* to links for suggestions, rewritten queries, and original queries in div.searchdidyoumean, based on their HTML ids. Track when those are clicked on in DidYouMean schema in didYouMeanSource field. Remove wprov parameter from query params and browser history. Bug: T110359 Change-Id: I704a9fc022887fde89878033b4083f3a3a06b400 --- M WikimediaEvents.php M modules/ext.wikimediaEvents.didyoumean.js 2 files changed, 33 insertions(+), 3 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/WikimediaEvents.php b/WikimediaEvents.php index 19857ab..d7d813a 100644 --- a/WikimediaEvents.php +++ b/WikimediaEvents.php @@ -78,7 +78,7 @@ 'schema.DidYouMean' => array( 'class' => 'ResourceLoaderSchemaModule', 'schema' => 'DidYouMean', - 'revision' => 13316693, + 'revision' => 13800499, ), 'schema.CompletionSuggestions' => array( 'class' => 'ResourceLoaderSchemaModule', @@ -131,6 +131,7 @@ 'localBasePath' => __DIR__ . '/modules', 'remoteExtPath' => 'WikimediaEvents/modules', 'targets' => array( 'desktop' ), + 'dependencies' => 'mediawiki.Uri', ), 'ext.wikimediaEvents.geoFeatures' => array( 'scripts' => array( diff --git a/modules/ext.wikimediaEvents.didyoumean.js b/modules/ext.wikimediaEvents.didyoumean.js index bee6f5b..d2616fd 100644 --- a/modules/ext.wikimediaEvents.didyoumean.js +++ b/modules/ext.wikimediaEvents.didyoumean.js @@ -6,8 +6,31 @@ * @author Erik Bernhardson <ebernhard...@wikimedia.org> */ ( function ( mw, $ ) { + var uri = new mw.Uri( location.href ), + cirrusDYM = uri.query.wprov && uri.query.wprov.indexOf( 'cirrusDYM-' ) === 0; + + if ( cirrusDYM ) { + cirrusDYM = uri.query.wprov; + cirrusDYM = cirrusDYM.replace( /^cirrusDYM-/, '' ) + '-click'; + // cleanup the location bar in supported browsers + if ( window.history.replaceState ) { + delete uri.query.wprov; + window.history.replaceState( {}, '', uri.toString() ); + } + } else { + cirrusDYM = 'no'; + } + function oneIn( populationSize ) { return Math.floor( Math.random() * populationSize ) === 0; + } + + function updateHref() { + if ( this.id ) { + var uri = new mw.Uri( this.href ); + uri.query.wprov = this.id.replace( /^mw-search-DYM/, 'cirrusDYM' ); + this.href = uri.toString(); + } } function participateInTest() { @@ -16,7 +39,7 @@ suggestIsRewritten = $target.find( '.searchrewritten' ).length > 0, numResults = $( '.mw-search-result-heading' ).length, pageId = mw.user.generateRandomSessionId(), - runSuggestion = +new mw.Uri( window.location.href ).query.runsuggestion, + runSuggestion = +uri.query.runsuggestion, logEvent = function ( action ) { mw.eventLog.logEvent( 'DidYouMean', { // Used to correlate actions that happen on the same @@ -36,7 +59,11 @@ logId: mw.user.generateRandomSessionId(), // Records if the user explicitly opted out of auto-running // suggested queries - runsuggestion: isNaN( runSuggestion ) ? true : !!runSuggestion, + runSuggestion: isNaN( runSuggestion ) ? true : !!runSuggestion, + // Records whether the user clicked on a DYM link to get here + // 'original-click', 'rewritten-click', 'suggestion-click', or 'no' + didYouMeanSource: cirrusDYM, + // Records the action taken on this page action: action } ); }, @@ -67,6 +94,8 @@ } $( document ).ready( function () { + // tag "Did you mean" suggestion and original query + $( '#mw-content-text .searchdidyoumean > a' ).each( updateHref ); // we fire most events from click handlers, so we need to filter for // only browser that support sendBeacon and will reliably deliver // these events. -- To view, visit https://gerrit.wikimedia.org/r/235049 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I704a9fc022887fde89878033b4083f3a3a06b400 Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/extensions/WikimediaEvents Gerrit-Branch: master Gerrit-Owner: Tjones <tjo...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com> Gerrit-Reviewer: Tjones <tjo...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits