r106251 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106250‎ | r106251 | r106252 >
Date:22:06, 14 December 2011
Author:rsterbin
Status:ok
Tags:
Comment:
First pass addressing bug #32992:
- modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js:
- Moved determination of whether to track clicks out into the jquery
plugin
- Updated clickFeedbackLink() to use the jquery plugin for tracking
- Prefixing of tracking ids now happens in the plugin
- The vertical link now has its own tracking id
- modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js:
- New property clickTracking
- New methods checkClickTracking(), bucketName(), ctaName(),
trackingUrl(), editUrl(), and trackClick()
- Updated init() to call checkClickTracking()
- Updated bucket 4 and cta 1 to use editUrl()
- Added trackClick() to the externally-accessible methods
- Added click tracking for:
- Submit button (buckets 1, 2, and 3)
- Edit button for bucket 4
- Edit button for cta 1
- Learn more button for cta 2
- Form load
- CTA load
- Overlay close
- ArticleFeedbackv5.php:
- Switched to tracking everybody by default
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -62,6 +62,11 @@
6363 $.articleFeedbackv5.debug = mw.config.get( 'wgArticleFeedbackv5Debug' ) ? true : false;
6464
6565 /**
 66+ * Are we tracking clicks?
 67+ */
 68+ $.articleFeedbackv5.clickTracking = false;
 69+
 70+ /**
6671 * Have the containers been added?
6772 */
6873 $.articleFeedbackv5.hasContainers = false;
@@ -398,6 +403,8 @@
399404 $block.find( '.articleFeedbackv5-submit' )
400405 .click( function ( e ) {
401406 e.preventDefault();
 407+ $.articleFeedbackv5.trackClick( 'option1-submit-' +
 408+ ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
402409 $.articleFeedbackv5.submitForm();
403410 } );
404411 },
@@ -652,8 +659,9 @@
653660 // Attach the submit
654661 $block.find( '.articleFeedbackv5-submit' )
655662 .click( function ( e ) {
656 - //alert( 'got to click event' );
657663 e.preventDefault();
 664+ $.articleFeedbackv5.trackClick( 'option2-submit-' +
 665+ ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
658666 $.articleFeedbackv5.submitForm();
659667 } );
660668
@@ -980,6 +988,8 @@
981989 $block.find( '.articleFeedbackv5-submit' )
982990 .click( function ( e ) {
983991 e.preventDefault();
 992+ $.articleFeedbackv5.trackClick( 'option3-submit-' +
 993+ ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
984994 $.articleFeedbackv5.submitForm();
985995 } );
986996
@@ -1118,16 +1128,10 @@
11191129 .attr( 'href', mw.config.get( 'wgArticleFeedbackv5LearnToEdit' ) );
11201130
11211131 // Fill in the edit link
1122 - $block.find( '.articleFeedbackv5-submit' )
1123 - .attr( 'href',
1124 - mw.config.get( 'wgScript' ) + '?' + $.param( {
1125 - 'title': mw.config.get( 'wgPageName' ),
1126 - 'action': 'edit',
1127 - 'articleFeedbackv5_feedback_id': $.articleFeedbackv5.feedbackId,
1128 - 'articleFeedbackv5_cta_id': $.articleFeedbackv5.ctaId,
1129 - 'articleFeedbackv5_bucket_id': $.articleFeedbackv5.bucketId
1130 - } )
1131 - );
 1132+ var edit_track_id = $.articleFeedbackv5.buttonName() + '-button-click-' +
 1133+ ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' );
 1134+ $block.find( '.articleFeedbackv5-cta-button' )
 1135+ .attr( 'href', $.articleFeedbackv5.editUrl( edit_track_id ) );
11321136
11331137 // Turn the submit into a slick button
11341138 $block.find( '.articleFeedbackv5-submit' )
@@ -1898,17 +1902,10 @@
18991903 .attr( 'href', mw.msg( 'articlefeedbackv5-cta1-learn-how-url' ) );
19001904
19011905 // Fill in the link
 1906+ var edit_track_id = $.articleFeedbackv5.ctaName() + '-button-click-' +
 1907+ ( $.articleFeedbackv5.inDialog ? 'overlay': 'bottom' );
19021908 $block.find( '.articleFeedbackv5-cta-button' )
1903 - .attr(
1904 - 'href',
1905 - mw.config.get( 'wgScript' ) + '?' + $.param( {
1906 - 'title': mw.config.get( 'wgPageName' ),
1907 - 'action': 'edit',
1908 - 'articleFeedbackv5_feedback_id': $.articleFeedbackv5.feedbackId,
1909 - 'articleFeedbackv5_cta_id': $.articleFeedbackv5.ctaId,
1910 - 'articleFeedbackv5_bucket_id': $.articleFeedbackv5.bucketId
1911 - } )
1912 - );
 1909+ .attr( 'href', $.articleFeedbackv5.editUrl( edit_track_id ) );
19131910
19141911 return $block;
19151912 },
@@ -1970,8 +1967,11 @@
19711968 var $block = $( $.articleFeedbackv5.currentCTA().templates.block );
19721969
19731970 // Fill in the button link
 1971+ var learn_url = mw.msg( 'articlefeedbackv5-cta1-learn-how-url' );
 1972+ var learn_track_id = $.articleFeedbackv5.ctaName() + '-button-click-' +
 1973+ ( $.articleFeedbackv5.inDialog ? 'overlay': 'bottom' );
19741974 $block.find( '.articleFeedbackv5-cta-button' )
1975 - .attr( 'href', mw.msg( 'articlefeedbackv5-cta1-learn-how-url' ) );
 1975+ .attr( 'href', $.articleFeedbackv5.trackingUrl( learn_url, learn_track_id ) );
19761976
19771977 return $block;
19781978 },
@@ -2013,6 +2013,8 @@
20142014 $.articleFeedbackv5.init = function ( $el, config ) {
20152015 $.articleFeedbackv5.$holder = $el;
20162016 $.articleFeedbackv5.config = config;
 2017+ // Are we tracking clicks?
 2018+ $.articleFeedbackv5.clickTracking = $.articleFeedbackv5.checkClickTracking();
20172019 // Has the user already submitted ratings for this page at this revision?
20182020 $.articleFeedbackv5.alreadySubmitted = $.cookie( $.articleFeedbackv5.prefix( 'submitted' ) ) === 'true';
20192021 // Are we in debug mode?
@@ -2077,8 +2079,28 @@
20782080 };
20792081
20802082 // }}}
 2083+ // {{{ checkClickTracking
20812084
 2085+ /**
 2086+ * Checks whether click tracking is turned on
 2087+ *
 2088+ * Only track users who have been assigned to the tracking group; don't bucket
 2089+ * at all if we're set to always ignore or always track.
 2090+ */
 2091+ $.articleFeedbackv5.checkClickTracking = function () {
 2092+ var b = mw.config.get( 'wgArticleFeedbackv5Tracking' );
 2093+ if ( b.buckets.ignore == 100 && b.buckets.track == 0 ) {
 2094+ return false;
 2095+ }
 2096+ if ( b.buckets.ignore == 0 && b.buckets.track == 100 ) {
 2097+ return true;
 2098+ }
 2099+ return ( 'track' === mw.user.bucket( 'ext.articleFeedbackv5-tracking', b ) );
 2100+ };
 2101+
20822102 // }}}
 2103+
 2104+ // }}}
20832105 // {{{ Utility methods
20842106
20852107 // {{{ prefix
@@ -2206,8 +2228,87 @@
22072229 };
22082230
22092231 // }}}
 2232+ // {{{ bucketName
22102233
 2234+ /**
 2235+ * Utility method: Gets the name of the current bucket
 2236+ *
 2237+ * @return string the bucket name
 2238+ */
 2239+ $.articleFeedbackv5.bucketName = function () {
 2240+ return 'option' + $.articleFeedbackv5.bucketId;
 2241+ };
 2242+
