From 5ccf0324f0e6304b27fe5035a5e8ffb54468dcf4 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Fri, 11 Feb 2022 15:42:17 -0600 Subject: [PATCH] Improve DiscussionTools a/b test bucket logging Make sure it works on pages which don't trigger DT, such as full-page wikitext editing. Bug: T301497 Change-Id: Id3d46eef319f278ee71fbbedbddd16d5ffd540d8 --- .../ve-mw/init/ve.init.mw.trackSubscriber.js | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/modules/ve-mw/init/ve.init.mw.trackSubscriber.js b/modules/ve-mw/init/ve.init.mw.trackSubscriber.js index 3b5a4cd8fa..435d78dc58 100644 --- a/modules/ve-mw/init/ve.init.mw.trackSubscriber.js +++ b/modules/ve-mw/init/ve.init.mw.trackSubscriber.js @@ -42,6 +42,25 @@ ); } + function addABTestData( data ) { + // DiscussionTools New Topic A/B test for logged out users + if ( !mw.config.get( 'wgDiscussionToolsABTest' ) ) { + return; + } + if ( mw.user.isAnon() ) { + var tokenData = mw.storage.getObject( 'DTNewTopicABToken' ); + if ( !tokenData ) { + return; + } + var anonid = parseInt( tokenData.token.slice( 0, 8 ), 16 ); + data.bucket = anonid % 2 === 0 ? 'test' : 'control'; + // eslint-disable-next-line camelcase + data.anonymous_user_id = tokenData.token; + } else if ( mw.user.options.get( 'discussiontools-abtest2' ) ) { + data.bucket = mw.user.options.get( 'discussiontools-abtest2' ); + } + } + function computeDuration( action, event, timeStamp ) { if ( event.timing !== undefined ) { return event.timing; @@ -192,15 +211,10 @@ } else { timing[ action ] = timeStamp; } - - if ( mw.config.get( 'wgDiscussionToolsABTestBucket' ) ) { - data.bucket = mw.config.get( 'wgDiscussionToolsABTestBucket' ); - if ( mw.config.get( 'wgDiscussionToolsAnonymousUserId' ) ) { - data.anonymous_user_id = mw.config.get( 'wgDiscussionToolsAnonymousUserId' ); - } - } /* eslint-enable camelcase */ + addABTestData( event ); + if ( trackdebug ) { log( topic, duration + 'ms', event ); } else { @@ -254,15 +268,10 @@ integration: ve.getProp( ve, 'init', 'target', 'constructor', 'static', 'integrationType' ) || 'page', platform: ve.getProp( ve, 'init', 'target', 'constructor', 'static', 'platformType' ) || 'other' }; - - if ( mw.config.get( 'wgDiscussionToolsABTestBucket' ) ) { - data.bucket = mw.config.get( 'wgDiscussionToolsABTestBucket' ); - if ( mw.config.get( 'wgDiscussionToolsAnonymousUserId' ) ) { - data.anonymous_user_id = mw.config.get( 'wgDiscussionToolsAnonymousUserId' ); - } - } /* eslint-enable camelcase */ + addABTestData( data ); + if ( trackdebug ) { log( topic, event ); } else {