Add new @stable event.Popups.SettingChange event

Extensions may want to log metrics relating to settings being enabled
or disabled. This is currently the case with reference previews.

This is a follow up to
I1c434f0098ae23bd62256686a658e3d5ef7f70b9

Additional change: Add FIXME clarifying migrateOldPreferences is temporary
and setting a date it can be removed.

Bug: T353798
Change-Id: If9bac123d731e7da7429ba3a0ea92e80263df6a6
This commit is contained in:
Jon Robson 2024-01-17 16:25:10 -08:00
parent 8fc7222b26
commit 8e4996485f
7 changed files with 18 additions and 8 deletions

View file

@ -75,7 +75,7 @@
},
{
"path": "resources/dist/referencePreviews.js",
"maxSize": "2.0kB"
"maxSize": "2.1kB"
}
]
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -5,6 +5,8 @@ import renderFn from './createReferencePreview';
import { TYPE_REFERENCE, FETCH_DELAY_REFERENCE_TYPE } from './constants';
import setUserConfigFlags from './setUserConfigFlags';
const REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups';
setUserConfigFlags( mw.config );
const referencePreviewsState = isReferencePreviewsEnabled(
mw.user, mw.popups.isEnabled,
@ -17,6 +19,12 @@ const gateway = createReferenceGateway();
// can check that state differently.
mw.config.set( 'wgPopupsReferencePreviewsVisible', !!referencePreviewsState );
mw.trackSubscribe( 'Popups.SettingChange', ( data ) => {
if ( data.previewType === TYPE_REFERENCE ) {
mw.track( REFERENCE_PREVIEWS_LOGGING_SCHEMA, data );
}
} );
window.refPreviews = referencePreviewsState !== null ? {
type: TYPE_REFERENCE,
selector: '#mw-content-text .reference a[ href*="#" ]',

View file

@ -1,5 +1,4 @@
import { previewTypes } from './preview/model';
import { TYPE_REFERENCE } from './ext.popups.referencePreviews/constants.js';
/**
* @module userSettings
@ -13,7 +12,7 @@ import { TYPE_REFERENCE } from './ext.popups.referencePreviews/constants.js';
const PAGE_PREVIEWS_ENABLED_KEY = 'mwe-popups-enabled',
REFERENCE_PREVIEWS_ENABLED_KEY = 'mwe-popups-referencePreviews-enabled',
REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups';
PAGE_PREVIEWS_CHANGE_SETTING_EVENT = 'Popups.SettingChange';
/**
* Creates an object whose methods encapsulate all interactions with the UA's
@ -31,6 +30,7 @@ export default function createUserSettings( storage ) {
storage.remove( PAGE_PREVIEWS_ENABLED_KEY );
this.storePreviewTypeEnabled( previewTypes.TYPE_PAGE, false );
}
const TYPE_REFERENCE = 'reference';
const isRefsDisabled = !!storage.get( REFERENCE_PREVIEWS_ENABLED_KEY );
if ( isRefsDisabled ) {
storage.remove( REFERENCE_PREVIEWS_ENABLED_KEY );
@ -61,17 +61,19 @@ export default function createUserSettings( storage ) {
* @param {boolean} enabled
*/
storePreviewTypeEnabled( previewType, enabled ) {
if ( previewType === TYPE_REFERENCE ) {
mw.track( REFERENCE_PREVIEWS_LOGGING_SCHEMA, {
action: enabled ? 'anonymousEnabled' : 'anonymousDisabled'
} );
}
const storageKey = `mwe-popups-${ previewType }-enabled`;
if ( enabled ) {
storage.remove( storageKey );
} else {
storage.set( storageKey, '0' );
}
/**
* @stable for use in MediaWiki extensions.
*/
mw.track( PAGE_PREVIEWS_CHANGE_SETTING_EVENT, {
previewType,
action: enabled ? 'anonymousEnabled' : 'anonymousDisabled'
} );
}
};
}