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
This commit is contained in:
David Lynch 2018-10-11 11:52:14 -05:00
parent 46e34297e0
commit 0a3eda0529

View file

@ -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 );
}
}() );