jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/388131 )

Change subject: Track usage of features
......................................................................


Track usage of features

This change adds tracking capabilities to the extension.

Bug: T173572
Change-Id: Ia2bdcf783da76273819dddab611f57cfda7aae63
---
M AdvancedSearch.hooks.php
M extension.json
A modules/dm/trackingEvents/ext.advancedSearch.SearchRequest.js
M modules/ext.advancedSearch.init.js
A tests/qunit/dm/trackingEvents/SearchRequest.test.js
5 files changed, 106 insertions(+), 1 deletion(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  WMDE-Fisch: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/AdvancedSearch.hooks.php b/AdvancedSearch.hooks.php
index 10df22c..48899ea 100644
--- a/AdvancedSearch.hooks.php
+++ b/AdvancedSearch.hooks.php
@@ -72,7 +72,8 @@
                                'tests/qunit/ui/SearchPreview.test.js',
                                'tests/qunit/ui/TemplateSearch.test.js',
                                'tests/qunit/dm/SearchModel.test.js',
-                               'tests/qunit/dm/FileTypeOptionProvider.test.js'
+                               'tests/qunit/dm/FileTypeOptionProvider.test.js',
+                               
'tests/qunit/dm/trackingEvents/SearchRequest.test.js'
                        ],
                        'dependencies' => [
                                'ext.advancedSearch.ui.ArbitraryWordInput',
@@ -82,6 +83,7 @@
                                'ext.advancedSearch.ui.TemplateSearch',
                                'ext.advancedSearch.dm.SearchModel',
                                'ext.advancedSearch.dm.FileTypeOptionProvider',
+                               
'ext.advancedSearch.dm.trackingEvents.SearchRequest',
                                'oojs-ui'
                        ],
                        'localBasePath' => __DIR__,
diff --git a/extension.json b/extension.json
index 6c09f98..ae9599c 100644
--- a/extension.json
+++ b/extension.json
@@ -83,6 +83,7 @@
                                "ext.advancedSearch.util",
                                "ext.advancedSearch.dm.SearchModel",
                                "ext.advancedSearch.dm.FileTypeOptionProvider",
+                               
"ext.advancedSearch.dm.trackingEvents.SearchRequest",
                                "ext.advancedSearch.ui.ArbitraryWordInput",
                                "ext.advancedSearch.ui.FileTypeSelection",
                                "ext.advancedSearch.ui.FormState",
@@ -228,12 +229,23 @@
                                "ext.advancedSearch.util"
                        ]
                },
+               "ext.advancedSearch.dm.trackingEvents.SearchRequest": {
+                       "scripts": [
+                               
"modules/dm/trackingEvents/ext.advancedSearch.SearchRequest.js"
+                       ],
+                       "dependencies": [
+                               "oojs-ui"
+                       ]
+               },
                "ext.advancedSearch.util": {
                        "scripts": [
                                "modules/ext.advancedSearch.util.js"
                        ]
                }
        },
