Extension:EventLogging/Programming


 * ''See ../Data model (singular) for notes in storage in Redis

When code logs an event, it must reference a data model:

Here the data model is openTask.


 * 1) The data model is a JSON structure that is a JSON schema for the fields in the event &mdash; their names, their types, whether required or not.
 * 2) The PHP code in core or an extension has to explicitly request a particular data model.
 * 3) MediaWiki ResourceLoader gets the

How it works

 * Meet a researcher, determine what you're going to log, name the fields to log, reusing well-known field names.


 * Create a JSON structure representing this data model in the Schema: namespace on meta.
 * Sample: m:Schema:OpenTask


 * Use the schema's talk page to link to experiments using this, discuss niceties, etc.
 * always document what code in what circumstances logs the event.

Built-in data fields
The JavaScript mw.eventLog.logEvent logs
 * _db
 * the wiki database ("enwiki", etc.)


 * _id
 * the modelName that is logging (in this example, "openTask")

The server-side logging that picks up the events logs a server timestamp UTC.

Common data fields

 * action
 * per-data model, such as 'impression', 'click', 'submit', 'accept' (a task).


 * version
 * a number representing changes to the condition, e.g. bump it when deploying a different version of the code

Standard data fields

 * isAnon (opposite of authenticated)
 * user has not logged-in. In JavaScript, mw.user.isAnon


 * editCount
 * how many edits a logged-in user has made. In JavaScript, request the config value wgEditCount.


 * token
 * a unique random persistent token per browser, stored in the (badly misnamed) mediaWiki.user.id cookie. In JavaScript, calling mw.user.id will generate this.

 ?? maybe have an additional session token


 * article
 * the title of the page the user is editing. In JavaScript, request the config value wgTitle.
 * note this doesn't work for Special pages and other namespaces.

Available data models

 * openTask
 * in Schema


 * account_create
 * event logged on server


 * article edit/save
 * we used to log this on the server...


 * mobile
 * Event_logging/Mobile

"article": { "type": "string" },	"task": { "type": "string" },	"referrer": { "type": "string" },	"token": { "type": "string", "required": true },	"editcount": { "type": "number" }

JSON schema validation
The data model JSON format is a JSON schema, an evolving standard for specifying a data format. As of December 2012 the schemas on meta aren't validated as schemas.

Error handling
If a client attempts invalid log, EventLogging detects it's invalid and flags it, but logs it anyway.