Draft: [JS] Create Submitter
Instruments using MetricsClient#submitInteraction()
and other methods will need to repeat the streamName
and schemaID
parameters on every invocation. In order to allow instrument maintainers to keep their instruments DRY, I propose adding a "submitter," an object that has a MetricsClient
-like interface but is bound to a specific {streamName,schemaID}
pair.
Example
type Action = [ 'scroll', 'scroll-to-top' ];
const m = createMetricsClient();
const submitter = m.newSubmitter(
'mediawiki.web_ui_scroll_migrated',
'/analytics/mediawiki/product_metrics/web_ui_actions/1.0.1',
true // Submit "init" event immediately
);
// …
/**
* @param {Action} action
*/
function log( action ) {
submitter.submitInteraction( action );
}
// …
// Is the instrument enabled?
if ( submitter.isStreamInSample() ) {
}
c.f. mediawiki/extensions/WikimediaEvents/modules/ext.wikimediaEvents/webUIScroll.js
Future
There are two possible improvements that we could make either now or in future:
- Allow
MetricsClient#newSubmitter()
to accept a{streamName,schemaVersion}
pair. Stream configs must have aschema_title
property. Combining that property with a version creates a schema ID - Allow
MetricsClient#newSubmitter()
to accept onlystreamName
. Stream configs could include the schema ID in theproducers.metrics_platform_client
property and the Metrics Platform client libraries could be updated to use that property by default
Notes
- The Mobile Web team (who became the Web team) had the same idea with the
mw.eventLog.Schema
class.