Extension:E3 Experiments/Architecture

The extension combines
 * a somewhat generic harness for making experimental changes to pages
 * specific PHP and JavaScript code for particular experiments
 * and CSS and HTML resources appropriate to the experiment if it makes changes to pages.

So the extension code only makes sense within an end-to-end explanation of a particular experiment.

E3Experiment for post-edit feedback
The [Editor engagement experiments/Post-edit feedback]] experiment puts up one of two messages on successful edit for a very limited set of users.

Because a MediaWiki edit redirects to a normal page URL, the extension registers a hook for ArticleUpdateBeforeRedirect (in Experiments.hooks.php) that appends ?pe=1 to the URL if it is the result of an edit.

Most of the rest of the code is JavaScript running in the browser. The extension uses the MW resource loader to load everything in lib/*.js onBeforePageDisplay, and supplies the user's edit count and registration date as JS mw.config variables wgEditCount and wgRegistration.

Eligibility

 * Tracking is expensive, an overriding goal is to run it as little as possible

JavaScript code on client computes experiment start and end times, eligibility duration, whether the page is appropriate
 * test: use latest dashboard (see ../Testing, it reports times. ? See if bucketing occurs inside/outside the window.
 * Perhaps server-side onBeforePageDisplay hook code could skip loading the JS code if !pageIsAppropriate

If the user is in the experiment, it calls mw.experiments.murmur3 to turn the wgUserName into a random-ish number, assigns to control/experimental_1/experimental_2 bucket from this, then calls ClickTracking jQuery code to remember which user the bucket in the userbuckets cookie. It also calls $.trackActionWithOptions (more ClickTracking code) to track this as PEF1BUCKETASSIGN may turn off this event

Extension:ClickTracking
mw:Extension:ClickTracking is used by various extensions besides E3, like moodbar, article feedback tracking.


 * Provides user bucketing JS functions on jQuery $ that add information to userbuckets cookie (in ext.UserBuckets.js). UserBuckets can also set up a campaign if you provide it enough info in mw.activeCampaigns, but unlike say Account Creation, E3 Experiments doesn't do this.
 * Provides action tracking JS functions on jQuery $ such as $.trackAction('SOME INFO') (in jquery.clickTracking.js). The action tracking functions
 * check for a clicktrackingDebug cookie and set it if ?clicktrackingDebug is in the query string
 * if it doesn't already exist, set a clicktracking-session cookie
 * post using XMLHttpRequest a clicktracking action to api.php (This is hella expensive, it can't be cached!) unless clicktrackingDebug

ClickTracking does lots of other things like rewrite left-side navbar to track clicks, provides a function to track a URL (by requesting it through api.php which then redirects to the requested URL &mdash; expensive), hook into EditPage::showEditForm:fields form fields to add clicktrackingsession and event hidden form fields, etc. Kill this code if not used any more

API calls
ClickTracking's API module always (?) logs additional information. Its ClickTrackingHooks:trackEvent also logs: The latter is provided by another extension,
 * whether the user isLoggedIn
 * the user's edit counts over three time periods, etc.

Here's a sample line from a click action on the en:Wikipedia:Community Portal page in the m:Research:Community portal redesign experiment: communityPortalClick	20120726225623	1	sUnbevNTg2FHRxMeqpAopbNQlH08dwS2w	4	722	21	21	5	https://en.wikipedia.org/wiki/India@/wiki/Main_Page
 * if ($wgClickTrackingDatabase) it writes the data to the click_tracking database table, and writes the values of all buckets in the userbuckets cookie to the click_tracking_user_properties database table.
 * if ($wgClickTrackingLog) it calls wfErrorLog to log most of the information, but not buckets:
 * event name
 * timestamp
 * whether user is logged in
 * a session id
 * the namespace of the page
 * the user contributions and user contributions over three time periods
 * additional information
 * event name is communityPortalClick
 * timestamp is July 26 2012
 * this user is logged in
 * the session ID is anonymized
 * the numerical namespace of the page is 4 (the "Wikipedia:" namespace).
 * the user contributions are 722, contributions over timespans 1-2-3 are 21-21-5
 * the additional information in this experiment is the referring page followed by '@' followed the destination of the click, thus the India Wikipedia page followed by the home page.

Log processing
Squid logging explains how WMF processes logs, including the log output from ClickTracking. This step prepends the wiki from which the log came, e.g. enwiki, to the log message that ClickTracking generates.

Wikimedia researchers process these logs to explore and test hypotheses about the experiments.