Extension:EventLogging

The EventLogging extension facilitates the collection of metrics on how users interact with MediaWiki's interface. The Wikimedia Foundation captures this data and analyses it in aggregate to better understand how readers and editors interact with our site, to identify usability or performance problems, and to provide feedback for features engineers, with the overarching goal of driving improvements to user experience.

Features

 * EventLogging supports client-side logging from JavaScript and server-side logging from PHP.
 * The events are JSON objects defined by JSON schemas that can be edited on a MediaWiki server in a Schema: namespace; the latter feature is generally useful for storing other structured data in wiki pages.
 * The extension includes much back-end code for transporting, parsing and loading these events into SQL tables (automatically generated from the same schemas) and MongoDB collections. The details of these components are specific to Wikimedia Foundation's configuration.

Configuring the schema location
By default, the extension will look for schemas on Meta-Wiki. The relevant default settings are:

To use local schemas, or schemas from the central wiki of your own wikifarm, you need to override these. E.g. to use the  namespace of the local wiki, set (and ensure the user account that will create the schemas is autoconfirmed).

Documentation

 * /Guide to developing and deploying EventLogging schemas, and more
 * /Programming has tips and suggestions for developers writing code to log events
 * /Events
 * /Comparison notes
 * /UserAgentSanitization
 * EventLogging system architecture (Wikitech)

A thorough guide
If you want to log events with EventLogging, read Extension:EventLogging/Guide.

Developer setup
As a developer, you will want to set up and use EventLogging on your development wiki to simulate its use in production.

Sanity checking your setup
Your local development wiki must be running some cache server, such as memcached.

describes the EventLogging configuration variables.

The eventlogging server repository provides a dummy web server in  that responds to EventLogging's requests to its beacon URL, by default on port 8080. See eventlogging/README.md for Python setup instructions. The eventlogging server repository is checked in as a git submodule in the extension at. After cloning the extension, run  to clone the server repository.

So you can set and run export PYTHONPATH=./server && server/bin/eventlogging-devserver in a terminal to see events. The MediaWiki-Vagrant server "appliance" uses port 8080, so you may want to use another port like 8081 for event.gif requests.

To verify your setup, browse to any page of your wiki, and in a JavaScript console enter The last line will generate console warnings in debug mode as null is not a known schema, but eventlogging-devserver should dump the event along with its own warnings.

For server-side events, set  to a local file writable by the PHP/Web server, and in a terminal run tail -f on that file. This will dump any calls to the PHP  function.

Using mediawiki-vagrant
If you develop using mediawiki-vagrant, all of the above is encapsulated in the  role. To enable it, do

vagrant roles enable eventlogging vagrant provision

This will start eventlogging-devserver listening on port 8100. Apache will be configured to proxy events from localhost:8080/event.gif to the eventlogging-devserver. You should be able to see your events in. eventlogging-devserver daemon output can be found in

Tips
Read /Guide to learn about creating and using a proper schema for your event.

Don't use a schema name like "MyFakeTest" during development. Since schemas are referenced by MediaWiki revision ID, development versions won't conflict with production, so you should always use a real name and can point to the production wiki holding schemas during development.

Your code that logs events can fail if EventLogging is not available, or it can have a soft dependency.
 * Sample code for specifying a soft dependency on EventLogging.

How to run tests
There are PHP tests, python tests, and JavaScript tests.

To run Javascript tests, visit Special:JavaScriptTest/qunit on your development wiki. (see: Manual:JavaScript unit testing)

To run PHP tests, we use PHPUnit. Make sure it is installed, see: Manual:PHP unit testing/Installing PHPUnit). Then

To run eventlogging server python tests in vagrant you need to install tox. If you use Windows, may also need to clone it to a directory that is not shared between guest and host (to work around an apparent VirtualBox shared folder issue). E.g.:

> vagrant@mediawiki-vagrant:/vagrant/mediawiki/extensions/EventLogging$ git clone. ~/EventLogging > vagrant@mediawiki-vagrant:/vagrant/mediawiki/extensions/EventLogging$ sudo pip install tox > vagrant@mediawiki-vagrant:/vagrant/mediawiki/extensions/EventLogging$ cd ~/EventLogging > vagrant@mediawiki-vagrant:/vagrant/mediawiki/extensions/EventLogging$ git submodule update --init   # to get server/ checked out

Then, run tox:

> tox

Note that tox tries to run tests for Python 2.7 and Python 3.4. EventLogging runs with Python 2.7 in production. If you want to install Python3 in vagrant please run:

> sudo apt-get install python3

How to run flake8
> vagrant@mediawiki-vagrant:/vagrant/mediawiki/extensions/EventLogging$ tox -e flake8