r111692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111691‎ | r111692 | r111693 >
Date:22:17, 16 February 2012
Author:bsitu
Status:ok
Tags:
Comment:
Standardizing clickTracking event name for article creation workflow by introducing acwbucket & acwsource
Modified paths:
  • /trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.hooks.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationTemplates.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationUtil.php (modified) (history)
  • /trunk/extensions/ArticleCreationWorkflow/modules/ext.articleCreation.user/ext.articleCreation.user.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationUtil.php
@@ -38,12 +38,46 @@
3939
4040 /**
4141 * Generate tracking code prefix for this campaign
42 - * @return string - the prefix text for clickTracking
 42+ * @return string
4343 */
4444 public static function trackingCodePrefix() {
4545 global $wgExtensionCredits;
46 - return 'ext.articlecreationworkflow@' . $wgExtensionCredits['other'][0]['version'] . '-';
 46+ return 'ext.articleCreationWorkflow@' . $wgExtensionCredits['other'][0]['version'] . '-';
4747 }
 48+
 49+ /**
 50+ * Generate a tracking code bucket for this campaign
 51+ * @return string
 52+ */
 53+ public static function trackingBucket() {
 54+ global $wgRequest, $wgUser;
 55+
 56+ if ( $wgUser->isAnon() ) {
 57+ return 'anon';
 58+ } else {
 59+ if ( $wgRequest->getVal( 'fromsignup' ) ) {
 60+ return 'new';
 61+ } else {
 62+ return 'reg';
 63+ }
 64+ }
 65+ }
 66+
 67+ /**
 68+ * Valid tracking bucket
 69+ * @return array
 70+ */
 71+ public static function getValidTrackingBucket() {
 72+ return array( 'anon', 'new', 'reg' );
 73+ }
 74+
 75+ /**
 76+ * Valid tracking source
 77+ * @return array
 78+ */
 79+ public static function getValidTrackingSource() {
 80+ return array( '', 'skip', 'direct' );
 81+ }
4882
4983 /**
5084 * Track the page stats to the special article creation landing page
@@ -52,18 +86,9 @@
5387 * @param $par string - the title for the non-existing article
5488 */
5589 public static function TrackSpecialLandingPage( $request, $user, $par ) {
56 - if ( $user->isAnon() ) {
57 - $event = 'landingpage-anonymous';
58 - } else {
59 - $event = 'landingpage-loggedin';
 90+
 91+ $event = self::trackingBucket() . '-impression';
6092
61 - if ( $request->getBool( 'fromlogin' ) ) {
62 - $event .= '-fromlogin';
63 - } elseif ( $request->getBool( 'fromsignup' ) ) {
64 - $event .= '-fromsignup';
65 - }
66 - }
67 -
6893 self::clickTracking( $event, Title::newFromText( $par ) );
6994 }
7095
@@ -87,14 +112,14 @@
88113 $token = wfGenerateToken();
89114 }
90115
91 - $pageId = $title->getArticleID();
 116+ $revId = $title->getLatestRevID();
92117
93118 $params = new FauxRequest( array(
94119 'action' => 'clicktracking',
95120 'eventid' => self::trackingCodePrefix() . $event,
96121 'token' => $token,
97122 'namespacenumber' => $title->getNamespace(),
98 - 'additional' => $title->getDBkey() . ( $pageId ? '|' . $pageId : '' ),
 123+ 'additional' => $title->getDBkey() . ( $revId ? '|' . $revId : '' ),
99124 ) );
100125 $api = new ApiMain( $params, true );
101126 $api->execute();
Index: trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationTemplates.php
@@ -151,6 +151,8 @@
152152 '{{SCRIPT}}' => $wgScript,
153153 '{{USER}}' => $wgUser,
154154 '{{PAGE}}' => $page,
 155+ '{{BUCKETID}}' => ArticleCreationUtil::trackingBucket(),
 156+ '{{SOURCE}}' => 'direct',
155157 );
156158
157159 $target = strtr( $target, $replacements );
Index: trunk/extensions/ArticleCreationWorkflow/modules/ext.articleCreation.user/ext.articleCreation.user.js
@@ -91,7 +91,7 @@
9292 }
9393
9494 var article = wgPageName.substr( wgPageName.indexOf('/') + 1 );
95 - ac.trackAction( article, $(this).data('ac-button' ) + '-interstitial' );
 95+ ac.trackAction( article, $(this).data('ac-button' ) + '_button_click' );
9696
9797 $( this )
9898 //make it green
@@ -160,6 +160,21 @@
161161 if ( $('.ac-dismiss-interstitial').is(':checked') ) {
162162 ac.disableInterstitial( action );
163163 }
 164+
 165+ var acwsource = '';
 166+ var buttonType = 'button_click';
 167+ if ( action === 'create' ) {
 168+ if ( ac.panel.find('.mw-ac-interstitial').is(':visible') ) {
 169+ buttonType = 'submit';
 170+ if ( $('.ac-dismiss-interstitial').is(':checked') ) {
 171+ acwsource = 'skip';
 172+ buttonType = acwsource + '_' + buttonType;
 173+ }
 174+ } else {
 175+ acwsource = 'direct';
 176+ buttonType = acwsource + '_' + buttonType;
 177+ }
 178+ }
164179
165180 var article = wgPageName.substr( wgPageName.indexOf('/') + 1 );
166181 var urlTemplate = ac.config['action-url'][action];
@@ -167,8 +182,12 @@
168183 urlTemplate = urlTemplate.replace( '{{PAGE}}', encodeURIComponent( article ) );
169184 urlTemplate = urlTemplate.replace( '{{USER}}', encodeURIComponent( wgUserName ) );
170185 urlTemplate = urlTemplate.replace( '{{SCRIPT}}', wgScript );
 186+ if ( action === 'create' ) {
 187+ urlTemplate = urlTemplate.replace( '{{BUCKETID}}', encodeURIComponent( ac.config['acwbucket'] ) );
 188+ urlTemplate = urlTemplate.replace( '{{SOURCE}}', encodeURIComponent( acwsource ) );
 189+ }
171190
172 - ac.trackAction(article, action)
 191+ ac.trackAction(article, action + '_' + buttonType)
