jenkins-bot has submitted this change and it was merged. Change subject: Fix four bugs in search satisfaction fulltext clicks improperly recorded ......................................................................
Fix four bugs in search satisfaction fulltext clicks improperly recorded * Autocomplete was calling SessionState.prototype.has, but the function did not exist. Add the function. * The code to re-send events that were put into local storage due to not being sucesfully delivered was expecting the url to be the value in the object, but the key is what has the url. Adjust to recognize that the key is the appropriate url to visit. * Clicks to sub links in search results, like a section title or redirect page, were not properly updating the wprov parameter. The click events were properly collected but not the visitPage events on the other side. Additionally the click events wern't collecting the position clicked. * Depending on network speed events sent by our extended event log implementation that suppors non-sendBeacon enabled browsers can result in duplicate events. Add a uniqueId field back to the schema to allow de-duplicating when running analysis. Bug: T137262 Change-Id: I7955e1d9b94f54b1e63bc5362bfa5c90d904c20c (cherry picked from commit 3178eba79f290fb018d33930d5cd0e2fca176369) --- M extension.json M modules/ext.wikimediaEvents.searchSatisfaction.js 2 files changed, 39 insertions(+), 39 deletions(-) Approvals: EBernhardson: Looks good to me, approved jenkins-bot: Verified diff --git a/extension.json b/extension.json index 5e1d2ad..dc86d30 100644 --- a/extension.json +++ b/extension.json @@ -114,7 +114,7 @@ "schema.TestSearchSatisfaction2": { "class": "ResourceLoaderSchemaModule", "schema": "TestSearchSatisfaction2", - "revision": 15644862 + "revision": 15700292 }, "schema.GeoFeatures": { "class": "ResourceLoaderSchemaModule", diff --git a/modules/ext.wikimediaEvents.searchSatisfaction.js b/modules/ext.wikimediaEvents.searchSatisfaction.js index 0a1caa1..e32762b 100644 --- a/modules/ext.wikimediaEvents.searchSatisfaction.js +++ b/modules/ext.wikimediaEvents.searchSatisfaction.js @@ -48,6 +48,16 @@ return res; } + /** + * Generate a unique token. Appends timestamp in base 36 to increase + * uniqueness of the token. + * + * @return {string} + */ + function randomToken() { + return mw.user.generateRandomSessionId() + new Date().getTime().toString( 36 ); + } + search = initFromWprov( 'srpw1_' ); autoComplete = initFromWprov( 'acrw1_' ); // with no position appended indicates the user submitted the @@ -80,16 +90,6 @@ */ function key( type ) { return storageNamespace + '-' + type; - } - - /** - * Generate a unique token. Appends timestamp in base 36 to increase - * uniqueness of the token. - * - * @return {string} - */ - function randomToken() { - return mw.user.generateRandomSessionId() + new Date().getTime().toString( 36 ); } /** @@ -160,6 +160,10 @@ return true; } + this.has = function ( type ) { + return this.get( type ) !== null; + }; + this.get = function ( type ) { if ( !state.hasOwnProperty( type ) ) { if ( ttl.hasOwnProperty( type ) ) { @@ -201,24 +205,6 @@ state.enabled = initialize( this ); return this; - } - - /** - * Adds an attribute to the link to track the offset - * of the result in the SERP. - * - * Expects to be run with an html anchor as `this`. - * - * @param {Event} evt jQuery Event object - * @private - */ - function updateSearchHref( evt ) { - var uri = new mw.Uri( evt.target.href ), - offset = $( evt.target ).data( 'serp-pos' ); - if ( offset ) { - uri.query.wprov = evt.data.wprovPrefix + offset; - evt.target.href = uri.toString(); - } } /** @@ -319,15 +305,15 @@ // might be reducing our deliverability. Not sure the best way to // handle. $( document ).ready( function () { - var queue, key, + var queue, url, jsonQueue = mw.storage.get( queueKey ); if ( jsonQueue ) { mw.storage.remove( queueKey ); queue = JSON.parse( jsonQueue ); - for ( key in queue ) { - if ( queue.hasOwnProperty( key ) ) { - self.sendBeacon( queue[ key ] ); + for ( url in queue ) { + if ( queue.hasOwnProperty( url ) ) { + self.sendBeacon( url ); } } } @@ -378,7 +364,13 @@ scroll: scrollTop !== lastScrollTop, // mediawiki session id to correlate with other schemas, // such as QuickSurvey - mwSessionId: mw.user.sessionId() + mwSessionId: mw.user.sessionId(), + // unique event identifier to filter duplicate events. In + // testing these primarily come from browsers without + // sendBeacon using our extended event log implementation. + // Depending on speed of the network the request may or may + // not get completed before page unload + uniqueId: randomToken() }; lastScrollTop = scrollTop; @@ -424,13 +416,21 @@ $( '#mw-content-text' ).on( 'click', '.mw-search-result-heading a', - { wprovPrefix: search.wprovPrefix }, function ( evt ) { - updateSearchHref( evt ); - // test event, duplicated by visitPage event when - // the user arrives. + var $target = $( evt.target ), + uri = new mw.Uri( $target.attr( 'href' ) ), + // Only the primary anchor has the data-serp-pos attribute, but we + // might be updating a sub-link like a section. + index = $target.closest( '.mw-search-result-heading' ) + .find( '[data-serp-pos]' ) + .data( 'serp-pos' ); + + if ( index !== undefined ) { + uri.query.wprov = search.wprovPrefix + index; + $target.attr( 'href', uri.toString() ); + } logEvent( 'click', { - position: $( evt.target ).data( 'serp-pos' ) + position: index } ); } ); -- To view, visit https://gerrit.wikimedia.org/r/294772 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I7955e1d9b94f54b1e63bc5362bfa5c90d904c20c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikimediaEvents Gerrit-Branch: wmf/1.28.0-wmf.6 Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits