EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/247852
Change subject: Revert "Add new fields to TestSearchSatisfaction" ...................................................................... Revert "Add new fields to TestSearchSatisfaction" This may have caused a performance regression, as described at T116137. Reverting to see if that fixes int. This reverts commit c5b6de098f16f1a8e63020943e49a6682e5f27b1. Change-Id: I740ca6e8708fa6e800681e832e966a5372200e00 --- M WikimediaEvents.php M modules/ext.wikimediaEvents.search.js 2 files changed, 15 insertions(+), 85 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents refs/changes/52/247852/1 diff --git a/WikimediaEvents.php b/WikimediaEvents.php index fb361fe..d7d813a 100644 --- a/WikimediaEvents.php +++ b/WikimediaEvents.php @@ -88,7 +88,7 @@ 'schema.TestSearchSatisfaction2' => array( 'class' => 'ResourceLoaderSchemaModule', 'schema' => 'TestSearchSatisfaction2', - 'revision' => 13821644, + 'revision' => 13223897, ), 'schema.GeoFeatures' => array( 'class' => 'ResourceLoaderSchemaModule', diff --git a/modules/ext.wikimediaEvents.search.js b/modules/ext.wikimediaEvents.search.js index dd3e274..ac173f9 100644 --- a/modules/ext.wikimediaEvents.search.js +++ b/modules/ext.wikimediaEvents.search.js @@ -1,19 +1,5 @@ /*! * Javacsript module for measuring internal search bounce rate and dwell time. - * Utilizes two wprov query string formats: - * - serp:N - This indicates the link was visited directly from a SERP. N is - * a positive integer indicating the position of this page within the results. - * - cirrus - This indicates the link was visited as part of a search session - * but not directly from the search page. - * - * Example: - * - User performs search, is shown Special:Search. This has no wprov query string parameter - * - User clicks the 2nd result in the page which is `Jimmy Wales`, the user is sent to - * /wiki/Jimmy_Wales?wprov=serp:2 - * - User clicks a link in the content area of `Jimmy Wales` to `Wikipedia`, the user is sent to - * /wiki/Wikipedia?wprov=cirrus. - * - Visiting any page without having a direct click stream through article pages back - * to a SERP does not log events. * * @license GNU GPL v2 or later * @author Erik Bernhardson <ebernhard...@wikimedia.org> @@ -21,26 +7,13 @@ ( function ( mw, $, undefined ) { var isSearchResultPage = mw.config.get( 'wgIsSearchResultPage' ), uri = new mw.Uri( location.href ), - // wprov attached to all search result links. If available - // indicates user got here directly from Special:Search - wprovPrefix = 'srpw1_', - // srpw1 has the position (including offset) of the search - // result appended. - searchResultPosition = parseInt( uri.query.wprov && - uri.query.wprov.substr( 0, wprovPrefix.length ) === wprovPrefix && - uri.query.wprov.substr( wprovPrefix.length ), 10 ), - cameFromSearchResult = !isNaN( searchResultPosition ), - isDeepSearchResult = uri.query.wprov === 'sdlw1', - lastScrollTop = $( window ).scrollTop(); + cameFromSearchResult = uri.query.wprov === 'cirrus'; function oneIn( populationSize ) { - var rand = mw.user.generateRandomSessionId(), - // take the first 52 bits of the rand value - parsed = parseInt( rand.slice( 0, 13 ), 16 ); - return parsed % populationSize === 0; + return Math.floor( Math.random() * populationSize ) === 0; } - if ( cameFromSearchResult || isDeepSearchResult ) { + if ( cameFromSearchResult ) { // cleanup the location bar in supported browsers if ( window.history.replaceState ) { delete uri.query.wprov; @@ -57,69 +30,36 @@ 'schema.TestSearchSatisfaction2' ] ).then( function () { var searchSessionId = $.jStorage.get( 'searchSessionId' ), - searchToken = $.jStorage.get( 'searchToken' ), sessionLifetimeMs = 10 * 60 * 1000, - tokenLifetimeMs = 24 * 60 * 60 * 1000, checkinTimes = [ 10, 20, 30, 40, 50, 60, 90, 120, 150, 180, 210, 240, 300, 360, 420 ], - articleId = mw.config.get( 'wgArticleId' ), - pageViewId = mw.user.generateRandomSessionId(), + pageId = mw.user.generateRandomSessionId(), logEvent = function ( action, checkinTime ) { - var scrollTop = $( window ).scrollTop(), - evt = { + var evt = { // searchResultPage, visitPage or checkin action: action, // identifies a single user performing searches within // a limited time span. searchSessionId: searchSessionId, - // identifies a single user over a 24 hour timespan, - // allowing to tie together multiple search sessions - searchToken: searchToken, // used to correlate actions that happen on the same // page. Otherwise a user opening multiple search results // in tabs would make their events overlap and the dwell // time per page uncertain. - pageViewId: pageViewId, - // identifies if a user has scrolled the page since the - // last event - scroll: scrollTop !== lastScrollTop + pageId: pageId, + // we noticed a number of events get sent multiple + // times from javascript, especially when using sendBeacon. + // This logId allows for later deduplication + logId: mw.user.generateRandomSessionId() }; - lastScrollTop = scrollTop; if ( checkinTime !== undefined ) { - // identifies how long the user has been on this page evt.checkin = checkinTime; - } - if ( isSearchResultPage ) { - // the users actual search term - evt.query = mw.config.get( 'searchTerm' ); - // the number of results shown on this page. - evt.hitsReturned = $( '.mw-search-result-heading' ).length; - } - if ( articleId > 0 ) { - evt.articleId = articleId; - } - if ( cameFromSearchResult ) { - // this is only available on article pages linked - // directly from a search result. - evt.position = searchResultPosition; } mw.eventLog.logEvent( 'TestSearchSatisfaction2', evt ); }, - // expects to be run with an html anchor as `this` - updateSearchHref = function () { - var uri = new mw.Uri( this.href ), - offset = $( this ).data( 'serp-pos' ); - if ( offset ) { - uri.query.wprov = 'srpw1_' + offset; - this.href = uri.toString(); - } - }, - // expects to be run with an html anchor as `this` - updateDeepHref = function () { + updateHref = function () { var uri = new mw.Uri( this.href ); - // try to not add our query param to unnecessary places. The - // wikitext parser always outputs /wiki/ for [[WikiLinks]]. + // try to not add our query param to unnecessary places if ( uri.path.substr( 0, 6 ) === '/wiki/' ) { - uri.query.wprov = 'sdlw1'; + uri.query.wprov = 'cirrus'; this.href = uri.toString(); } }; @@ -155,21 +95,11 @@ } } - if ( searchToken === null ) { - searchToken = mw.user.generateRandomSessionId(); - $.jStorage.set( 'searchToken', searchToken, { TTL: tokenLifetimeMs } ); - if ( $.jStorage.get( 'searchToken' ) !== searchToken ) { - // likely localstorage is full, we can't properly track - // this user - return; - } - } + $( '#mw-content-text a:not(.external)' ).each( updateHref ); if ( isSearchResultPage ) { - $( '.mw-search-result-heading a' ).each( updateSearchHref ); logEvent( 'searchResultPage' ); } else { - $( '#mw-content-text a:not(.external)' ).each( updateDeepHref ); logEvent( 'visitPage' ); $( checkinTimes ).each( function ( _, checkin ) { setTimeout( function () { -- To view, visit https://gerrit.wikimedia.org/r/247852 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I740ca6e8708fa6e800681e832e966a5372200e00 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikimediaEvents Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits