https://www.mediawiki.org/wiki/Special:Code/MediaWiki/106251
Revision: 106251
Author: rsterbin
Date: 2011-12-14 22:06:37 +0000 (Wed, 14 Dec 2011)
Log Message:
-----------
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
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
Modified: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php
===================================================================
--- trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php 2011-12-14
22:00:46 UTC (rev 106250)
+++ trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php 2011-12-14
22:06:37 UTC (rev 106251)
@@ -82,7 +82,7 @@
'tracked' => false,
);
-// Bucket settings for click tracking on feedback links
+// Bucket settings for click tracking across the plugin
$wgArticleFeedbackv5Tracking = array(
// Not all users need to be tracked, but we do want to track some users
over time - these
// buckets are used when deciding to track someone or not, placing them
in one of two buckets:
@@ -91,8 +91,8 @@
// this number to ensure the new odds are applied to everyone, not just
people who have yet to
// be placed in a bucket.
'buckets' => array(
- 'ignore' => 100,
- 'track' => 0,
+ 'ignore' => 0,
+ 'track' => 100,
),
// This version number is added to all tracking event names, so that
changes in the software
// don't corrupt the data being collected. Bump this when you want to
start a new "experiment".
Modified:
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
===================================================================
---
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
2011-12-14 22:00:46 UTC (rev 106250)
+++
trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js
2011-12-14 22:06:37 UTC (rev 106251)
@@ -18,39 +18,17 @@
/* Setup for feedback links */
-// Only track users who have been assigned to the tracking group; don't bucket
-// at all if we're set to always ignore or always track.
-var useClickTracking = function () {
- var b = mw.config.get( 'wgArticleFeedbackv5Tracking' );
- if ( b.buckets.ignore == 100 && b.buckets.track == 0 ) {
- return false;
- }
- if ( b.buckets.ignore == 0 && b.buckets.track == 100 ) {
- return true;
- }
- return ( 'track' === mw.user.bucket( 'ext.articleFeedbackv5-tracking',
b ) );
-}();
-
// Info about each of the links
var linkInfo = {
- '1': {
- clickTracking: $aftDiv.articleFeedbackv5( 'prefix',
'section-link' )
- },
- '2': {
- clickTracking: $aftDiv.articleFeedbackv5( 'prefix',
'titlebar-link' )
- },
- '4': {
- clickTracking: $aftDiv.articleFeedbackv5( 'prefix',
'toolbox-link' )
- }
+ '1': { trackId: 'section-link' },
+ '2': { trackId: 'titlebar-link' },
+ '3': { trackId: 'vertical-link' },
+ '4': { trackId: 'toolbox-link' }
};
// Click event
var clickFeedbackLink = function ( $link ) {
- // Click tracking
- if ( useClickTracking && $.isFunction( $.trackActionWithInfo ) ) {
- $.trackActionWithInfo( linkInfo[ $link.data( 'linkId' )
].clickTracking, mw.config.get( 'wgTitle' ) );
- }
- // Open as modal
+ $aftDiv.articleFeedbackv5( 'trackClick', linkInfo[ $link.data( 'linkId'
) ].trackId );
$aftDiv.articleFeedbackv5( 'openAsModal', $link );
};
Modified:
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
===================================================================
---
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
2011-12-14 22:00:46 UTC (rev 106250)
+++
trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
2011-12-14 22:06:37 UTC (rev 106251)
@@ -62,6 +62,11 @@
$.articleFeedbackv5.debug = mw.config.get( 'wgArticleFeedbackv5Debug' )
? true : false;
/**
+ * Are we tracking clicks?
+ */
+ $.articleFeedbackv5.clickTracking = false;
+
+ /**
* Have the containers been added?
*/
$.articleFeedbackv5.hasContainers = false;
@@ -398,6 +403,8 @@
$block.find( '.articleFeedbackv5-submit' )
.click( function ( e ) {
e.preventDefault();
+ $.articleFeedbackv5.trackClick(
'option1-submit-' +
+ (
$.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
$.articleFeedbackv5.submitForm();
} );
},
@@ -652,8 +659,9 @@
// Attach the submit
$block.find( '.articleFeedbackv5-submit' )
.click( function ( e ) {
- //alert( 'got to click event' );
e.preventDefault();
+ $.articleFeedbackv5.trackClick(
'option2-submit-' +
+ (
$.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
$.articleFeedbackv5.submitForm();
} );
@@ -980,6 +988,8 @@
$block.find( '.articleFeedbackv5-submit' )
.click( function ( e ) {
e.preventDefault();
+ $.articleFeedbackv5.trackClick(
'option3-submit-' +
+ (
$.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) );
$.articleFeedbackv5.submitForm();
} );
@@ -1118,16 +1128,10 @@
.attr( 'href', mw.config.get(
'wgArticleFeedbackv5LearnToEdit' ) );
// Fill in the edit link
- $block.find( '.articleFeedbackv5-submit' )
- .attr( 'href',
- mw.config.get( 'wgScript' ) +
'?' + $.param( {
- 'title': mw.config.get(
'wgPageName' ),
- 'action': 'edit',
-
'articleFeedbackv5_feedback_id': $.articleFeedbackv5.feedbackId,
-
'articleFeedbackv5_cta_id': $.articleFeedbackv5.ctaId,
-
'articleFeedbackv5_bucket_id': $.articleFeedbackv5.bucketId
- } )
- );
+ var edit_track_id =
$.articleFeedbackv5.buttonName() + '-button-click-' +
+ ( $.articleFeedbackv5.inDialog ?
'overlay' : 'bottom' );
+ $block.find( '.articleFeedbackv5-cta-button' )
+ .attr( 'href',
$.articleFeedbackv5.editUrl( edit_track_id ) );
// Turn the submit into a slick button
$block.find( '.articleFeedbackv5-submit' )
@@ -1898,17 +1902,10 @@
.attr( 'href', mw.msg(
'articlefeedbackv5-cta1-learn-how-url' ) );
// Fill in the link
+ var edit_track_id =
$.articleFeedbackv5.ctaName() + '-button-click-' +
+ ( $.articleFeedbackv5.inDialog ?
'overlay': 'bottom' );
$block.find( '.articleFeedbackv5-cta-button' )
- .attr(
- 'href',
- mw.config.get( 'wgScript' ) +
'?' + $.param( {
- 'title': mw.config.get(
'wgPageName' ),
- 'action': 'edit',
-
'articleFeedbackv5_feedback_id': $.articleFeedbackv5.feedbackId,
-
'articleFeedbackv5_cta_id': $.articleFeedbackv5.ctaId,
-
'articleFeedbackv5_bucket_id': $.articleFeedbackv5.bucketId
- } )
- );
+ .attr( 'href',
$.articleFeedbackv5.editUrl( edit_track_id ) );
return $block;
},
@@ -1970,8 +1967,11 @@
var $block = $(
$.articleFeedbackv5.currentCTA().templates.block );
// Fill in the button link
+ var learn_url = mw.msg(
'articlefeedbackv5-cta1-learn-how-url' );
+ var learn_track_id =
$.articleFeedbackv5.ctaName() + '-button-click-' +
+ ( $.articleFeedbackv5.inDialog ?
'overlay': 'bottom' );
$block.find( '.articleFeedbackv5-cta-button' )
- .attr( 'href', mw.msg(
'articlefeedbackv5-cta1-learn-how-url' ) );
+ .attr( 'href',
$.articleFeedbackv5.trackingUrl( learn_url, learn_track_id ) );
return $block;
},
@@ -2013,6 +2013,8 @@
$.articleFeedbackv5.init = function ( $el, config ) {
$.articleFeedbackv5.$holder = $el;
$.articleFeedbackv5.config = config;
+ // Are we tracking clicks?
+ $.articleFeedbackv5.clickTracking =
$.articleFeedbackv5.checkClickTracking();
// Has the user already submitted ratings for this page at this
revision?
$.articleFeedbackv5.alreadySubmitted = $.cookie(
$.articleFeedbackv5.prefix( 'submitted' ) ) === 'true';
// Are we in debug mode?
@@ -2077,8 +2079,28 @@
};
// }}}
+ // {{{ checkClickTracking
+ /**
+ * Checks whether click tracking is turned on
+ *
+ * Only track users who have been assigned to the tracking group; don't
bucket
+ * at all if we're set to always ignore or always track.
+ */
+ $.articleFeedbackv5.checkClickTracking = function () {
+ var b = mw.config.get( 'wgArticleFeedbackv5Tracking' );
+ if ( b.buckets.ignore == 100 && b.buckets.track == 0 ) {
+ return false;
+ }
+ if ( b.buckets.ignore == 0 && b.buckets.track == 100 ) {
+ return true;
+ }
+ return ( 'track' === mw.user.bucket(
'ext.articleFeedbackv5-tracking', b ) );
+ };
+
// }}}
+
+ // }}}
// {{{ Utility methods
// {{{ prefix
@@ -2206,8 +2228,87 @@
};
// }}}
+ // {{{ bucketName
+ /**
+ * Utility method: Gets the name of the current bucket
+ *
+ * @return string the bucket name
+ */
+ $.articleFeedbackv5.bucketName = function () {
+ return 'option' + $.articleFeedbackv5.bucketId;
+ };
+
// }}}
+ // {{{ ctaName
+
+ /**
+ * Utility method: Gets the name of the current CTA
+ *
+ * @return string the CTA name
+ */
+ $.articleFeedbackv5.ctaName = function () {
+ if ( '0' == $.articleFeedbackv5.ctaId ) {
+ return 'cta-none';
+ } else if ( '1' == $.articleFeedbackv5.ctaId ) {
+ return 'cta-edit';
+ } else if ( '2' == $.articleFeedbackv5.ctaId ) {
+ return 'cta-learn-more';
+ } else {
+ return 'cta-unknown';
+ }
+ };
+
+ // }}}
+ // {{{ trackingUrl
+
+ /**
+ * Creates a URL that tracks a particular click
+ *
+ * @param url string the url so far
+ * @param trackingId string the tracking ID
+ */
+ $.articleFeedbackv5.trackingUrl = function ( url, trackingId ) {
+ if ( $.articleFeedbackv5.clickTracking && $.isFunction(
$.trackActionURL ) ) {
+ return $.trackActionURL( url,
$.articleFeedbackv5.prefix( trackingId ) );
+ } else {
+ return url;
+ }
+ };
+
+ // }}}
+ // {{{ editUrl
+
+ /**
+ * Builds the edit URL, with tracking if appropriate
+ *
+ * @param trackingId string the tracking ID
+ */
+ $.articleFeedbackv5.editUrl = function ( url, trackingId ) {
+ var params = {
+ 'title': mw.config.get( 'wgPageName' ),
+ 'action': 'edit',
+ };
+ if ( $.articleFeedbackv5.bucketId ) {
+ params.articleFeedbackv5_bucket_id =
$.articleFeedbackv5.bucketId;
+ }
+ if ( $.articleFeedbackv5.ctaId ) {
+ params.articleFeedbackv5_cta_id =
$.articleFeedbackv5.ctaId;
+ }
+ if ( $.articleFeedbackv5.feedbackId ) {
+ params.articleFeedbackv5_feedback_id =
$.articleFeedbackv5.feedbackId;
+ }
+ var url = mw.config.get( 'wgScript' ) + '?' + $.param( params );
+ if ( trackingId ) {
+ return $.articleFeedbackv5.trackingUrl( url, trackingId
);
+ } else {
+ return url;
+ }
+ };
+
+ // }}}
+
+ // }}}
// {{{ Process methods
// {{{ load
@@ -2358,6 +2459,14 @@
bucket.afterBuild();
}
+ // Track the event
+ if ( $.articleFeedbackv5.inDialog ) {
+ $.articleFeedbackv5.trackClick(
$.articleFeedbackv5.bucketName() + '-overlay-impression' );
+ } else {
+ // Don't track bottom-of-the-page loads, at least for
now
+ // $.articleFeedbackv5.trackClick(
$.articleFeedbackv5.bucketName() + '-bottom-impression' );
+ }
+
$.articleFeedbackv5.nowShowing = 'form';
};
@@ -2546,6 +2655,10 @@
// Reset the panel dimensions
$.articleFeedbackv5.setDialogDimensions();
+ // Track the event
+ $.articleFeedbackv5.trackClick(
$.articleFeedbackv5.ctaName() + '-impression-' +
+ ( $.articleFeedbackv5.inDialog ? 'overlay' :
'bottom' ) );
+
$.articleFeedbackv5.nowShowing = 'cta';
};
@@ -2795,6 +2908,11 @@
*/
$.articleFeedbackv5.closeAsModal = function () {
if ( $.articleFeedbackv5.inDialog ) {
+ if ( 'form' == $.articleFeedbackv5.nowShowing ) {
+ $.articleFeedbackv5.trackClick(
$.articleFeedbackv5.bucketName() + '-overlay-close' );
+ } else if ('cta' == $.articleFeedbackv5.nowShowing ) {
+ $.articleFeedbackv5.trackClick(
$.articleFeedbackv5.ctaName() + '-overlay-close' );
+ }
$.articleFeedbackv5.setLinkId( '0' );
$.articleFeedbackv5.$dialog.find(
'.articleFeedbackv5-tooltip' ).hide();
$inner = $.articleFeedbackv5.$dialog.find(
'.articleFeedbackv5-ui' ).detach();
@@ -2821,9 +2939,26 @@
};
// }}}
+ // {{{ trackClick
+ /**
+ * Tracks a click
+ *
+ * @param trackingId string the tracking ID
+ */
+ $.articleFeedbackv5.trackClick = function ( trackingId ) {
+ if ( $.articleFeedbackv5.clickTracking && $.isFunction(
$.trackActionWithInfo ) ) {
+ $.trackActionWithInfo(
+ $.articleFeedbackv5.prefix( trackingId ),
+ mw.config.get( 'wgTitle' )
+ );
+ }
+ };
+
// }}}
+ // }}}
+
// }}}
// {{{ articleFeedbackv5 plugin
@@ -2846,7 +2981,8 @@
prefix: { args: 1, ret: true },
addToRemovalQueue: { args: 1, ret: false },
openAsModal: { args: 1, ret: false },
- closeAsModal: { args: 0, ret: true }
+ closeAsModal: { args: 0, ret: true },
+ trackClick: { args: 1, ret: false }
};
if ( opts in public ) {
var r;
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs