Expand all

package Experiment

This class represents an experiment enrolment for the current user. You can use it to get which group the user was assigned when they were enrolled into the experiment and send experiment-related analytics events.

Note well that this class should be constructed using mw.xLab.getExperiment() instead, e.g.

const experiment = mw.xLab.getExperiment( 'my-awesome-experiment' );

Methods

getAssignedGroup() → {string|null} #

Gets the group assigned to the current user.

Source:

Returns:

Type
string | null
Gets the group assigned to the current user.

isAssignedGroup(…groups) → {boolean} #

Gets whether the group assigned to the current user is one of the given groups.

Example

const e = mw.xLab.getExperiment( 'my-awesome-experiment' );

// Is the current user assigned A or B for the "My Awesome Experiment" experiment?
if ( e.isAssignedGroup( 'A', 'B' ) {
  // ...
}

Parameters:

Name Type Attributes Description
groups string repeatable
Source:
See:

Returns:

Type
boolean
Gets whether the group assigned to the current user is one of the given groups.

send(action, [interactionData]) #

Sends an analytics event related to the experiment.

If the user is enrolled in the experiment, then the event is decorated with experiment-related data and sent. The experiment-related data are specified and documented in the fragment/analytics/product_metrics/experiment schema fragment.

By default, the analytics event will be sent to the product_metrics.web_base stream and be validated with the /analytics/product_metrics/web/base/1.5.0 schema. The stream and schema can be overridden with Experiment#setStream and Experiment#setSchema, respectively.

Parameters:

Name Type Attributes Description
action string

The action that the user enrolled in this experiment took, e.g. "hover", "click"

interactionData Object optional

Additional data about the action that the user enrolled in the experiment took

Source:
See:
Sends an analytics event related to the experiment.

setSchema(schemaID) → {Experiment} #

Sets the ID of the schema used to validate analytics events sent with Experiment#send.

This method is chainable.

Parameters:

Name Type Description
schemaID string
Source:

Returns:

Type
Experiment

Sets the ID of the schema used to validate analytics events sent with Experiment#send.

setStream(streamName) → {Experiment} #

Sets the stream to send analytics events to with Experiment#send.

This method is chainable.

Parameters:

Name Type Description
streamName string
Source:

Returns:

The instance on which this method was called

Type
Experiment
Sets the stream to send analytics events to with Experiment#send.

submitInteraction(action, interactionData)package #

Submits an event related to this experiment.

This method makes Experiment compatible with the click-through rate implementation in the ext.wikimediaEvents.xLab ResourceLoader module by proxying to Experiment#send. Calling this outside of xLab is not supported.

Parameters:

Name Type Description
action string

The action related to the submitted event

interactionData Object

Additional data

Source:
See:
Submits an event related to this experiment.