Phuedx has uploaded a new change for review. https://gerrit.wikimedia.org/r/132220
Change subject: Instrument the SignupExpCTAButtonClick schema ...................................................................... Instrument the SignupExpCTAButtonClick schema Change-Id: I6a2b1fdfde1034daa5ee99e136a054a6af329422 --- M GettingStarted.php M resources/ext.gettingstarted.anonymousEditorAcquisition.js M resources/tours/anonymouseditoracquisitionpostedit.js M resources/tours/anonymouseditoracquisitionpreedit.js M resources/tours/anonymouseditoracquisitionpreeditve.js 5 files changed, 134 insertions(+), 26 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GettingStarted refs/changes/20/132220/1 diff --git a/GettingStarted.php b/GettingStarted.php index 005de1f..e404772 100644 --- a/GettingStarted.php +++ b/GettingStarted.php @@ -294,6 +294,7 @@ 'mediawiki.Uri', 'ext.gettingstarted.user', 'schema.SignupExpPageLinkClick', + 'schema.SignupExpCTAButtonClick', 'ext.guidedTour.lib', ), 'messages' => array( @@ -319,6 +320,12 @@ 'revision' => 8101716 ); +$wgResourceModules[ 'schema.SignupExpCTAButtonClick' ] = array( + 'class' => 'ResourceLoaderSchemaModule', + 'schema' => 'SignupExpCTAButtonClick', + 'revision' => 8102619 +); + $wgResourceModules[ 'ext.gettingstarted.assignToken' ] = array( 'scripts' => 'ext.gettingstarted.assignToken.js', 'dependencies' => array( diff --git a/resources/ext.gettingstarted.anonymousEditorAcquisition.js b/resources/ext.gettingstarted.anonymousEditorAcquisition.js index 9c070e2..d66c707 100644 --- a/resources/ext.gettingstarted.anonymousEditorAcquisition.js +++ b/resources/ext.gettingstarted.anonymousEditorAcquisition.js @@ -6,7 +6,7 @@ user = mw.gettingStarted.user, token = user.getToken(), bucket = user.getBucket(), - LOG_LINK_CLICK_DELAY = 500, // (ms) + LOG_EVENT_TIMEOUT = 500, // (ms) tourToSelectorMapping = { 'anonymouseditoracquisitionpreedit': [ '#ca-edit', '.mw-editsection a:not( .mw-editsection-visualeditor )' ], 'anonymouseditoracquisitionpreeditve': [ '#ca-ve-edit', '.mw-editsection-visualeditor ' ] @@ -17,7 +17,21 @@ isViewPage = ( mw.config.get( 'wgIsArticle' ) && !( 'diff' in currentUri.query ) - ); + ), + namespace = mw.config.get( 'wgNamespaceNumber' ), + self; + + // NOTE (phuedx, 2014/05/07): This function provides a consistent, internal API for logging + // events. + // + // Ideally the EventLogging API should provide an equivalent of `logEventOrTimeout`. + // However, there are currently concerns about the approach [0]. + // + // [0] https://bugzilla.wikimedia.org/show_bug.cgi?id=52287 + function logEvent( schemaName, eventInstance ) { + return mw.eventLog.logEvent( schemaName, eventInstance ); + } + /** * Registers a click listener on links corresponding to one or more selectors. @@ -26,8 +40,7 @@ * If `shouldDelay` is false, it will allow the normal link navigation to work. * * If `shouldDelay` is true, it will prevent normal navigation and wait for logging. When - * logging completes, or after a LOG_LINK_CLICK_DELAY-millisecond timeout, it will navigate - * then. + * logging completes, or after a 500 millisecond timeout, it will navigate then. * * @private * @@ -45,27 +58,53 @@ } $( selectors ).click( function ( event ) { - var logEventPromise, dfd; + var schemaName, eventInstance; - logEventPromise = mw.eventLog.logEvent( 'SignupExpPageLinkClick', { + schemaName = 'SignupExpPageLinkClick'; + eventInstance = { token: token, bucket: bucket, link: link, - namespace: mw.config.get( 'wgNamespaceNumber' ) - } ); + namespace: namespace + }; if ( shouldDelay ) { event.preventDefault(); - dfd = $.Deferred(); - dfd.always( function () { + logEventOrTimeout( schemaName, eventInstance ).always( function () { window.location.href = getHrefFromTarget( $( event.currentTarget ) ); } ); - - window.setTimeout( dfd.reject, LOG_LINK_CLICK_DELAY ); - logEventPromise.then( dfd.resolve, dfd.reject ); + } else { + logEvent( schemaName, eventInstance ); } } ); + } + + /** + * Attempts to log an event in less than 500 milliseconds. + * + * Returns a promise that will be resolved or rejected when either the HTTP request to log + * the event resolves or after 500 milliseconds. Note that in the former case the promise + * will be resolved or rejected depending on the outcome of the HTTP request, whereas in the + * latter case the promise will always be rejected. + * + * See `mw.eventLog.logEvent`. + * + * @private + * + * @param {string} schemaName The canonical name of the schema + * @param {Object} eventInstance The event instance + * @return {jQuery.Promise} + */ + function logEventOrTimeout( schemaName, eventInstance ) { + var dfd; + + dfd = $.Deferred(); + + window.setTimeout( dfd.reject, LOG_EVENT_TIMEOUT ); + logEvent( schemaName, eventInstance ).then( dfd.resolve, dfd.reject ); + + return dfd.promise(); } function unregisterPreEditVariant() { @@ -128,7 +167,7 @@ * @class mw.gettingStarted.anonymousEditorAcquisition * @singleton */ - mw.gettingStarted.anonymousEditorAcquisition = { + mw.gettingStarted.anonymousEditorAcquisition = self = { /** * Handles the 'no thanks' selection when the target * is a VisualEditor edit link. @@ -136,6 +175,13 @@ handleNoThanksForVisualEditor: function () { gt.hideAll(); if ( isViewPage ) { + logEvent( 'SignupExpCTAButtonClick', { + token: token, + cta: 'pre-edit', + button: 'edit', + namespace: namespace + } ); + // Load VE without full page load $currentGuiderTarget.click(); } else { @@ -148,23 +194,68 @@ * Handle no thanks by following a link with a full page load */ handleNoThanksWithPageLoad: function () { - window.location.href = getHrefFromTarget( $currentGuiderTarget ); + logEventOrTimeout( 'SignupExpCTAButtonClick', { + token: token, + cta: 'pre-edit', + button: 'edit', + namespace: namespace + } ).always( function () { + window.location.href = getHrefFromTarget( $currentGuiderTarget ); + } ); }, /** - * Handles then 'signup and edit' selection. Goes to the signup page, using the + * Handles the 'Sign up and edit' selection. Goes to the signup page, using the * current page as the returnto and the query string from the edit tab/link as the * returntoquery. */ handleSignupAndEdit: function () { - var uri = new mw.Uri( getHrefFromTarget( $currentGuiderTarget ) ); - delete uri.query.title; - window.location.href = new mw.Title( 'Special:UserLogin' ).getUrl( { - type: 'signup', - returnto: mw.config.get( 'wgPageName' ), - returntoquery: uri.getQueryString() - } ); + self.handleSignup( 'pre-edit', new mw.Uri( getHrefFromTarget( $currentGuiderTarget ) ) ); + }, + /** + * Handles the both the 'Sign up and edit' and 'Create my account' selections. + * + * @param {string=post-edit} cta The 'cta' parameter of the SignupExpCTAButtonClick + * schema. Either 'pre-edit' or 'post-edit' + * @param {mw.Uri} uri The URI to extract the returntoquery parameter from. + * Defaults to the current URI + */ + handleSignup: function ( cta, uri ) { + if ( cta === undefined ) { + cta = 'post-edit'; + } + + if ( uri === undefined ) { + uri = new mw.Uri(); + } + + delete uri.query.title; + + logEventOrTimeout( 'SignupExpCTAButtonClick', { + token: token, + cta: cta, + button: 'signup', + namespace: namespace + } ).always( function () { + window.location.href = new mw.Title( 'Special:UserLogin' ).getUrl( { + type: 'signup', + returnto: mw.config.get( 'wgPageName' ), + returntoquery: uri.getQueryString() + } ); + } ); + }, + + /** + * Handles dismissal of the pre- and post-edit CTAs. + */ + handleClose: function ( cta ) { + logEvent( 'SignupExpCTAButtonClick', { + token: token, + cta: cta, + button: 'dismiss', + namespace: namespace + } ); } }; diff --git a/resources/tours/anonymouseditoracquisitionpostedit.js b/resources/tours/anonymouseditoracquisitionpostedit.js index f7e8985..2e52262 100644 --- a/resources/tours/anonymouseditoracquisitionpostedit.js +++ b/resources/tours/anonymouseditoracquisitionpostedit.js @@ -2,8 +2,7 @@ 'use strict'; - var ptCreateaccountSelector = '#pt-createaccount', - $ptCreateaccount = $( ptCreateaccountSelector ); + var ptCreateaccountSelector = '#pt-createaccount'; gt.defineTour( { name: 'anonymouseditoracquisitionpostedit', @@ -25,10 +24,15 @@ namespace: mw.config.get( 'wgNamespaceNumber' ) } ); }, + onClose: function () { + mw.gettingStarted.anonymousEditorAcquisition.handleClose( 'post-edit' ); + }, buttons: [ { namemsg: 'guidedtour-tour-anonymouseditoracquisitionpostedit-continue', action: 'externalLink', - url: $ptCreateaccount.find( 'a' ).attr( 'href' ) + onclick: function () { + mw.gettingStarted.anonymousEditorAcquisition.handleSignup() ; + } } ] } ] } ); diff --git a/resources/tours/anonymouseditoracquisitionpreedit.js b/resources/tours/anonymouseditoracquisitionpreedit.js index dee4806..a4bc780 100644 --- a/resources/tours/anonymouseditoracquisitionpreedit.js +++ b/resources/tours/anonymouseditoracquisitionpreedit.js @@ -19,6 +19,9 @@ namespace: mw.config.get( 'wgNamespaceNumber' ) } ); }, + onClose: function () { + mw.gettingStarted.anonymousEditorAcquisition.handleClose( 'pre-edit' ); + }, buttons: [ // "No thanks" diff --git a/resources/tours/anonymouseditoracquisitionpreeditve.js b/resources/tours/anonymouseditoracquisitionpreeditve.js index 086971d..0e46e17 100644 --- a/resources/tours/anonymouseditoracquisitionpreeditve.js +++ b/resources/tours/anonymouseditoracquisitionpreeditve.js @@ -19,6 +19,9 @@ namespace: mw.config.get( 'wgNamespaceNumber' ) } ); }, + onClose: function () { + mw.gettingStarted.anonymousEditorAcquisition.handleClose( 'pre-edit' ); + }, buttons: [ // "No thanks" -- To view, visit https://gerrit.wikimedia.org/r/132220 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6a2b1fdfde1034daa5ee99e136a054a6af329422 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GettingStarted Gerrit-Branch: master Gerrit-Owner: Phuedx <g...@samsmith.io> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits