Index: trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationUtil.php |
— | — | @@ -38,12 +38,46 @@ |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Generate tracking code prefix for this campaign |
42 | | - * @return string - the prefix text for clickTracking |
| 42 | + * @return string |
43 | 43 | */ |
44 | 44 | public static function trackingCodePrefix() { |
45 | 45 | global $wgExtensionCredits; |
46 | | - return 'ext.articlecreationworkflow@' . $wgExtensionCredits['other'][0]['version'] . '-'; |
| 46 | + return 'ext.articleCreationWorkflow@' . $wgExtensionCredits['other'][0]['version'] . '-'; |
47 | 47 | } |
| 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 | + } |
48 | 82 | |
49 | 83 | /** |
50 | 84 | * Track the page stats to the special article creation landing page |
— | — | @@ -52,18 +86,9 @@ |
53 | 87 | * @param $par string - the title for the non-existing article |
54 | 88 | */ |
55 | 89 | 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'; |
60 | 92 | |
61 | | - if ( $request->getBool( 'fromlogin' ) ) { |
62 | | - $event .= '-fromlogin'; |
63 | | - } elseif ( $request->getBool( 'fromsignup' ) ) { |
64 | | - $event .= '-fromsignup'; |
65 | | - } |
66 | | - } |
67 | | - |
68 | 93 | self::clickTracking( $event, Title::newFromText( $par ) ); |
69 | 94 | } |
70 | 95 | |
— | — | @@ -87,14 +112,14 @@ |
88 | 113 | $token = wfGenerateToken(); |
89 | 114 | } |
90 | 115 | |
91 | | - $pageId = $title->getArticleID(); |
| 116 | + $revId = $title->getLatestRevID(); |
92 | 117 | |
93 | 118 | $params = new FauxRequest( array( |
94 | 119 | 'action' => 'clicktracking', |
95 | 120 | 'eventid' => self::trackingCodePrefix() . $event, |
96 | 121 | 'token' => $token, |
97 | 122 | 'namespacenumber' => $title->getNamespace(), |
98 | | - 'additional' => $title->getDBkey() . ( $pageId ? '|' . $pageId : '' ), |
| 123 | + 'additional' => $title->getDBkey() . ( $revId ? '|' . $revId : '' ), |
99 | 124 | ) ); |
100 | 125 | $api = new ApiMain( $params, true ); |
101 | 126 | $api->execute(); |
Index: trunk/extensions/ArticleCreationWorkflow/includes/ArticleCreationTemplates.php |
— | — | @@ -151,6 +151,8 @@ |
152 | 152 | '{{SCRIPT}}' => $wgScript, |
153 | 153 | '{{USER}}' => $wgUser, |
154 | 154 | '{{PAGE}}' => $page, |
| 155 | + '{{BUCKETID}}' => ArticleCreationUtil::trackingBucket(), |
| 156 | + '{{SOURCE}}' => 'direct', |
155 | 157 | ); |
156 | 158 | |
157 | 159 | $target = strtr( $target, $replacements ); |
Index: trunk/extensions/ArticleCreationWorkflow/modules/ext.articleCreation.user/ext.articleCreation.user.js |
— | — | @@ -91,7 +91,7 @@ |
92 | 92 | } |
93 | 93 | |
94 | 94 | 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' ); |
96 | 96 | |
97 | 97 | $( this ) |
98 | 98 | //make it green |
— | — | @@ -160,6 +160,21 @@ |
161 | 161 | if ( $('.ac-dismiss-interstitial').is(':checked') ) { |
162 | 162 | ac.disableInterstitial( action ); |
163 | 163 | } |
| 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 | + } |
164 | 179 | |
165 | 180 | var article = wgPageName.substr( wgPageName.indexOf('/') + 1 ); |
166 | 181 | var urlTemplate = ac.config['action-url'][action]; |
— | — | @@ -167,8 +182,12 @@ |
168 | 183 | urlTemplate = urlTemplate.replace( '{{PAGE}}', encodeURIComponent( article ) ); |
169 | 184 | urlTemplate = urlTemplate.replace( '{{USER}}', encodeURIComponent( wgUserName ) ); |
170 | 185 | 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 | + } |
171 | 190 | |
172 | | - ac.trackAction(article, action) |
| 191 | + ac.trackAction(article, action + '_' + buttonType) |
173 | 192 | .complete( function() { |
174 | 193 | window.location.href = urlTemplate; |
175 | 194 | }); |
— | — | @@ -208,7 +227,7 @@ |
209 | 228 | title = title.replace(' ', '_' ); |
210 | 229 | |
211 | 230 | return jQuery.trackActionWithOptions( { |
212 | | - id : ac.config['tracking-code-prefix'] + action, |
| 231 | + id : ac.config['tracking-code-prefix'] + ac.config['acwbucket'] + '-' + action, |
213 | 232 | namespace : namespaceNumber, |
214 | 233 | info : title |
215 | 234 | } ); |
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.php |
— | — | @@ -171,9 +171,9 @@ |
172 | 172 | |
173 | 173 | $wgArticleCreationConfig = array( |
174 | 174 | '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}}', |
178 | 178 | 'signup' => '{{SCRIPT}}?title=Special:Userlogin/signup&returnto=Special:ArticleCreationLanding/{{PAGE}}&returntoquery=' . urlencode( 'fromsignup=1' ), |
179 | 179 | 'request' => 'http://google.com/?q={{PAGE}}' |
180 | 180 | ), |
Index: trunk/extensions/ArticleCreationWorkflow/ArticleCreationWorkflow.hooks.php |
— | — | @@ -74,6 +74,7 @@ |
75 | 75 | 'tracking-turned-on' => ArticleCreationUtil::trackingEnabled(), |
76 | 76 | 'tracking-code-prefix' => ArticleCreationUtil::trackingCodePrefix(), |
77 | 77 | 'variant' => ArticleCreationTemplates::getLandingVariant( $wgTitle ), |
| 78 | + 'acwbucket' => ArticleCreationUtil::trackingBucket(), |
78 | 79 | ); |
79 | 80 | |
80 | 81 | return true; |
— | — | @@ -113,10 +114,10 @@ |
114 | 115 | * @return bool |
115 | 116 | */ |
116 | 117 | 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'] ); |
121 | 122 | } |
122 | 123 | |
123 | 124 | return true; |
— | — | @@ -124,7 +125,6 @@ |
125 | 126 | |
126 | 127 | /** |
127 | 128 | * Tracks successful save from article creation workflow |
128 | | - * |
129 | 129 | * @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete |
130 | 130 | * @param $article WikiPage |
131 | 131 | * @param $user |
— | — | @@ -143,10 +143,13 @@ |
144 | 144 | $summary, $minoredit, $watchthis, $sectionanchor, &$flags, |
145 | 145 | $revision, &$status, $baseRevId /*, &$redirect */ ) { // $redirect not passed in 1.18wmf1 |
146 | 146 | |
147 | | - global $wgRequest; |
| 147 | + $res = self::validateTrackingBucketSource(); |
148 | 148 | |
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() ); |
151 | 154 | } |
152 | 155 | |
153 | 156 | return true; |
— | — | @@ -154,18 +157,37 @@ |
155 | 158 | |
156 | 159 | /** |
157 | 160 | * Tracks save attempt from article creation workflow |
158 | | - * |
159 | 161 | * @see http://www.mediawiki.org/wiki/Manual:Hooks/EditPage::attemptSave |
160 | 162 | * @param $editpage EditPage |
161 | 163 | * @return bool |
162 | 164 | */ |
163 | 165 | 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() ); |
168 | 173 | } |
169 | 174 | |
170 | 175 | return true; |
171 | 176 | } |
| 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 | + } |
172 | 194 | } |