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

dispatch(eventName, customData)static #

Construct and submits a Metrics Platform Event from the event name and custom data for each stream that is interested in those events.

The Metrics Platform Event for a stream (S) is constructed by first initializing the minimum valid event (E) that can be submitted to S, and then mixing the context attributes requested in the configuration for S into E.

The Metrics Platform Event is submitted to a stream (S) if S is in sample and the event is not filtered according to the filtering rules for S.

Parameters:

Name Type Attributes Description
eventName string
customData Object.<string, any> optional
Deprecated:
  • Yes
Source:
See:

Construct and submits a Metrics Platform Event from the event name and custom data for each stream that is interested in those events.

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.

submit(streamName, eventData)static #

Submit an event to a stream.

The event (E) is submitted to the stream (S) if E has the $schema property and S is in sample. If E does not have the $schema property, then a warning is logged.

Parameters:

Name Type Description
streamName string

The name of the stream to send the event data to

eventData Object

The event data

Source:
Submit an event to a stream.