Extension:EventLogging/Programming


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

To do any event logging, you must reference a data model

Here the data model is openTask. 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.

PHP code that implements core or an extension has to explicitly request a particular data model.

How it works

 * Meet a researcher, name the fields to log, reuse well-known 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.

"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.