+       "EventLoggingSchemas": {
+               "AdvancedSearchRequest": 17379859
+       },
        "ResourceFileModulePaths": {
                "localBasePath": "",
                "remoteExtPath": "AdvancedSearch"
diff --git a/modules/dm/trackingEvents/ext.advancedSearch.SearchRequest.js 
b/modules/dm/trackingEvents/ext.advancedSearch.SearchRequest.js
new file mode 100644
index 0000000..f326885
--- /dev/null
+++ b/modules/dm/trackingEvents/ext.advancedSearch.SearchRequest.js
@@ -0,0 +1,60 @@
+( function ( mw ) {
+       'use strict';
+
+       mw.libs = mw.libs || {};
+       mw.libs.advancedSearch = mw.libs.advancedSearch || {};
+       mw.libs.advancedSearch.dm = mw.libs.advancedSearch.dm || {};
+       mw.libs.advancedSearch.dm.trackingEvents = 
mw.libs.advancedSearch.dm.trackingEvents || {};
+
+       /**
+        * @class
+        * @constructor
+        */
+       mw.libs.advancedSearch.dm.trackingEvents.SearchRequest = function () {
+               this.eventName = 'AdvancedSearchRequest';
+               this.eventData = {
+                       plain: false,
+                       phrase: false,
+                       not: false,
+                       or: false,
+                       intitle: false,
+                       hastemplate: false
+               };
+       };
+
+       OO.initClass( mw.libs.advancedSearch.dm.trackingEvents.SearchRequest );
+
+       /**
+        * Gets the event name
+        *
+        * @return {string}
+        */
+       
mw.libs.advancedSearch.dm.trackingEvents.SearchRequest.prototype.getEventName = 
function () {
+               return this.eventName;
+       };
+
+       /**
+        * Gets the event data
+        *
+        * @return {object}
+        */
+       
mw.libs.advancedSearch.dm.trackingEvents.SearchRequest.prototype.getEventData = 
function () {
+               return this.eventData;
+       };
+
+       /**
+        * Populate tracking event by given search options
+        *
+        * @param {Object} searchOptions
+        */
+       
mw.libs.advancedSearch.dm.trackingEvents.SearchRequest.prototype.populateFromStoreOptions
 = function ( searchOptions ) {
+               var self = this;
+
+               for ( var key in searchOptions ) {
+                       if ( searchOptions.hasOwnProperty( key ) && 
searchOptions[ key ].length ) {
+                               self.eventData[ key ] = true;
+                       }
+               }
+       };
+
+}( mediaWiki ) );
diff --git a/modules/ext.advancedSearch.init.js 
b/modules/ext.advancedSearch.init.js
index 136fb4d..b9bcd16 100644
--- a/modules/ext.advancedSearch.init.js
+++ b/modules/ext.advancedSearch.init.js
@@ -337,6 +337,12 @@
 
        $searchField.val( getSearchOriginal() );
 
+       $search.on( 'submit', function () {
+               var trackingEvent = new 
mw.libs.advancedSearch.dm.trackingEvents.SearchRequest();
+               trackingEvent.populateFromStoreOptions( state.getOptions() );
+               mw.track( 'event.' + trackingEvent.getEventName(), 
trackingEvent.getEventData() );
+       } );
+
        function createWidget( option ) {
                var initializationFunction = option.init ||
                        function () {
diff --git a/tests/qunit/dm/trackingEvents/SearchRequest.test.js 
b/tests/qunit/dm/trackingEvents/SearchRequest.test.js
new file mode 100644
index 0000000..7c036e9
--- /dev/null
+++ b/tests/qunit/dm/trackingEvents/SearchRequest.test.js
@@ -0,0 +1,25 @@
+( function ( mw ) {
+       var SearchRequest,
+               SearchModel;
+
+       QUnit.module( 'ext.advancedSearch.dm.trackingEvents.SearchRequest' );
+
+       QUnit.testStart( function () {
+               SearchModel = mw.libs.advancedSearch.dm.SearchModel;
+               SearchRequest = 
mw.libs.advancedSearch.dm.trackingEvents.SearchRequest;
+       } );
+
+       QUnit.test( 'using search options are reflected in the tracking event', 
function ( assert ) {
+               var searchModel = new SearchModel(),
+                       trackingEvent = new SearchRequest();
+
+               searchModel.storeOption( 'plain', [ 'some', 'value' ] );
+               searchModel.storeOption( 'not', 'some word' );
+               trackingEvent.populateFromStoreOptions( 
searchModel.getOptions() );
+
+               assert.strictEqual( true, trackingEvent.getEventData().plain, 
'option "plain" is being used' );
+               assert.strictEqual( true, trackingEvent.getEventData().not, 
'option "not" is being used' );
+               assert.strictEqual( false, trackingEvent.getEventData().or, 
'option "or" is not being used' );
+       } );
+
+}( mediaWiki ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/388131
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia2bdcf783da76273819dddab611f57cfda7aae63
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Kai Nissen (WMDE) <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Andrew-WMDE <[email protected]>
Gerrit-Reviewer: Gabriel Birke <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Pablo Grass (WMDE) <[email protected]>
Gerrit-Reviewer: Tobias Gritschacher <[email protected]>
Gerrit-Reviewer: WMDE-Fisch <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to