mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-27 17:50:44 +00:00
Merge "Centralize EditAttemptStep logging code in WikimediaEvents"
This commit is contained in:
commit
71f6366371
|
@ -8,194 +8,37 @@
|
||||||
// This sets $.wikiEditor and $.fn.wikiEditor
|
// This sets $.wikiEditor and $.fn.wikiEditor
|
||||||
require( './jquery.wikiEditor.js' );
|
require( './jquery.wikiEditor.js' );
|
||||||
|
|
||||||
function log() {
|
function logEditEvent( data ) {
|
||||||
// mw.log is a no-op unless resource loader is in debug mode, so
|
if ( mw.config.get( 'wgMFMode' ) !== null ) {
|
||||||
// this allows trackdebug to work independently (T211698)
|
// Visiting a ?action=edit URL can, depending on user settings, result
|
||||||
// eslint-disable-next-line no-console
|
// in the MobileFrontend overlay appearing on top of WikiEditor. In
|
||||||
console.log.apply( console, arguments );
|
// these cases, don't log anything.
|
||||||
}
|
|
||||||
|
|
||||||
function sampledLogger( schema, callback, transformCallback ) {
|
|
||||||
var trackdebug = !!mw.util.getParamValue( 'trackdebug' );
|
|
||||||
return function () {
|
|
||||||
if ( mw.loader.getState( 'ext.eventLogging' ) === null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ( mw.config.get( 'wgMFMode' ) !== null ) {
|
|
||||||
// Visiting a ?action=edit URL can, depending on user settings, result
|
|
||||||
// in the MobileFrontend overlay appearing on top of WikiEditor. In
|
|
||||||
// these cases, don't log anything.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var args = Array.prototype.slice.call( arguments );
|
|
||||||
|
|
||||||
mw.loader.using( [ 'ext.eventLogging' ] ).done( function () {
|
|
||||||
// Sampling
|
|
||||||
// We have to do this on the client too because the unload handler
|
|
||||||
// can cause an editingSessionId to be generated on the client
|
|
||||||
// Not using mw.eventLog.inSample() because we need to be able to pass our own editingSessionId
|
|
||||||
var inSample = mw.eventLog.randomTokenMatch(
|
|
||||||
1 / mw.config.get( 'wgWMESchemaEditAttemptStepSamplingRate' ),
|
|
||||||
editingSessionId
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( !inSample && !mw.config.get( 'wgWMESchemaEditAttemptStepOversample' ) && !trackdebug ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var data = callback.apply( this, [ inSample ].concat( args ) );
|
|
||||||
|
|
||||||
if ( trackdebug ) {
|
|
||||||
log( schema, data );
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mw.eventLog.logEvent( schema, data );
|
|
||||||
|
|
||||||
// T309013: If applicable, log via the Metrics Platform:
|
|
||||||
if ( transformCallback ) {
|
|
||||||
var transformed = transformCallback.apply( this, [ data ] );
|
|
||||||
|
|
||||||
mw.eventLog.dispatch( transformed[ 0 ], transformed[ 1 ] );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function addABTestData( data, addToken ) {
|
|
||||||
// DiscussionTools New Topic A/B test for logged out users
|
|
||||||
if ( !mw.config.get( 'wgDiscussionToolsABTest' ) ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( mw.config.get( 'wgDiscussionToolsABTestBucket' ) ) {
|
mw.track( 'editAttemptStep', $.extend( {
|
||||||
data.bucket = mw.config.get( 'wgDiscussionToolsABTestBucket' );
|
// eslint-disable-next-line camelcase
|
||||||
}
|
editor_interface: 'wikitext',
|
||||||
if ( mw.user.isAnon() && addToken ) {
|
platform: 'desktop', // FIXME T249944
|
||||||
var token = mw.cookie.get( 'DTABid', '' );
|
integration: 'page'
|
||||||
if ( token ) {
|
}, data ) );
|
||||||
// eslint-disable-next-line camelcase
|
|
||||||
data.anonymous_user_token = token;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var actionPrefixMap = {
|
function logEditFeature( feature, action ) {
|
||||||
firstChange: 'first_change',
|
if ( mw.config.get( 'wgMFMode' ) !== null ) {
|
||||||
saveIntent: 'save_intent',
|
// Visiting a ?action=edit URL can, depending on user settings, result
|
||||||
saveAttempt: 'save_attempt',
|
// in the MobileFrontend overlay appearing on top of WikiEditor. In
|
||||||
saveSuccess: 'save_success',
|
// these cases, don't log anything.
|
||||||
saveFailure: 'save_failure'
|
return;
|
||||||
};
|
|
||||||
|
|
||||||
var logEditEvent = sampledLogger(
|
|
||||||
'EditAttemptStep',
|
|
||||||
function ( inSample, action, data ) {
|
|
||||||
var actionPrefix = actionPrefixMap[ action ] || action;
|
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
|
||||||
data = $.extend( {
|
|
||||||
version: 1,
|
|
||||||
action: action,
|
|
||||||
is_oversample: !inSample,
|
|
||||||
editing_session_id: editingSessionId,
|
|
||||||
page_token: mw.user.getPageviewToken(),
|
|
||||||
session_token: mw.user.sessionId(),
|
|
||||||
editor_interface: 'wikitext',
|
|
||||||
platform: 'desktop', // FIXME T249944
|
|
||||||
integration: 'page',
|
|
||||||
page_id: mw.config.get( 'wgArticleId' ),
|
|
||||||
page_title: mw.config.get( 'wgPageName' ),
|
|
||||||
page_ns: mw.config.get( 'wgNamespaceNumber' ),
|
|
||||||
revision_id: mw.config.get( 'wgRevisionId' ) || +$( 'input[name=parentRevId]' ).val() || 0,
|
|
||||||
user_id: mw.user.getId(),
|
|
||||||
user_editcount: mw.config.get( 'wgUserEditCount', 0 ),
|
|
||||||
mw_version: mw.config.get( 'wgVersion' )
|
|
||||||
}, data );
|
|
||||||
|
|
||||||
if ( mw.user.isAnon() ) {
|
|
||||||
data.user_class = 'IP';
|
|
||||||
}
|
|
||||||
|
|
||||||
addABTestData( data, true );
|
|
||||||
|
|
||||||
// Schema's kind of a mess of special properties
|
|
||||||
if ( data.action === 'init' || data.action === 'abort' || data.action === 'saveFailure' ) {
|
|
||||||
data[ actionPrefix + '_type' ] = data.type;
|
|
||||||
}
|
|
||||||
if ( data.action === 'init' || data.action === 'abort' ) {
|
|
||||||
data[ actionPrefix + '_mechanism' ] = data.mechanism;
|
|
||||||
}
|
|
||||||
if ( data.action !== 'init' ) {
|
|
||||||
data[ actionPrefix + '_timing' ] = data.timing === undefined ? 0 : Math.floor( data.timing );
|
|
||||||
}
|
|
||||||
/* eslint-enable camelcase */
|
|
||||||
|
|
||||||
// Remove renamed properties
|
|
||||||
delete data.type;
|
|
||||||
delete data.mechanism;
|
|
||||||
delete data.timing;
|
|
||||||
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Transforms the data produced by the callback above into an event name/custom data pair
|
|
||||||
// to be logged via the Metrics Platform.
|
|
||||||
function ( data ) {
|
|
||||||
var actionPrefix = actionPrefixMap[ data.action ] || data.action,
|
|
||||||
eventName = 'eas.wt.' + actionPrefix,
|
|
||||||
customData = $.extend( {}, data );
|
|
||||||
|
|
||||||
delete customData.version;
|
|
||||||
delete customData.action;
|
|
||||||
|
|
||||||
// Sampling rate (and therefore whether a stream should oversample) is captured in
|
|
||||||
// the stream config ($wgEventStreams).
|
|
||||||
delete customData.is_oversample;
|
|
||||||
|
|
||||||
delete customData.page_token;
|
|
||||||
delete customData.session_token;
|
|
||||||
|
|
||||||
// Platform can be derived from the agent_client_platform_family context attribute
|
|
||||||
// mixed in by the JavaScript Metrics Platform Client. The context attribute will be
|
|
||||||
// "desktop_browser" or "mobile_browser" depending on whether the MobileFrontend
|
|
||||||
// extension has signalled that it is enabled.
|
|
||||||
delete customData.platform;
|
|
||||||
|
|
||||||
delete customData.page_id;
|
|
||||||
delete customData.page_title;
|
|
||||||
delete customData.page_ns;
|
|
||||||
|
|
||||||
// If the revision ID can be fetched from the config, then it will be mixed in by the
|
|
||||||
// JavaScript Metrics Platform Client.
|
|
||||||
if ( mw.config.exists( 'wgRevisionId' ) ) {
|
|
||||||
delete customData.revision_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete customData.user_id;
|
|
||||||
delete customData.user_editcount;
|
|
||||||
delete customData.mw_version;
|
|
||||||
|
|
||||||
return [ eventName, customData ];
|
|
||||||
}
|
}
|
||||||
);
|
mw.track( 'visualEditorFeatureUse', {
|
||||||
|
|
||||||
var logEditFeature = sampledLogger( 'VisualEditorFeatureUse', function ( inSample, feature, action ) {
|
|
||||||
/* eslint-disable camelcase */
|
|
||||||
var data = {
|
|
||||||
feature: feature,
|
feature: feature,
|
||||||
action: action,
|
action: action,
|
||||||
editingSessionId: editingSessionId,
|
// eslint-disable-next-line camelcase
|
||||||
user_id: mw.user.getId(),
|
editor_interface: 'wikitext',
|
||||||
user_editcount: mw.config.get( 'wgUserEditCount', 0 ),
|
|
||||||
platform: 'desktop', // FIXME T249944
|
platform: 'desktop', // FIXME T249944
|
||||||
integration: 'page',
|
integration: 'page'
|
||||||
editor_interface: 'wikitext'
|
} );
|
||||||
};
|
}
|
||||||
addABTestData( data );
|
|
||||||
/* eslint-enable camelcase */
|
|
||||||
return data;
|
|
||||||
} );
|
|
||||||
|
|
||||||
function logAbort( switchingToVE, unmodified ) {
|
function logAbort( switchingToVE, unmodified ) {
|
||||||
if ( switchingToVE ) {
|
if ( switchingToVE ) {
|
||||||
|
@ -213,7 +56,8 @@
|
||||||
abortType = 'abandon';
|
abortType = 'abandon';
|
||||||
}
|
}
|
||||||
|
|
||||||
logEditEvent( 'abort', {
|
logEditEvent( {
|
||||||
|
action: 'abort',
|
||||||
type: abortType
|
type: abortType
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -236,15 +80,18 @@
|
||||||
// that don't, we just ignore them, so as to not skew the
|
// that don't, we just ignore them, so as to not skew the
|
||||||
// results towards better-performance in those cases.
|
// results towards better-performance in those cases.
|
||||||
var readyTime = Date.now();
|
var readyTime = Date.now();
|
||||||
logEditEvent( 'ready', {
|
logEditEvent( {
|
||||||
|
action: 'ready',
|
||||||
timing: readyTime - window.performance.timing.navigationStart
|
timing: readyTime - window.performance.timing.navigationStart
|
||||||
} );
|
} );
|
||||||
$textarea.on( 'wikiEditor-toolbar-doneInitialSections', function () {
|
$textarea.on( 'wikiEditor-toolbar-doneInitialSections', function () {
|
||||||
logEditEvent( 'loaded', {
|
logEditEvent( {
|
||||||
|
action: 'loaded',
|
||||||
timing: Date.now() - window.performance.timing.navigationStart
|
timing: Date.now() - window.performance.timing.navigationStart
|
||||||
} );
|
} );
|
||||||
} ).one( 'input', function () {
|
} ).one( 'input', function () {
|
||||||
logEditEvent( 'firstChange', {
|
logEditEvent( {
|
||||||
|
action: 'firstChange',
|
||||||
timing: Date.now() - readyTime
|
timing: Date.now() - readyTime
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
Loading…
Reference in a new issue