173192 .complete( function() {
174193 window.location.href = urlTemplate;
175194 });
@@ -208,7 +227,7 @@
209228 title = title.replace(' ', '_' );
210229
211230 return jQuery.trackActionWithOptions( {
212 - id : ac.config['tracking-code-prefix'] + action,
 231+ id : ac.config['tracking-code-prefix'] + ac.config['acwbucket'] + '-' + action,
213232 namespace : namespaceNumber,
214233 info : title
215234 } );
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.php
@@ -171,9 +171,9 @@
172172
173173 $wgArticleCreationConfig = array(
174174 'action-url' => array(
175 - 'draft' => '{{SCRIPT}}?title=User:{{USER}}/{{PAGE}}&action=edit&fromacw=1',
176 - 'create' => '{{SCRIPT}}?title={{PAGE}}&action=edit&fromacw=1',
177 - 'login' => '{{SCRIPT}}?title=Special:Userlogin&returnto=Special:ArticleCreationLanding/{{PAGE}}&returntoquery=' . urlencode( 'fromlogin=1' ),
 175+ 'draft' => '{{SCRIPT}}?title=User:{{USER}}/{{PAGE}}&action=edit',
 176+ 'create' => '{{SCRIPT}}?title={{PAGE}}&action=edit&acwbucket={{BUCKETID}}&acwsource={{SOURCE}}',
 177+ 'login' => '{{SCRIPT}}?title=Special:Userlogin&returnto=Special:ArticleCreationLanding/{{PAGE}}',
178178 'signup' => '{{SCRIPT}}?title=Special:Userlogin/signup&returnto=Special:ArticleCreationLanding/{{PAGE}}&returntoquery=' . urlencode( 'fromsignup=1' ),
179179 'request' => 'http://google.com/?q={{PAGE}}'
180180 ),
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.hooks.php
@@ -74,6 +74,7 @@
7575 'tracking-turned-on' => ArticleCreationUtil::trackingEnabled(),
7676 'tracking-code-prefix' => ArticleCreationUtil::trackingCodePrefix(),
7777 'variant' => ArticleCreationTemplates::getLandingVariant( $wgTitle ),
 78+ 'acwbucket' => ArticleCreationUtil::trackingBucket(),
7879 );
7980
8081 return true;
@@ -113,10 +114,10 @@
114115 * @return bool
115116 */
116117 public static function pushTrackingFieldsToEdit( $editPage, $output ) {
117 - $fromacw = $output->getRequest()->getVal( 'fromacw' );
118 -
119 - if ( $fromacw ) {
120 - $editPage->editFormTextAfterContent .= Html::hidden( 'fromacw', '1' );
 118+ $res = self::validateTrackingBucketSource();
 119+ if ( $res ) {
 120+ $editPage->editFormTextAfterContent .= Html::hidden( 'acwbucket', $res['bucket'] );
 121+ $editPage->editFormTextAfterContent .= Html::hidden( 'acwsource', $res['source'] );
121122 }
122123
123124 return true;
@@ -124,7 +125,6 @@
125126
126127 /**
127128 * Tracks successful save from article creation workflow
128 - *
129129 * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete
130130 * @param $article WikiPage
131131 * @param $user
@@ -143,10 +143,13 @@
144144 $summary, $minoredit, $watchthis, $sectionanchor, &$flags,
145145 $revision, &$status, $baseRevId /*, &$redirect */ ) { // $redirect not passed in 1.18wmf1
146146
147 - global $wgRequest;
 147+ $res = self::validateTrackingBucketSource();
148148
149 - if ( $wgRequest->getVal( 'fromacw' ) ) {
150 - ArticleCreationUtil::clickTracking( 'created-from-article-creation', $article->getTitle() );
 149+ if ( $res ) {
 150+ if ( $res['source'] ) {
 151+ $res['source'] .= '_';
 152+ }
 153+ ArticleCreationUtil::clickTracking( $res['bucket'] . '-' . 'create_' . $res['source'] . 'edit_success', $article->getTitle() );
151154 }
152155
153156 return true;
@@ -154,18 +157,37 @@
155158
156159 /**
157160 * Tracks save attempt from article creation workflow
158 - *
159161 * @see http://www.mediawiki.org/wiki/Manual:Hooks/EditPage::attemptSave
160162 * @param $editpage EditPage
161163 * @return bool
162164 */
163165 public static function trackEditAttempt( $editpage ) {
164 - global $wgRequest;
165 -
166 - if ( $wgRequest->getVal( 'fromacw' ) ) {
167 - ArticleCreationUtil::clickTracking( 'attempt-save-from-article-creation', $editpage->getArticle()->getTitle() );
 166+ $res = self::validateTrackingBucketSource();
 167+
 168+ if ( $res ) {
 169+ if ( $res['source'] ) {
 170+ $res['source'] .= '_';
 171+ }
 172+ ArticleCreationUtil::clickTracking( $res['bucket'] . '-' . 'create_' . $res['source'] . 'edit_attempt', $editpage->getArticle()->getTitle() );
168173 }
169174
170175 return true;
171176 }
 177+
 178+ /**
 179+ * Validate the tracking bucket and source
 180+ * @return array|bool
 181+ */
 182+ private static function validateTrackingBucketSource() {
 183+ global $wgRequest;
 184+ $bucket = $wgRequest->getVal( 'acwbucket' );
 185+ $source = $wgRequest->getVal( 'acwsource' );
 186+
 187+ if ( in_array( $bucket, ArticleCreationUtil::getValidTrackingBucket(), true ) &&
 188+ in_array( $source, ArticleCreationUtil::getValidTrackingSource(), true ) ) {
 189+ return array( 'bucket' => $bucket, 'source' => $source );
 190+ } else {
 191+ return false;
 192+ }
 193+ }
172194 }

Sign-offs

UserFlagDate
Nikerabbitinspected07:14, 17 February 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r111693followup to -r111692 - wrap long linebsitu22:21, 16 February 2012

Status & tagging log