22112243 // }}}
 2244+ // {{{ ctaName
 2245+
 2246+ /**
 2247+ * Utility method: Gets the name of the current CTA
 2248+ *
 2249+ * @return string the CTA name
 2250+ */
 2251+ $.articleFeedbackv5.ctaName = function () {
 2252+ if ( '0' == $.articleFeedbackv5.ctaId ) {
 2253+ return 'cta-none';
 2254+ } else if ( '1' == $.articleFeedbackv5.ctaId ) {
 2255+ return 'cta-edit';
 2256+ } else if ( '2' == $.articleFeedbackv5.ctaId ) {
 2257+ return 'cta-learn-more';
 2258+ } else {
 2259+ return 'cta-unknown';
 2260+ }
 2261+ };
 2262+
 2263+ // }}}
 2264+ // {{{ trackingUrl
 2265+
 2266+ /**
 2267+ * Creates a URL that tracks a particular click
 2268+ *
 2269+ * @param url string the url so far
 2270+ * @param trackingId string the tracking ID
 2271+ */
 2272+ $.articleFeedbackv5.trackingUrl = function ( url, trackingId ) {
 2273+ if ( $.articleFeedbackv5.clickTracking && $.isFunction( $.trackActionURL ) ) {
 2274+ return $.trackActionURL( url, $.articleFeedbackv5.prefix( trackingId ) );
 2275+ } else {
 2276+ return url;
 2277+ }
 2278+ };
 2279+
 2280+ // }}}
 2281+ // {{{ editUrl
 2282+
 2283+ /**
 2284+ * Builds the edit URL, with tracking if appropriate
 2285+ *
 2286+ * @param trackingId string the tracking ID
 2287+ */
 2288+ $.articleFeedbackv5.editUrl = function ( url, trackingId ) {
 2289+ var params = {
 2290+ 'title': mw.config.get( 'wgPageName' ),
 2291+ 'action': 'edit',
 2292+ };
 2293+ if ( $.articleFeedbackv5.bucketId ) {
 2294+ params.articleFeedbackv5_bucket_id = $.articleFeedbackv5.bucketId;
 2295+ }
 2296+ if ( $.articleFeedbackv5.ctaId ) {
 2297+ params.articleFeedbackv5_cta_id = $.articleFeedbackv5.ctaId;
 2298+ }
 2299+ if ( $.articleFeedbackv5.feedbackId ) {
 2300+ params.articleFeedbackv5_feedback_id = $.articleFeedbackv5.feedbackId;
 2301+ }
 2302+ var url = mw.config.get( 'wgScript' ) + '?' + $.param( params );
 2303+ if ( trackingId ) {
 2304+ return $.articleFeedbackv5.trackingUrl( url, trackingId );
 2305+ } else {
 2306+ return url;
 2307+ }
 2308+ };
 2309+
 2310+ // }}}
 2311+
 2312+ // }}}
22122313 // {{{ Process methods
22132314
22142315 // {{{ load
@@ -2358,6 +2459,14 @@
23592460 bucket.afterBuild();
23602461 }
23612462
 2463+ // Track the event
 2464+ if ( $.articleFeedbackv5.inDialog ) {
 2465+ $.articleFeedbackv5.trackClick( $.articleFeedbackv5.bucketName() + '-overlay-impression' );
 2466+ } else {
 2467+ // Don't track bottom-of-the-page loads, at least for now
 2468+ // $.articleFeedbackv5.trackClick( $.articleFeedbackv5.bucketName() + '-bottom-impression' );
 2469+ }
 2470+
