From 0a3eda0529fa44dd7cd52e809a5b24a2d33e2e39 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Thu, 11 Oct 2018 11:52:14 -0500 Subject: [PATCH] trackSubscriber: log activity events for VisualEditorFeatureUse This won't really do anything until the patches to ve-core for the activity events, and WikimediaEvents for the schema land. Bug: T202148 Change-Id: Ie462a24f66240a1accfd0185c46273e60effbd64 --- .../ve-mw/init/ve.init.mw.trackSubscriber.js | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/modules/ve-mw/init/ve.init.mw.trackSubscriber.js b/modules/ve-mw/init/ve.init.mw.trackSubscriber.js index e737ac6a45..cd2b6b8c90 100644 --- a/modules/ve-mw/init/ve.init.mw.trackSubscriber.js +++ b/modules/ve-mw/init/ve.init.mw.trackSubscriber.js @@ -10,12 +10,6 @@ ( function () { var timing, editingSessionId; - if ( mw.loader.getState( 'schema.Edit' ) === null ) { - // Only route any events into the Edit schema if the module is actually available. - // It won't be if EventLogging is installed but WikimediaEvents is not. - return; - } - timing = {}; editingSessionId = mw.user.generateRandomSessionId(); @@ -58,7 +52,7 @@ return -1; } - ve.trackSubscribe( 'mwedit.', function ( topic, data, timeStamp ) { + function mwEditHandler( topic, data, timeStamp ) { var action = topic.split( '.' )[ 1 ], event; @@ -148,9 +142,9 @@ mw.track( 'event.Edit', event ); } - } ); + } - ve.trackSubscribe( 'mwtiming.', function ( topic, data ) { + function mwTimingHandler( topic, data ) { // Add type for save errors; not in the topic for stupid historical reasons if ( topic === 'mwtiming.performance.user.saveError' ) { topic = topic + '.' + data.type; @@ -159,6 +153,34 @@ // Map mwtiming.foo --> timing.ve.foo.mobile topic = topic.replace( /^mwtiming/, 'timing.ve.' + data.targetName ); mw.track( topic, data.duration ); - } ); + } + + function activityHandler( topic, data ) { + var feature = topic.split( '.' )[ 1 ], + event; + + event = { + feature: feature, + action: data.action, + editingSessionId: editingSessionId + }; + + // Sample at 6.25% + if ( event.editingSessionId && event.editingSessionId[ 0 ] === '0' ) { + mw.track( 'event.VisualEditorFeatureUse', event ); + } + } + + if ( mw.loader.getState( 'schema.Edit' ) !== null ) { + // Only route any events into the Edit schema if the module is actually available. + // It won't be if EventLogging is installed but WikimediaEvents is not. + ve.trackSubscribe( 'mwedit.', mwEditHandler ); + ve.trackSubscribe( 'mwtiming.', mwTimingHandler ); + } + + if ( mw.loader.getState( 'schema.VisualEditorFeatureUse' ) !== null ) { + // Similarly for the VisualEditorFeatureUse schema + ve.trackSubscribe( 'activity.', activityHandler ); + } }() );