Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js |
— | — | @@ -62,6 +62,11 @@ |
63 | 63 | $.articleFeedbackv5.debug = mw.config.get( 'wgArticleFeedbackv5Debug' ) ? true : false; |
64 | 64 | |
65 | 65 | /** |
| 66 | + * Are we tracking clicks? |
| 67 | + */ |
| 68 | + $.articleFeedbackv5.clickTracking = false; |
| 69 | + |
| 70 | + /** |
66 | 71 | * Have the containers been added? |
67 | 72 | */ |
68 | 73 | $.articleFeedbackv5.hasContainers = false; |
— | — | @@ -398,6 +403,8 @@ |
399 | 404 | $block.find( '.articleFeedbackv5-submit' ) |
400 | 405 | .click( function ( e ) { |
401 | 406 | e.preventDefault(); |
| 407 | + $.articleFeedbackv5.trackClick( 'option1-submit-' + |
| 408 | + ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) ); |
402 | 409 | $.articleFeedbackv5.submitForm(); |
403 | 410 | } ); |
404 | 411 | }, |
— | — | @@ -652,8 +659,9 @@ |
653 | 660 | // Attach the submit |
654 | 661 | $block.find( '.articleFeedbackv5-submit' ) |
655 | 662 | .click( function ( e ) { |
656 | | - //alert( 'got to click event' ); |
657 | 663 | e.preventDefault(); |
| 664 | + $.articleFeedbackv5.trackClick( 'option2-submit-' + |
| 665 | + ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) ); |
658 | 666 | $.articleFeedbackv5.submitForm(); |
659 | 667 | } ); |
660 | 668 | |
— | — | @@ -980,6 +988,8 @@ |
981 | 989 | $block.find( '.articleFeedbackv5-submit' ) |
982 | 990 | .click( function ( e ) { |
983 | 991 | e.preventDefault(); |
| 992 | + $.articleFeedbackv5.trackClick( 'option3-submit-' + |
| 993 | + ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) ); |
984 | 994 | $.articleFeedbackv5.submitForm(); |
985 | 995 | } ); |
986 | 996 | |
— | — | @@ -1118,16 +1128,10 @@ |
1119 | 1129 | .attr( 'href', mw.config.get( 'wgArticleFeedbackv5LearnToEdit' ) ); |
1120 | 1130 | |
1121 | 1131 | // 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 ) ); |
1132 | 1136 | |
1133 | 1137 | // Turn the submit into a slick button |
1134 | 1138 | $block.find( '.articleFeedbackv5-submit' ) |
— | — | @@ -1898,17 +1902,10 @@ |
1899 | 1903 | .attr( 'href', mw.msg( 'articlefeedbackv5-cta1-learn-how-url' ) ); |
1900 | 1904 | |
1901 | 1905 | // Fill in the link |
| 1906 | + var edit_track_id = $.articleFeedbackv5.ctaName() + '-button-click-' + |
| 1907 | + ( $.articleFeedbackv5.inDialog ? 'overlay': 'bottom' ); |
1902 | 1908 | $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 ) ); |
1913 | 1910 | |
1914 | 1911 | return $block; |
1915 | 1912 | }, |
— | — | @@ -1970,8 +1967,11 @@ |
1971 | 1968 | var $block = $( $.articleFeedbackv5.currentCTA().templates.block ); |
1972 | 1969 | |
1973 | 1970 | // 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' ); |
1974 | 1974 | $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 ) ); |
1976 | 1976 | |
1977 | 1977 | return $block; |
1978 | 1978 | }, |
— | — | @@ -2013,6 +2013,8 @@ |
2014 | 2014 | $.articleFeedbackv5.init = function ( $el, config ) { |
2015 | 2015 | $.articleFeedbackv5.$holder = $el; |
2016 | 2016 | $.articleFeedbackv5.config = config; |
| 2017 | + // Are we tracking clicks? |
| 2018 | + $.articleFeedbackv5.clickTracking = $.articleFeedbackv5.checkClickTracking(); |
2017 | 2019 | // Has the user already submitted ratings for this page at this revision? |
2018 | 2020 | $.articleFeedbackv5.alreadySubmitted = $.cookie( $.articleFeedbackv5.prefix( 'submitted' ) ) === 'true'; |
2019 | 2021 | // Are we in debug mode? |
— | — | @@ -2077,8 +2079,28 @@ |
2078 | 2080 | }; |
2079 | 2081 | |
2080 | 2082 | // }}} |
| 2083 | + // {{{ checkClickTracking |
2081 | 2084 | |
| 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 | + |
2082 | 2102 | // }}} |
| 2103 | + |
| 2104 | + // }}} |
2083 | 2105 | // {{{ Utility methods |
2084 | 2106 | |
2085 | 2107 | // {{{ prefix |
— | — | @@ -2206,8 +2228,87 @@ |
2207 | 2229 | }; |
2208 | 2230 | |
2209 | 2231 | // }}} |
| 2232 | + // {{{ bucketName |
2210 | 2233 | |
| 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 | + |
2211 | 2243 | // }}} |
| 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 | + // }}} |
2212 | 2313 | // {{{ Process methods |
2213 | 2314 | |
2214 | 2315 | // {{{ load |
— | — | @@ -2358,6 +2459,14 @@ |
2359 | 2460 | bucket.afterBuild(); |
2360 | 2461 | } |
2361 | 2462 | |
| 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 | + |
2362 | 2471 | $.articleFeedbackv5.nowShowing = 'form'; |
2363 | 2472 | }; |
2364 | 2473 | |
— | — | @@ -2546,6 +2655,10 @@ |
2547 | 2656 | // Reset the panel dimensions |
2548 | 2657 | $.articleFeedbackv5.setDialogDimensions(); |
2549 | 2658 | |
| 2659 | + // Track the event |
| 2660 | + $.articleFeedbackv5.trackClick( $.articleFeedbackv5.ctaName() + '-impression-' + |
| 2661 | + ( $.articleFeedbackv5.inDialog ? 'overlay' : 'bottom' ) ); |
| 2662 | + |
2550 | 2663 | $.articleFeedbackv5.nowShowing = 'cta'; |
2551 | 2664 | }; |
2552 | 2665 | |
— | — | @@ -2795,6 +2908,11 @@ |
2796 | 2909 | */ |
2797 | 2910 | $.articleFeedbackv5.closeAsModal = function () { |
2798 | 2911 | 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 | + } |
2799 | 2917 | $.articleFeedbackv5.setLinkId( '0' ); |
2800 | 2918 | $.articleFeedbackv5.$dialog.find( '.articleFeedbackv5-tooltip' ).hide(); |
2801 | 2919 | $inner = $.articleFeedbackv5.$dialog.find( '.articleFeedbackv5-ui' ).detach(); |
— | — | @@ -2821,9 +2939,26 @@ |
2822 | 2940 | }; |
2823 | 2941 | |
2824 | 2942 | // }}} |
| 2943 | + // {{{ trackClick |
2825 | 2944 | |
| 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 | + |
2826 | 2959 | // }}} |
2827 | 2960 | |
| 2961 | + // }}} |
| 2962 | + |
2828 | 2963 | // }}} |
2829 | 2964 | // {{{ articleFeedbackv5 plugin |
2830 | 2965 | |
— | — | @@ -2846,7 +2981,8 @@ |
2847 | 2982 | prefix: { args: 1, ret: true }, |
2848 | 2983 | addToRemovalQueue: { args: 1, ret: false }, |
2849 | 2984 | openAsModal: { args: 1, ret: false }, |
2850 | | - closeAsModal: { args: 0, ret: true } |
| 2985 | + closeAsModal: { args: 0, ret: true }, |
| 2986 | + trackClick: { args: 1, ret: false } |
2851 | 2987 | }; |
2852 | 2988 | if ( opts in public ) { |
2853 | 2989 | var r; |
Index: trunk/extensions/ArticleFeedbackv5/modules/ext.articleFeedbackv5/ext.articleFeedbackv5.js |
— | — | @@ -18,39 +18,17 @@ |
19 | 19 | |
20 | 20 | /* Setup for feedback links */ |
21 | 21 | |
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 | | - |
35 | 22 | // Info about each of the links |
36 | 23 | 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' } |
46 | 28 | }; |
47 | 29 | |
48 | 30 | // Click event |
49 | 31 | 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 ); |
55 | 33 | $aftDiv.articleFeedbackv5( 'openAsModal', $link ); |
56 | 34 | }; |
57 | 35 | |
Index: trunk/extensions/ArticleFeedbackv5/ArticleFeedbackv5.php |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | 'tracked' => false, |
84 | 84 | ); |
85 | 85 | |
86 | | -// Bucket settings for click tracking on feedback links |
| 86 | +// Bucket settings for click tracking across the plugin |
87 | 87 | $wgArticleFeedbackv5Tracking = array( |
88 | 88 | // Not all users need to be tracked, but we do want to track some users over time - these |
89 | 89 | // buckets are used when deciding to track someone or not, placing them in one of two buckets: |
— | — | @@ -91,8 +91,8 @@ |
92 | 92 | // this number to ensure the new odds are applied to everyone, not just people who have yet to |
93 | 93 | // be placed in a bucket. |
94 | 94 | 'buckets' => array( |
95 | | - 'ignore' => 100, |
96 | | - 'track' => 0, |
| 95 | + 'ignore' => 0, |
| 96 | + 'track' => 100, |
97 | 97 | ), |
98 | 98 | // This version number is added to all tracking event names, so that changes in the software |
99 | 99 | // don't corrupt the data being collected. Bump this when you want to start a new "experiment". |