Module: reducers/eventLogging

(require("reducers/eventLogging"))(state, action) → {Object}

Reducer for actions that may result in an event being logged with the Popups schema via EventLogging.

The complexity of this reducer reflects the complexity of the schema, which is compounded by the introduction of two delays introduced by the system to provide reasonable performance and a consistent UX.

The reducer must:

  • Accumulate the state required to log events. This state is referred to as "the interaction state" or "the interaction";
  • Enforce the invariant that one event is logged per interaction;
  • Defend against delayed actions being dispatched; and, as a direct consequence
  • Handle transitioning from one interaction to another at the same time.

Furthermore, we distinguish between "finalizing" and "closing" the current interaction state. Since only one event should be logged per link interaction, we say that the interaction state is finalized when an event has been logged and is closed when a new interaction should be created. In practice, the interaction state is only finalized when the user clicks a link or a preview.

Parameters:
Name Type Description
state Object
action Object
Source:
Returns:

The state resulting from reducing the action with the current state

Type
Object

Methods

(inner) createClosingEvent(interaction) → {Object|undefined}

Creates an event that, when mixed into the base data (see getBaseData), represents the user abandoning a link or preview.

Since the event should be logged when the user has either abandoned a link or dwelled on a different link, we refer to these events as "closing" events as the link interaction has finished and a new one will be created later.

If the link interaction is finalized, then no closing event is created.

Parameters:
Name Type Description
interaction Object
Source:
Returns:
Type
Object | undefined

(inner) createEvent(interaction, actionData) → {Object}

Takes data specific to the action and adds the following properties:

  • linkInteractionToken;
  • pageTitleHover and namespaceIdHover; and
  • previewType and perceivedWait, if a preview has been shown.

The linkInteractionToken is renewed on each new preview dwelling unlike the pageToken which has a lifespan tied to the pageview. It is erroneous to use the same linkInteractionToken across multiple previews even if the previews are for the same link.

Parameters:
Name Type Description
interaction Object
actionData Object

Data specific to the action, e.g. see createClosingEvent

Source:
Returns:
Type
Object

(inner) getBaseData(bootAction) → {Object}

Initialize the data that's shared between all events.

Parameters:
Name Type Description
bootAction Object
Source:
Returns:
Type
Object