Page MenuHomePhabricator

Provide hooks for 3rd party instrumentation
Open, MediumPublic

Description

Wikipedia Preview partners want to understand how the features are being used by their users. They would like to be able to build instrumentation.

This task is about defining and implementing some sort of "hooks" so partners can build or plug in their own instrumentation when certain events (open, expand, gallery, read more on wiki, etc) are happening.

Event Timeline

SBisson created this task.Dec 11 2020, 2:39 PM
Restricted Application added a project: Inuka-Team. · View Herald TranscriptDec 11 2020, 2:39 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript
AMuigai triaged this task as Medium priority.Dec 18 2020, 4:30 PM

I'm thinking allowing something like this:

wikipediaPreview.init({
  ...
  events: {
    onShow: function(e) {
      // invoked when a preview is shown
    },
    onHide: function(e) {
      // invoked when a preview is hidden
    },
    onExpand: function(e) {
      // invoked when a preview is expanded
    },
    onShowGallery: function(e) {
      // invoked when the gallery is shown
    },
    // whole bunch of other events
  }
})

Another option is to have a single event callback and describe what is happening using the event object parameter:

wikipediaPreview.init({
  ...
  onEvent: function(e) {
    switch (e.type) {
      case: 'show':
      case: 'hide':
      // a whole bunch of possible types
    }
  }
})

I vote for the first option

  1. events are independence, so the scope can be limited without worrying the onEvent scope.
  2. more native to insert on* single event

Agree the first option seems more aligned with the current codebase