r85048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85047‎ | r85048 | r85049 >
Date:21:01, 30 March 2011
Author:tparscal
Status:ok
Tags:
Comment:
Changed how events and cookies are named, now including version numbers, and added more tracking. Now we are tracking:
* pitch-<name>-show
* pitch-<name>-accept
* pitch-<name>-altAccept
* pitch-<name>-reject
* survey-submit-attempt
* survey-submit-complete
* survey-cancel
Modified paths:
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/ArticleFeedback.php (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php
@@ -203,9 +203,12 @@
204204 * ResourceLoaderGetConfigVars hook
205205 */
206206 public static function resourceLoaderGetConfigVars( &$vars ) {
207 - global $wgArticleFeedbackCategories, $wgArticleFeedbackLotteryOdds;
 207+ global $wgArticleFeedbackCategories,
 208+ $wgArticleFeedbackLotteryOdds,
 209+ $wgArticleFeedbackTrackingVersion;
208210 $vars['wgArticleFeedbackCategories'] = $wgArticleFeedbackCategories;
209211 $vars['wgArticleFeedbackLotteryOdds'] = $wgArticleFeedbackLotteryOdds;
 212+ $vars['wgArticleFeedbackTrackingVersion'] = $wgArticleFeedbackTrackingVersion;
210213 return true;
211214 }
212215 }
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -5,6 +5,17 @@
66 ( function( $, mw ) {
77
88 /**
 9+ * Prefixes a key for cookies or events, with extension and version information
 10+ *
 11+ * @param event String: Name of event to prefix
 12+ * @return String: Prefixed event name
 13+ */
 14+function prefix( key ) {
 15+ var version = mw.config.get( 'wgArticleFeedbackTrackingVersion' ) || 0;
 16+ return 'ext.articleFeedback@' + version + '-' + key;
 17+}
 18+
 19+/**
920 * Article Feedback jQuery Plugin Support Code
1021 */
1122 $.articleFeedback = {
@@ -358,9 +369,9 @@
359370 .text( mw.msg( context.options.pitches[key].accept ) )
360371 .click( function() {
361372 var $pitch = $(this).closest( '.articleFeedback-pitch' );
 373+ var key = $pitch.attr( 'rel' );
362374 return $.articleFeedback.fn.executePitch.call(
363 - $(this),
364 - context.options.pitches[$pitch.attr( 'rel' )].action
 375+ $(this), context.options.pitches[key].action
365376 );
366377 } )
367378 .button()
@@ -370,13 +381,16 @@
371382 .text( mw.msg( context.options.pitches[key].reject ) )
372383 .click( function() {
373384 var $pitch = $(this).closest( '.articleFeedback-pitch' );
 385+ var key = $pitch.attr( 'rel' );
374386 // Remember that the users rejected this, set a cookie to not
375387 // show this for 3 days
376388 $.cookie(
377 - 'jquery.articleFeedback-pitch.' + $pitch.attr( 'rel' ),
378 - 'hide',
379 - { 'expires': 3 }
 389+ prefix( 'pitch-' + key ), 'hide', { 'expires': 3 }
380390 );
 391+ // Track that a pitch was dismissed
 392+ if ( typeof $.trackAction == 'function' ) {
 393+ $.trackAction( prefix( 'pitch-' + key + '-reject' ) );
 394+ }
381395 $pitch.fadeOut( 'fast', function() {
382396 context.$ui.find( '.articleFeedback-ui' ).show();
383397 } );
@@ -399,9 +413,9 @@
400414 .text( mw.msg( context.options.pitches[key].altAccept ) )
401415 .click( function() {
402416 var $pitch = $(this).closest( '.articleFeedback-pitch' );
 417+ var key = $pitch.attr( 'rel' );
403418 return $.articleFeedback.fn.executePitch.call(
404 - $(this),
405 - context.options.pitches[$pitch.attr( 'rel' )].altAction
 419+ $(this), context.options.pitches[key].altAction
406420 );
407421 } )
408422 .button()
@@ -455,7 +469,7 @@
456470 for ( var key in context.options.pitches ) {
457471 // Dont' bother checking the condition if there's a cookie that says
458472 // the user has rejected this within 3 days of right now
459 - var display = $.cookie( 'jquery.articleFeedback-pitch.' + key );
 473+ var display = $.cookie( prefix( 'pitch-' + key ) );
460474 if ( display !== 'hide' && context.options.pitches[key].condition() ) {
461475 pitches.push( key );
462476 }
@@ -469,8 +483,8 @@
470484 .fadeIn( 'fast' );
471485 context.$ui.find( '.articleFeedback-ui' ).hide();
472486 // Track that a pitch was presented
473 - if ( typeof $.trackActionWithInfo == 'function' ) {
474 - $.trackActionWithInfo( 'jquery.articlefeedback-pitch', key );
 487+ if ( typeof $.trackAction == 'function' ) {
 488+ $.trackAction( prefix( 'pitch-' + key + '-show' ) );
475489 }
476490 } else {
477491 // Give user some feedback that a save occured
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
@@ -5,13 +5,24 @@
66 ( function( $, mw ) {
77
88 /**
 9+ * Prefixes a key for cookies or events, with extension and version information
 10+ *
 11+ * @param event String: Name of event to prefix
 12+ * @return String: Prefixed event name
 13+ */
 14+function prefix( key ) {
 15+ var version = mw.config.get( 'wgArticleFeedbackTrackingVersion' ) || 0;
 16+ return 'ext.articleFeedback@' + version + '-' + key;
 17+}
 18+
 19+/**
920 * Checks if a pitch is currently muted
1021 *
1122 * @param pitch String: Name of pitch to check
1223 * @return Boolean: Whether the pitch is muted
1324 */
1425 function isPitchVisible( pitch ) {
15 - return $.cookie( 'ext.articleFeedback-pitches.' + pitch ) != 'hide';
 26+ return $.cookie( prefix( 'pitches-' + pitch ) ) != 'hide';
1627 }
1728
1829 /**
@@ -21,21 +32,19 @@
2233 * @param durration Integer: Number of days to mute the pitch for
2334 */
2435 function mutePitch( pitch, duration ) {
25 - $.cookie( 'ext.articleFeedback-pitches.' + pitch, 'hide', { 'expires': duration } );
 36+ $.cookie( prefix( 'pitches-' + pitch ), 'hide', { 'expires': duration } );
2637 }
2738
2839 function trackClick( id ) {
2940 // Track the click so we can figure out how useful this is
3041 if ( typeof $.trackActionWithInfo == 'function' ) {
31 - $.trackActionWithInfo(
32 - 'ext.articleFeedback-' + id, mediaWiki.config.get( 'wgTitle' )
33 - )
 42+ $.trackActionWithInfo( prefix( id ), mediaWiki.config.get( 'wgTitle' ) )
3443 }
3544 }
3645
3746 function trackClickURL( url, id ) {
3847 if ( typeof $.trackActionURL == 'function' ) {
39 - return $.trackActionURL( url, 'ext.articleFeedback-' + id );
 48+ return $.trackActionURL( url, prefix( id ) );
4049 } else {
4150 return url;
4251 }
@@ -80,12 +89,12 @@
8190 'modal': true,
8291 'title': mw.msg( 'articlefeedback-survey-title' ),
8392 'close': function() {
 93+ // Click tracking
 94+ trackClick( 'survey-cancel' );
8495 // Return the survey to default state
 96+ $dialog.dialog( 'option', 'height', 400 );
 97+ $form.show();
8598 $message.remove();
86 - $form.show();
87 - $dialog
88 - .dialog( 'option', 'height', 400 )
89 - .dialog( 'close' );
9099 }
91100 } )
92101 .load( formSource, function() {
@@ -140,6 +149,8 @@
141150 }
142151 }
143152 } );
 153+ // Click tracking
 154+ trackClick( 'survey-submit-attempt' );
144155 // XXX: Not only are we submitting to a special page instead of an API request, but we are
145156 // screen-scraping the result - this is evil and needs to be addressed later
146157 $.ajax( {
@@ -156,6 +167,8 @@
157168 that.alert( success ? 'success' : 'error' );
158169 // Mute for 30 days
159170 mutePitch( 'survey', 30 );
 171+ // Click tracking
 172+ trackClick( 'survey-submit-complete' );
160173 },
161174 'error': function( XMLHttpRequest, textStatus, errorThrown ) {
162175 // Take the dialog out of "loading" state
@@ -207,7 +220,7 @@
208221 'action': function() {
209222 survey.load();
210223 // Click tracking
211 - trackClick( 'pitch-survey' );
 224+ trackClick( 'pitch-survey-accept' );
212225 // Hide the pitch immediately
213226 return true;
214227 },
@@ -231,7 +244,7 @@
232245 'title': 'Special:UserLogin',
233246 'type': 'signup',
234247 'returnto': mediaWiki.config.get( 'wgPageName' )
235 - } ), 'pitch-join-signup' );
 248+ } ), 'pitch-signup-accept' );
236249 return false;
237250 },
238251 'title': 'articlefeedback-pitch-thanks',
@@ -250,7 +263,7 @@
251264 mediaWiki.config.get( 'wgScript' ) + '?' + $.param( {
252265 'title': 'Special:UserLogin',
253266 'returnto': mediaWiki.config.get( 'wgPageName' )
254 - } ), 'pitch-join-login' );
 267+ } ), 'pitch-join-accept' );
255268 return false;
256269 }
257270 },
@@ -279,8 +292,8 @@
280293 'title': mediaWiki.config.get( 'wgPageName' ),
281294 'action': 'edit',
282295 'clicktrackingsession': $.cookie( 'clicktracking-session' ),
283 - 'clicktrackingevent': 'ext.articleFeedback-pitch-edit-save'
284 - } ), 'pitch-edit' );
 296+ 'clicktrackingevent': prefix( 'pitch-edit-save' )
 297+ } ), 'pitch-edit-accept' );
285298 return false;
286299 },
287300 'title': 'articlefeedback-pitch-thanks',
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.php
@@ -31,6 +31,10 @@
3232 // are the smallest increments used.
3333 $wgArticleFeedbackLotteryOdds = 0;
3434
 35+// This version number is added to all tracking event names, so that changes in the software don't
 36+// corrupt the data being collected. Bump this when you want to start a new "experiment".
 37+$wgArticleFeedbackTrackingVersion = 0;
 38+
3539 // Would ordinarily call this articlefeedback but survey names are 16 chars max
3640 $wgPrefSwitchSurveys['articlerating'] = array(
3741 'updatable' => false,

Status & tagging log