r86145 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86144‎ | r86145 | r86146 >
Date:22:38, 15 April 2011
Author:tparscal
Status:ok
Tags:
Comment:
Added wgArticleFeedbackTrackingOdds, which allows only a subset of users to be tracked.
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/ext.articleFeedback/ext.articleFeedback.startup.js (modified) (history)
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/ArticleFeedback.hooks.php
@@ -204,10 +204,12 @@
205205 public static function resourceLoaderGetConfigVars( &$vars ) {
206206 global $wgArticleFeedbackCategories,
207207 $wgArticleFeedbackLotteryOdds,
208 - $wgArticleFeedbackTrackingVersion;
 208+ $wgArticleFeedbackTrackingVersion,
 209+ $wgArticleFeedbackTrackingOdds;
209210 $vars['wgArticleFeedbackCategories'] = $wgArticleFeedbackCategories;
210211 $vars['wgArticleFeedbackLotteryOdds'] = $wgArticleFeedbackLotteryOdds;
211212 $vars['wgArticleFeedbackTrackingVersion'] = $wgArticleFeedbackTrackingVersion;
 213+ $vars['wgArticleFeedbackTrackingOdds'] = $wgArticleFeedbackTrackingOdds;
212214 return true;
213215 }
214216 }
Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -4,6 +4,9 @@
55
66 ( function( $, mw ) {
77
 8+// Only track users who have been assigned to the tracking group
 9+var tracked = Number( $.cookie( 'ext.articleFeedback-tracking' ) );
 10+
811 /**
912 * Prefixes a key for cookies or events, with extension and version information
1013 *
@@ -396,7 +399,7 @@
397400 prefix( 'pitch-' + key ), 'hide', { 'expires': 3 }
398401 );
399402 // Track that a pitch was dismissed
400 - if ( typeof $.trackAction == 'function' ) {
 403+ if ( tracked && typeof $.trackAction == 'function' ) {
401404 $.trackAction( prefix( 'pitch-' + key + '-reject' ) );
402405 }
403406 $pitch.fadeOut( 'fast', function() {
@@ -491,7 +494,7 @@
492495 .fadeIn( 'fast' );
493496 context.$ui.find( '.articleFeedback-ui' ).hide();
494497 // Track that a pitch was presented
495 - if ( typeof $.trackAction == 'function' ) {
 498+ if ( tracked && typeof $.trackAction == 'function' ) {
496499 $.trackAction( prefix( 'pitch-' + key + '-show' ) );
497500 }
498501 } else {
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.js
@@ -4,6 +4,9 @@
55
66 ( function( $, mw ) {
77
 8+// Only track users who have been assigned to the tracking group
 9+var tracked = Number( $.cookie( 'ext.articleFeedback-tracking' ) );
 10+
811 /**
912 * Prefixes a key for cookies or events, with extension and version information
1013 *
@@ -37,13 +40,13 @@
3841
3942 function trackClick( id ) {
4043 // Track the click so we can figure out how useful this is
41 - if ( typeof $.trackActionWithInfo == 'function' ) {
 44+ if ( tracked && typeof $.trackActionWithInfo == 'function' ) {
4245 $.trackActionWithInfo( prefix( id ), mediaWiki.config.get( 'wgTitle' ) )
4346 }
4447 }
4548
4649 function trackClickURL( url, id ) {
47 - if ( typeof $.trackActionURL == 'function' ) {
 50+ if ( tracked && typeof $.trackActionURL == 'function' ) {
4851 return $.trackActionURL( url, prefix( id ) );
4952 } else {
5053 return url;
Index: trunk/extensions/ArticleFeedback/modules/ext.articleFeedback/ext.articleFeedback.startup.js
@@ -12,6 +12,36 @@
1313 && mw.util.getParamValue( 'diff' ) === null
1414 && mw.util.getParamValue( 'oldid' ) === null
1515 ) {
 16+ // If the version in the client's cookie doesn't match wgArticleFeedbackTrackingVersion,
 17+ // then we need to disregard the bucket they may already be in to ensure accurate
 18+ // redistribution when the odds are changed
 19+ var previousVersion = $.cookie( 'ext.articleFeedback-version' );
 20+ var currentVersion = Number( mw.config.get( 'wgArticleFeedbackTrackingVersion', 0 ) );
 21+ var tracking = null;
 22+ if ( previousVersion === null || Number( previousVersion ) != currentVersion ) {
 23+ $.cookie( 'ext.articleFeedback-version', currentVersion );
 24+ } else {
 25+ tracking = $.cookie( 'ext.articleFeedback-tracking' );
 26+ }
 27+ if ( tracking === null ) {
 28+ // Percentage chance of being tracked
 29+ var odds = Math.min( 100, Math.max( 0,
 30+ Number( mw.config.get( 'wgArticleFeedbackTrackingOdds', 0 ) )
 31+ ) );
 32+ // 0 = not tracked, 1 = tracked
 33+ tracking = Number( Math.random() * 100 < odds );
 34+ // Let the cookie expire after 30 days, allowing rotation in which users are tracked
 35+ $.cookie( 'ext.articleFeedback-tracking', tracking, { 'path': '/', 'expires': 30 } );
 36+ // To be extra-sure that the odds are being applied properly, track whether a user is to
 37+ // be tracked or not - this way we can compare the number of people in each bucket to
 38+ // the intended percentages defined by wgArticleFeedbackTrackingOdds
 39+ if ( 'trackAction' in $ ) {
 40+ $.trackAction(
 41+ 'ext.articleFeedback@' + currentVersion + '-tracking-' +
 42+ ( tracking ? 'on' : 'off' )
 43+ );
 44+ }
 45+ }
1646 // Category activation
1747 var articleFeedbackCategories = mw.config.get( 'wgArticleFeedbackCategories', [] );
1848 var articleCategories = mw.config.get( 'wgCategories', [] );
Index: trunk/extensions/ArticleFeedback/ArticleFeedback.php
@@ -35,6 +35,13 @@
3636 // corrupt the data being collected. Bump this when you want to start a new "experiment".
3737 $wgArticleFeedbackTrackingVersion = 0;
3838
 39+// Not all users need to be tracked, but we do want to track some users over time - this value is
 40+// used when deciding to track someone or not, placing them in one of two buckets: tracked and not.
 41+// When $wgArticleFeedbackTrackingVersion changes, users will be re-bucketed, so you should always
 42+// increment $wgArticleFeedbackTrackingVersion when changing this number to ensure the new odds
 43+// are applied to everyone, not just people who have yet to be placed in a bucket.
 44+$wgArticleFeedbackTrackingOdds = 100;
 45+
3946 // Would ordinarily call this articlefeedback but survey names are 16 chars max
4047 $wgPrefSwitchSurveys['articlerating'] = array(
4148 'updatable' => false,

Status & tagging log