Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4029973
Instrument.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
Instrument.js
View Options
// TypeScript can't parse the MetricsClient type without explicitly importing it. On the other
// hand, JSDoc can. Prioritise documentation over type checking for now.
// @ts-nocheck
/**
* Provides a convenient API for writing an instrument.
*
* This class provides the same methods as {@link MetricsClient} but bound to the stream
* name/schema ID pair, allowing developers to minimize repetition.
*
* Further, each method will mix in a value for `funnel_event_sequence_position` to each submitted
* event. The value increases by 1 after the event is submitted. For example, if an instrument
* submits an `init` and a `click` event:
*
* ```
* // i is an instance of Instrument
* i.submitInteraciton( 'init' );
* i.submitClick( '#button', 'my_button' );
* ```
*
* then the events will look like `action="init",funnel_event_sequence_postion=0` and
* `action="click",funnel_event_sequence_position=1`.
*
* Note well that this class is not expected to be constructed directly. Instead, developers should
* use {@link MetricsClient#newInstrument}, e.g.
*
* ```
* const m = require( '/path/to/metrics-platform' ).createMetricsClient();
* const i = m.newInstrument( STREAM_NAME, SCHEMA_ID );
*
* // ...
*
* i.submitInteraction( 'init' );
* ```
*
* @param {MetricsClient} metricsClient
* @param {string} streamName
* @param {string} schemaID
* @constructor
*/
function
Instrument
(
metricsClient
,
streamName
,
schemaID
)
{
this
.
metricsClient
=
metricsClient
;
this
.
streamName
=
streamName
;
this
.
schemaID
=
schemaID
;
this
.
eventSequencePosition
=
1
;
}
/**
* See {@link MetricsClient#isStreamInSample}.
*
* @return {boolean}
*/
Instrument
.
prototype
.
isStreamInSample
=
function
()
{
return
this
.
metricsClient
.
isStreamInSample
(
this
.
streamName
);
};
/**
* @return {boolean}
*/
Instrument
.
prototype
.
isEnabled
=
function
()
{
return
this
.
isStreamInSample
();
};
/**
* See {@link MetricsClient#submitInteraction}.
*
* @param {string} action
* @param {InteractionContextData} [interactionData]
*/
Instrument
.
prototype
.
submitInteraction
=
function
(
action
,
interactionData
)
{
interactionData
=
Object
.
assign
(
{},
interactionData
||
{},
{
// eslint-disable-next-line camelcase
funnel_event_sequence_position
:
this
.
eventSequencePosition
++
}
);
this
.
metricsClient
.
submitInteraction
(
this
.
streamName
,
this
.
schemaID
,
action
,
interactionData
);
};
/**
* See {@link MetricsClient#submitClick}.
*
* @param {ElementInteractionData} interactionData
*/
Instrument
.
prototype
.
submitClick
=
function
(
interactionData
)
{
// eslint-disable-next-line camelcase
interactionData
.
funnel_event_sequence_position
=
this
.
eventSequencePosition
++
;
this
.
metricsClient
.
submitClick
(
this
.
streamName
,
interactionData
);
};
module
.
exports
=
Instrument
;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 14 2026, 22:24 (13 w, 1 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
59/3b/11e8390e529f7c32d436a24d36e2
Default Alt Text
Instrument.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment