mw.eventLog

Client-side EventLogging API, including pub/sub subscriber functionality.

The main API is mw.eventLog.logEvent. This is set up as a listener for event-namespace topics in mw.track. Sampling utility methods are available in two flavors. Other methods represent internal functionality, exposed only to ease debugging code and writing tests.

Methods

enqueue(callback)static #

Add a pending callback to be flushed at a later time by the background queue.

Parameters:

Name Type Description
callback function

to enqueue and run when the queue is processed

Source:

Returns:

undefined

Add a pending callback to be flushed at a later time by the background queue.

getUserEditCountBucket(editCount) → {string|null}static #

Provide the user's edit count as a low-granularity bucket name.

Parameters:

Name Type Description
editCount number | null

User edit count, or null for anonymous performers.

Source:

Returns:

null for anonymous performers.

Do not use this value in conjunction with other edit count bucketing, or you will deanonymize users to some degree.

Type
string | null
Provide the user's edit count as a low-granularity bucket name.

logEvent(schemaName, eventData) → {jQuery.Promise}static #

Construct and transmit to a remote server a record of some event having occurred. Events are represented as JavaScript objects that conform to a JSON Schema. The schema describes the properties the event object may (or must) contain and their type. This method represents the public client-side API of EventLogging.

Parameters:

Name Type Description
schemaName string

Canonical schema name.

eventData Object

Event object.

Source:

Returns:

jQuery Promise object for the logging call.

Type
jQuery.Promise

Construct and transmit to a remote server a record of some event having occurred.

logFailure(schemaName, errorCode)static #

Increment the error count in statsd for this schema.

Should be called instead of logEvent in case of an error.

Parameters:

Name Type Description
schemaName string
errorCode string
Source:
Increment the error count in statsd for this schema.

pageviewInSample(populationSize) → {boolean}static #

Determine whether the current event is sampled given a sampling ratio per pageview.

Parameters:

Name Type Description
populationSize number

One in how many should be included. 0 means nobody, 1 is 100%, 2 is 50%, etc.

Source:

Returns:

Type
boolean

Determine whether the current event is sampled given a sampling ratio per pageview.

sendBeacon(url)static #

Make a "fire and forget" HTTP request to a specified URL.

In older browsers that lack the Beacon API (navigator.sendBeacon), this falls back to a detached Image request.

Parameters:

Name Type Description
url string

URL to request from the server.

Source:
Make a "fire and forget" HTTP request to a specified URL.

sessionInSample(populationSize) → {boolean}static #

Determine whether the current sessionId is sampled given a sampling ratio. This method is deterministic given same sampling rate and sessionId, so sampling is sticky given a session and a sampling rate

Parameters:

Name Type Description
populationSize number

One in how many should be included. 0 means nobody, 1 is 100%, 2 is 50%, etc.

Source:

Returns:

Type
boolean
Determine whether the current sessionId is sampled given a sampling ratio.