23622471 $.articleFeedbackv5.nowShowing = 'form';
23632472 };
23642473
@@ -2546,6 +2655,10 @@
25472656 // Reset the panel dimensions
25482657 $.articleFeedbackv5.setDialogDimensions();
25492658
 2659+ // Track the event
 2660+ $.articleFeedbackv5.trackClick( $.articleFeedbackv5.ctaName() + '-impression-' +
 2661+ ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
 2662+
25502663 $.articleFeedbackv5.nowShowing = 'cta';
25512664 };
25522665
@@ -2795,6 +2908,11 @@
27962909 */
27972910 $.articleFeedbackv5.closeAsModal = function () {
27982911 if ( $.articleFeedbackv5.inDialog ) {
 2912+ if ( 'form' == $.articleFeedbackv5.nowShowing ) {
 2913+ $.articleFeedbackv5.trackClick( $.articleFeedbackv5.bucketName() + '-overlay-close' );
 2914+ } else if ('cta' == $.articleFeedbackv5.nowShowing ) {
 2915+ $.articleFeedbackv5.trackClick( $.articleFeedbackv5.ctaName() + '-overlay-close' );
 2916+ }
27992917 $.articleFeedbackv5.setLinkId( '0' );
28002918 $.articleFeedbackv5.$dialog.find( '.articleFeedbackv5-tooltip' ).hide();
28012919 $inner = $.articleFeedbackv5.$dialog.find( '.articleFeedbackv5-ui' ).detach();
@@ -2821,9 +2939,26 @@
28222940 };
28232941
28242942 // }}}
 2943+ // {{{ trackClick
28252944
 2945+ /**
 2946+ * Tracks a click
 2947+ *
 2948+ * @param trackingId string the tracking ID
 2949+ */
 2950+ $.articleFeedbackv5.trackClick = function ( trackingId ) {
 2951+ if ( $.articleFeedbackv5.clickTracking && $.isFunction( $.trackActionWithInfo ) ) {
 2952+ $.trackActionWithInfo(
 2953+ $.articleFeedbackv5.prefix( trackingId ),
 2954+ mw.config.get( 'wgTitle' )
 2955+ );
 2956+ }
 2957+ };
 2958+
28262959 // }}}
28272960
 2961+ // }}}
 2962+
28282963 // }}}
28292964 // {{{ articleFeedbackv5 plugin
28302965
@@ -2846,7 +2981,8 @@
28472982 prefix: { args: 1, ret: true },
28482983 addToRemovalQueue: { args: 1, ret: false },
28492984 openAsModal: { args: 1, ret: false },
2850 - closeAsModal: { args: 0, ret: true }
 2985+ closeAsModal: { args: 0, ret: true },
 2986+ trackClick: { args: 1, ret: false }
28512987 };
28522988 if ( opts in public ) {
28532989 var r;
Index: trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
@@ -18,39 +18,17 @@
1919
2020 /* Setup for feedback links */
2121
22 -// Only track users who have been assigned to the tracking group; don't bucket
23 -// at all if we're set to always ignore or always track.
24 -var useClickTracking = function () {
25 - var b = mw.config.get( 'wgArticleFeedbackv5Tracking' );
26 - if ( b.buckets.ignore == 100 && b.buckets.track == 0 ) {
27 - return false;
28 - }
29 - if ( b.buckets.ignore == 0 && b.buckets.track == 100 ) {
30 - return true;
31 - }
32 - return ( 'track' === mw.user.bucket( 'ext.articleFeedbackv5-tracking', b ) );
33 -}();
34 -
3522 // Info about each of the links
3623 var linkInfo = {
37 - '1': {
38 - clickTracking: $aftDiv.articleFeedbackv5( 'prefix', 'section-link' )
39 - },
40 - '2': {
41 - clickTracking: $aftDiv.articleFeedbackv5( 'prefix', 'titlebar-link' )
42 - },
43 - '4': {
44 - clickTracking: $aftDiv.articleFeedbackv5( 'prefix', 'toolbox-link' )
45 - }
 24+ '1': { trackId: 'section-link' },
 25+ '2': { trackId: 'titlebar-link' },
 26+ '3': { trackId: 'vertical-link' },
 27+ '4': { trackId: 'toolbox-link' }
4628 };
4729
4830 // Click event
4931 var clickFeedbackLink = function ( $link ) {
50 - // Click tracking
51 - if ( useClickTracking && $.isFunction( $.trackActionWithInfo ) ) {
52 - $.trackActionWithInfo( linkInfo[ $link.data( 'linkId' ) ].clickTracking, mw.config.get( 'wgTitle' ) );
53 - }
54 - // Open as modal
 32+ $aftDiv.articleFeedbackv5( 'trackClick', linkInfo[ $link.data( 'linkId' ) ].trackId );
5533 $aftDiv.articleFeedbackv5( 'openAsModal', $link );
5634 };
5735
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
@@ -82,7 +82,7 @@
8383 'tracked' => false,
8484 );
8585
86 -// Bucket settings for click tracking on feedback links
 86+// Bucket settings for click tracking across the plugin
8787 $wgArticleFeedbackv5Tracking = array(
8888 // Not all users need to be tracked, but we do want to track some users over time - these
8989 // buckets are used when deciding to track someone or not, placing them in one of two buckets:
@@ -91,8 +91,8 @@
9292 // this number to ensure the new odds are applied to everyone, not just people who have yet to
9393 // be placed in a bucket.
9494 'buckets' => array(
95 - 'ignore' => 100,
96 - 'track' => 0,
 95+ 'ignore' => 0,
 96+ 'track' => 100,
9797 ),
9898 // This version number is added to all tracking event names, so that changes in the software
9999 // don't corrupt the data being collected. Bump this when you want to start a new "experiment".

Follow-up revisions

RevisionCommit summaryAuthorDate
r106267Tweaks to tracking ids for bug #32992:...rsterbin22:30, 14 December 2011
r106268Tweak for bug #32992 -- renamed learn-more cta to learnmorersterbin22:36, 14 December 2011
r106469Added edit tracking and tweaked tracking ids for bug #32992:...rsterbin19:40, 16 December 2011

Status & tagging log