From 8f612fbe64842fd3b57c245028982e1b9b907b92 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 7 Dec 2017 11:14:00 +0000 Subject: [PATCH] Pass editor mode (visual/source) to tracking code Change-Id: Iba5d3c66ecbd2872d76ea12f795ef3bebaae9d81 --- .../ve.init.mw.DesktopArticleTarget.init.js | 15 ++++++----- .../ve.init.mw.DesktopArticleTarget.js | 26 +++++++++++-------- .../ve-mw/init/ve.init.mw.ArticleTarget.js | 7 ++--- .../init/ve.init.mw.ArticleTargetEvents.js | 1 + .../init/ve.init.mw.ArticleTargetLoader.js | 21 ++++++++------- .../ve-mw/init/ve.init.mw.trackSubscriber.js | 6 +++++ 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js index 28c078d333..1d5e97b3df 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.init.js @@ -159,7 +159,7 @@ .concat( plugins ) .forEach( mw.libs.ve.targetLoader.addPlugin ); plugins = []; - return mw.libs.ve.targetLoader.loadModules(); + return mw.libs.ve.targetLoader.loadModules( mode ); } ) .then( function () { var target, @@ -207,7 +207,7 @@ } function trackActivateStart( initData ) { - ve.track( 'trace.activate.enter' ); + ve.track( 'trace.activate.enter', { mode: initData.mode } ); ve.track( 'mwedit.init', initData ); mw.libs.ve.activationStart = ve.now(); } @@ -310,14 +310,14 @@ return activatePromise; } ) .then( function () { - ve.track( 'mwedit.ready' ); - ve.track( 'mwedit.loaded' ); + ve.track( 'mwedit.ready', { mode: mode } ); + ve.track( 'mwedit.loaded', { mode: mode } ); } ) .always( clearLoading ); } function activatePageTarget( mode, modified ) { - trackActivateStart( { type: 'page', mechanism: 'click' } ); + trackActivateStart( { type: 'page', mechanism: 'click', mode: mode } ); if ( !active ) { if ( uri.query.action !== 'edit' && !( uri.query.veaction in editModes ) ) { @@ -785,7 +785,7 @@ return; } - trackActivateStart( { type: 'section', mechanism: 'click' } ); + trackActivateStart( { type: 'section', mechanism: 'click', mode: mode } ); if ( history.pushState && !( uri.query.veaction in editModes ) ) { // Replace the current state with one that is tagged as ours, to prevent the @@ -987,7 +987,8 @@ showWikitextWelcome = false; trackActivateStart( { type: section === null ? 'page' : 'section', - mechanism: 'url' + mechanism: 'url', + mode: mode } ); activateTarget( mode, section ); } else if ( diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index e0c0135c31..108127ec32 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -234,17 +234,18 @@ ve.init.mw.DesktopArticleTarget.prototype.verifyPopState = function ( popState ) */ ve.init.mw.DesktopArticleTarget.prototype.setupToolbar = function ( surface ) { var toolbar, + mode = surface.getMode(), wasSetup = !!this.toolbar, target = this; - ve.track( 'trace.setupToolbar.enter' ); + ve.track( 'trace.setupToolbar.enter', { mode: mode } ); // Parent method ve.init.mw.DesktopArticleTarget.super.prototype.setupToolbar.call( this, surface ); toolbar = this.getToolbar(); - ve.track( 'trace.setupToolbar.exit' ); + ve.track( 'trace.setupToolbar.exit', { mode: mode } ); if ( !wasSetup ) { setTimeout( function () { toolbar.$element @@ -263,12 +264,12 @@ ve.init.mw.DesktopArticleTarget.prototype.setupToolbar = function ( surface ) { var surface = target.getSurface(); // Check the surface wasn't torn down while the toolbar was animating if ( surface ) { - ve.track( 'trace.initializeToolbar.enter' ); + ve.track( 'trace.initializeToolbar.enter', { mode: mode } ); target.getToolbar().initialize(); surface.getView().emit( 'position' ); surface.getContext().updateDimensions(); - ve.track( 'trace.initializeToolbar.exit' ); - ve.track( 'trace.activate.exit' ); + ve.track( 'trace.initializeToolbar.exit', { mode: mode } ); + ve.track( 'trace.activate.exit', { mode: mode } ); } } ); } @@ -587,7 +588,8 @@ ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) } ve.track( 'mwedit.abort', { type: abortType, - mechanism: trackMechanism + mechanism: trackMechanism, + mode: this.surface ? this.surface.getMode() : this.getDefaultMode() } ); } @@ -758,7 +760,8 @@ ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () { surface.getModel().getDocument().once( 'transact', function () { ve.track( 'mwtiming.behavior.firstTransaction', { duration: ve.now() - surfaceReadyTime, - targetName: target.constructor.static.trackingName + targetName: target.constructor.static.trackingName, + mode: surface.getMode() } ); } ); @@ -1563,7 +1566,8 @@ ve.init.mw.DesktopArticleTarget.prototype.onUnload = function () { if ( !this.submitting ) { ve.track( 'mwedit.abort', { type: this.edited ? 'unknown-edited' : 'unknown', - mechanism: 'navigate' + mechanism: 'navigate', + mode: this.surface ? this.surface.getMode() : this.getDefaultMode() } ); } }; @@ -1580,9 +1584,9 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = funct if ( discardChanges ) { if ( modified ) { - ve.track( 'mwedit.abort', { type: 'switchwithout', mechanism: 'navigate' } ); + ve.track( 'mwedit.abort', { type: 'switchwithout', mechanism: 'navigate', mode: 'visual' } ); } else { - ve.track( 'mwedit.abort', { type: 'switchnochange', mechanism: 'navigate' } ); + ve.track( 'mwedit.abort', { type: 'switchnochange', mechanism: 'navigate', mode: 'visual' } ); } this.submitting = true; prefPromise.done( function () { @@ -1599,7 +1603,7 @@ ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = funct this.serialize( this.getDocToSave(), function ( wikitext ) { - ve.track( 'mwedit.abort', { type: 'switchwith', mechanism: 'navigate' } ); + ve.track( 'mwedit.abort', { type: 'switchwith', mechanism: 'navigate', mode: 'visual' } ); target.submitWithSaveFields( { wpDiff: 1, wpAutoSummary: '' }, wikitext ); } ); diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js index 7896af8770..bc661bb797 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTarget.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTarget.js @@ -293,7 +293,7 @@ ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) { if ( !data || typeof data.content !== 'string' ) { this.loadFail( 've-api', 'No HTML content in response from server' ); } else { - ve.track( 'trace.parseResponse.enter' ); + this.track( 'trace.parseResponse.enter' ); this.originalHtml = data.content; this.etag = data.etag; this.fromEditedState = data.fromEditedState; @@ -362,7 +362,7 @@ ve.init.mw.ArticleTarget.prototype.loadSuccess = function ( response ) { ve.init.platform.linkCache.setMissing( linkData ); } - ve.track( 'trace.parseResponse.exit' ); + this.track( 'trace.parseResponse.exit' ); // Everything worked, the page was loaded, continue initializing the editor this.documentReady( this.doc ); } @@ -1796,7 +1796,8 @@ ve.init.mw.ArticleTarget.prototype.getEditNotices = function () { * @inheritdoc */ ve.init.mw.ArticleTarget.prototype.track = function ( name ) { - ve.track( name ); + var mode = this.surface ? this.surface.getMode() : this.getDefaultMode(); + ve.track( name, { mode: mode } ); }; /** diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js b/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js index aee40c9b01..f3e9fd2d2e 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTargetEvents.js @@ -52,6 +52,7 @@ ve.init.mw.ArticleTargetEvents = function VeInitMwArticleTargetEvents( target ) */ ve.init.mw.ArticleTargetEvents.prototype.track = function ( topic, data ) { data.targetName = this.target.constructor.static.trackingName; + data.mode = this.target.surface ? this.target.surface.getMode() : this.target.getDefaultMode(); ve.track( 'mwtiming.' + topic, data ); if ( topic.indexOf( 'performance.system.serializeforcache' ) === 0 ) { diff --git a/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js b/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js index a5e898677e..0b5892a6e3 100644 --- a/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js +++ b/modules/ve-mw/init/ve.init.mw.ArticleTargetLoader.js @@ -78,13 +78,14 @@ * Once those are loaded, any registered plugin callbacks are executed, * and we wait for all promises returned by those callbacks to resolve. * + * @param {string} mode Initial editor mode, for tracking * @return {jQuery.Promise} Promise resolved when the loading process is complete */ - loadModules: function () { - ve.track( 'trace.moduleLoad.enter' ); + loadModules: function ( mode ) { + ve.track( 'trace.moduleLoad.enter', { mode: mode } ); return mw.loader.using( modules ) .then( function () { - ve.track( 'trace.moduleLoad.exit' ); + ve.track( 'trace.moduleLoad.exit', { mode: mode } ); pluginCallbacks.push( ve.init.platform.getInitializedPromise.bind( ve.init.platform ) ); // Execute plugin callbacks and collect promises return $.when.apply( $, pluginCallbacks.map( function ( callback ) { @@ -150,7 +151,7 @@ } // Load DOM start = ve.now(); - ve.track( 'trace.apiLoad.enter' ); + ve.track( 'trace.apiLoad.enter', { mode: 'visual' } ); if ( data.paction === 'parse' && options.wikitext !== undefined ) { // Non-RESTBase custom wikitext parse @@ -161,18 +162,19 @@ apiXhr = new mw.Api().get( data ); } apiPromise = apiXhr.then( function ( data, jqxhr ) { - ve.track( 'trace.apiLoad.exit' ); + ve.track( 'trace.apiLoad.exit', { mode: 'visual' } ); ve.track( 'mwtiming.performance.system.apiLoad', { bytes: $.byteLength( jqxhr.responseText ), duration: ve.now() - start, cacheHit: /hit/i.test( jqxhr.getResponseHeader( 'X-Cache' ) ), - targetName: options.targetName + targetName: options.targetName, + mode: 'visual' } ); return data; } ); if ( conf.fullRestbaseUrl || conf.restbaseUrl ) { - ve.track( 'trace.restbaseLoad.enter' ); + ve.track( 'trace.restbaseLoad.enter', { mode: 'visual' } ); // Should be synchronised with ApiVisualEditor.php headers = { @@ -225,11 +227,12 @@ } restbasePromise = restbaseXhr.then( function ( data, status, jqxhr ) { - ve.track( 'trace.restbaseLoad.exit' ); + ve.track( 'trace.restbaseLoad.exit', { mode: 'visual' } ); ve.track( 'mwtiming.performance.system.restbaseLoad', { bytes: $.byteLength( jqxhr.responseText ), duration: ve.now() - start, - targetName: options.targetName + targetName: options.targetName, + mode: 'visual' } ); return [ data, jqxhr.getResponseHeader( 'etag' ) ]; }, diff --git a/modules/ve-mw/init/ve.init.mw.trackSubscriber.js b/modules/ve-mw/init/ve.init.mw.trackSubscriber.js index 6ec3d87082..29b75cb61a 100644 --- a/modules/ve-mw/init/ve.init.mw.trackSubscriber.js +++ b/modules/ve-mw/init/ve.init.mw.trackSubscriber.js @@ -94,6 +94,12 @@ } } + // Convert mode=source/visual to editor name + if ( data.mode ) { + data.editor = data.mode === 'source' ? 'wikitext-2017' : 'visualeditor'; + delete data.mode; + } + event = $.extend( { version: 1, action: action,