Add tracking of template usage

The names in the schema are roughly following what's
done in Schema:TemplateWizard. The information if
templates have TemplateData will be logged seperatly.

Bug: T259705
Change-Id: Iafa7256f675dbfd6a5a6de794061901780e3c55d
This commit is contained in:
WMDE-Fisch 2020-12-11 16:09:45 +01:00
parent 3a0c565597
commit 2ce9934ab9
3 changed files with 49 additions and 2 deletions

View file

@ -2818,5 +2818,12 @@
"ConfigRegistry": {
"visualeditor": "GlobalVarConfig::newInstance"
},
"attributes": {
"EventLogging": {
"Schemas": {
"VisualEditorTemplateDialogUse": 20813064
}
}
},
"manifest_version": 2
}

View file

@ -389,7 +389,9 @@ ve.ui.MWTemplateDialog.prototype.checkRequiredParameters = function () {
* @inheritdoc
*/
ve.ui.MWTemplateDialog.prototype.getActionProcess = function ( action ) {
var dialog = this;
var templateEvent, i,
dialog = this;
if ( action === 'done' || action === 'insert' ) {
return new OO.ui.Process( function () {
var deferred = ve.createDeferred();
@ -410,6 +412,20 @@ ve.ui.MWTemplateDialog.prototype.getActionProcess = function ( action ) {
modelPromise = dialog.transclusionModel.insertTransclusionNode( dialog.getFragment() );
}
// TODO tracking will only be implemented temporarily to answer questions on
// template usage for the Technical Wishes topic area see T258917
templateEvent = {
action: 'save',
// eslint-disable-next-line camelcase
template_names: []
};
for ( i = 0; i < dialog.transclusionModel.getParts().length; i++ ) {
if ( dialog.transclusionModel.getParts()[ i ].getTitle ) {
templateEvent.template_names.push( dialog.transclusionModel.getParts()[ i ].getTitle() );
}
}
mw.track( 'event.VisualEditorTemplateDialogUse', templateEvent );
return modelPromise.then( function () {
dialog.close( { action: action } ).closed.always( dialog.popPending.bind( dialog ) );
} );
@ -429,7 +445,7 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
data = data || {};
return ve.ui.MWTemplateDialog.super.prototype.getSetupProcess.call( this, data )
.next( function () {
var template, promise,
var template, promise, templateEvent, i,
dialog = this;
// Properties
@ -467,6 +483,21 @@ ve.ui.MWTemplateDialog.prototype.getSetupProcess = function ( data ) {
}
} else {
// Load existing template
// TODO tracking will only be implemented temporarily to answer questions on
// template usage for the Technical Wishes topic area see T258917
templateEvent = {
action: 'edit',
// eslint-disable-next-line camelcase
template_names: []
};
for ( i = 0; i < this.selectedNode.partsList.length; i++ ) {
if ( this.selectedNode.partsList[ i ].templatePage ) {
templateEvent.template_names.push( this.selectedNode.partsList[ i ].templatePage );
}
}
mw.track( 'event.VisualEditorTemplateDialogUse', templateEvent );
promise = this.transclusionModel
.load( ve.copy( this.selectedNode.getAttribute( 'mw' ) ) )
.then( this.initializeTemplateParameters.bind( this ) );

View file

@ -131,6 +131,15 @@ ve.ui.MWTemplatePlaceholderPage.prototype.onAddTemplate = function () {
// Invalid titles return null, so abort here.
return;
}
// TODO tracking will only be implemented temporarily to answer questions on
// template usage for the Technical Wishes topic area see T258917
mw.track( 'event.VisualEditorTemplateDialogUse', {
action: 'add-template',
// eslint-disable-next-line camelcase
template_names: [ name.getPrefixedText() ]
} );
part = ve.dm.MWTemplateModel.newFromName( transclusion, name );
transclusion.replacePart( this.placeholder, part );
this.addTemplateInput.pushPending();