Index: trunk/extensions/ClickTracking/ClickTracking.hooks.php |
— | — | @@ -91,6 +91,26 @@ |
92 | 92 | return true; |
93 | 93 | } |
94 | 94 | |
| 95 | + |
| 96 | + //adds a bucket-testing campaign to the active campaigns |
| 97 | + public static function addCampaign($localBasePath, $remoteExtPath, $name ){ |
| 98 | + global $wgResourceModules; |
| 99 | + |
| 100 | + $cusResourceTemplate = array( |
| 101 | + 'localBasePath' => $localBasePath, |
| 102 | + 'remoteExtPath' => $remoteExtPath, |
| 103 | + ); |
| 104 | + $wgResourceModules["ext.UserBuckets.$name"] = array( |
| 105 | + 'scripts' => "$name.js", |
| 106 | + 'dependencies' => 'jquery.clickTracking', |
| 107 | + ) + $cusResourceTemplate; |
| 108 | + $wgResourceModules['ext.UserBuckets']['dependencies'] = array_merge( |
| 109 | + ( array ) $wgResourceModules['ext.UserBuckets']['dependencies'], |
| 110 | + array("ext.UserBuckets.$name")); |
| 111 | + } |
| 112 | + |
| 113 | + |
| 114 | + |
95 | 115 | /** |
96 | 116 | * Get event ID from name |
97 | 117 | * |
— | — | @@ -188,10 +208,13 @@ |
189 | 209 | $db_status_buckets = true; |
190 | 210 | $db_status = $dbw->insert( 'click_tracking', $data, __METHOD__ ); |
191 | 211 | $dbw->commit(); |
| 212 | + |
| 213 | + |
192 | 214 | |
193 | 215 | |
194 | 216 | if( $recordBucketInfo && $db_status ){ |
195 | 217 | $buckets = self::unpackBucketInfo(); |
| 218 | + |
196 | 219 | if( $buckets ){ |
197 | 220 | foreach( $buckets as $bucketName => $bucketValue ){ |
198 | 221 | $db_current_bucket_insert = $dbw->insert( 'click_tracking_user_properties', |
Index: trunk/extensions/ClickTracking/modules/ext.UserBuckets.js |
— | — | @@ -1,16 +1,41 @@ |
2 | 2 | |
| 3 | +var JSON; |
| 4 | +if (!JSON) { |
| 5 | + JSON = {}; |
3 | 6 | |
4 | | -if( !JSON || !JSON.stringify ){ |
5 | | - //include OpenSource JSON stringify from json.org |
| 7 | + if(!JSON.stringify){ |
| 8 | + /* Very limited JSON encoder */ |
| 9 | + JSON.stringify = function( js_obj ) { |
| 10 | + var returnstr = "{ "; |
| 11 | + |
| 12 | + // trailing commas and json don't mix |
| 13 | + var propertynum = 0; |
| 14 | + for ( property in js_obj ) { |
| 15 | + if ( propertynum > 0 ) { |
| 16 | + returnstr += ", "; |
| 17 | + } |
| 18 | + returnstr += "\"" + property + "\"" + " : "; |
| 19 | + if ( typeof js_obj[property] == 'object' ) { |
| 20 | + returnstr += JSON.stringify( js_obj[property] ); |
| 21 | + } else { |
| 22 | + returnstr += "\"" + js_obj[property] + "\" "; |
| 23 | + } |
| 24 | + propertynum++; |
| 25 | + } |
| 26 | + |
| 27 | + returnstr += " }"; |
| 28 | + return returnstr; |
| 29 | + }; |
| 30 | + } |
6 | 31 | } |
7 | 32 | |
8 | 33 | ( function( $ ) { |
9 | 34 | //lazy-load |
10 | 35 | $.getBuckets = function (force){ |
11 | | - if (typeof($.userBuckets) == 'undefined' || force ){ |
12 | | - $.userBuckets = $.parseJSON( $.cookie('userbuckets') ); |
| 36 | + if (typeof($j.userBuckets) == 'undefined' || force ){ |
| 37 | + $j.userBuckets = $.parseJSON( $.cookie('userbuckets') ); |
13 | 38 | } |
14 | | - return $.userBuckets; |
| 39 | + return $j.userBuckets; |
15 | 40 | }; |
16 | 41 | |
17 | 42 | $.setBucket = function ( bucketName, bucketValue, bucketVersion ){ |
Index: trunk/extensions/ClickTracking/ClickTracking.php |
— | — | @@ -89,13 +89,9 @@ |
90 | 90 | ) + $ctResourceTemplate; |
91 | 91 | $wgResourceModules['ext.UserBuckets'] = array( |
92 | 92 | 'scripts' => 'ext.UserBuckets.js', |
93 | | - 'dependencies' => array('jquery.clickTracking', 'jquery.cookie', /*'ext.UserBuckets.sampleCampaign'*/), |
| 93 | + 'dependencies' => array('jquery.clickTracking', 'jquery.cookie'), |
94 | 94 | ) + $ctResourceTemplate; |
95 | 95 | |
96 | | -//uncomment sample campaign below and sampleCampaign dependency to set up a sample campaign |
97 | | -/* |
98 | | -$wgResourceModules['ext.UserBuckets.sampleCampaign'] = array( |
99 | | - 'scripts' => 'sampleCampaign.js', |
100 | | - 'dependencies' => 'jquery.clickTracking', |
101 | | -) + $ctResourceTemplate; |
102 | | -*/ |
| 96 | +//uncomment for sample campaign |
| 97 | +//ClickTrackingHooks::addCampaign($dir. 'modules', 'ClickTracking/modules', 'sampleCampaign' ); |
| 98 | + |