Extension:EventLogging/Programming


 * See ../Guide for a comprehensive introduction to EventLogging, developing and deploying EventLogging schemas, and more.

How it works
After you have created a schema, you must add an entry to $wgEventStreams stream configuration, and also to $wgEventLoggingStreamNames. $wgEventStreams is where your event stream is declared, and it specifies which schema the events in the stream have. $wgEventLoggingStreamNames registers the stream for use with the EventLogging extension. See https://wikitech.wikimedia.org/wiki/Event_Platform/Instrumentation_How_To for more in depth instructions.

Good starting code

 * The WikimediaEvents extension has working code to log server-side events in PHP in.

Client-side logging

 * require your schema wherever you need to log events (it will pull in the  module which contains the   object).
 * See for API documentation.

Debugging
If code attempts to log an invalid event, EventLogging logs it anyway. If you want to enable informational validation (does not affect logging) see: Extension:EventLogging/Guide. If the logged event has a revision of -1, it's possible you haven't registered your Schema correctly.

Monitoring events

 * Client-side event logging works by sending POST HTTP request to  with the JSON events in the POST body. To see the log events you can
 * watch for this request in your browser's network console,
 * look for it in your web server's access logs, or
 * run the toy web server  in the EventLogging extension which pretty-prints the query string.


 * An alternative to the above is to enable the more user-friendly debugging UI introduced in, which will show a popup notice for each event and also log them to the console. Currently, the debugging UI is shipped to all users but is enabled via a hidden user preference, which can only be set by pasting the following into your browser's JavaScript console:
 * You can use  instead of   in the above snippet to enable console logs without the popups. Use the same snippets with   instead of   to disable.
 * To monitor events after processing, you can append an  callback after a   call, for example:

Logging clicks on links
Often you want to log clicks on links. If these take the user away from the current page, there's a chance that the browser will move to the new page before the request for the beacon image makes it onto the network, and the browser will drop the request. The E3 team experimented with using deferred promises to deal with this, but that introduced known and unknown unknowns. is related to this issue.

There are significant performance concerns regarding logging before showing the next page and our recommendation is not to do that until the new beacon API becomes available. Details on performance issues can be found here: https://bugzilla.wikimedia.org/show_bug.cgi?id=52287