mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-30 17:54:20 +00:00
b59eef1cfe
The current tracking is wrong for several reasons. Mainly because of a race condition if the Popups extension fininshed loading before the Cite tracking script is executed. But further more wgPopupsReferencePreviews was not a good choice to see if the user sees previews or not. The logging now uses the monoschema and only checks for enabled previews when the click events are fired. The chances that Popups finished initilizing then are much higher then. We still can see if the init is not finished and the variable not set though. Also we won't track the overall pageviews in here but use the generic pageview_hourly from the data lake instead. Bug: T353798 Depends-On: I1c434f0098ae23bd62256686a658e3d5ef7f70b9 Change-Id: I7a9524274efb58286f520c6148d5463bb0a78dbf
54 lines
2 KiB
JavaScript
54 lines
2 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @file Temporary tracking to evaluate the impact of Reference Previews on users' interaction with references.
|
|
*
|
|
* @see https://phabricator.wikimedia.org/T214493
|
|
* @see https://phabricator.wikimedia.org/T231529
|
|
* @see https://phabricator.wikimedia.org/T353798
|
|
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsBaseline
|
|
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsCite
|
|
*/
|
|
|
|
const CITE_BASELINE_LOGGING_SCHEMA = 'ext.cite.baseline';
|
|
// Same as in the Popups extension
|
|
// FIXME: Could be an extension wide constant when Reference Previews is merged into this code base
|
|
const REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups';
|
|
|
|
// EventLogging may not be installed
|
|
mw.loader.using( 'ext.eventLogging' ).then( function () {
|
|
$( function () {
|
|
if ( !navigator.sendBeacon ||
|
|
!mw.config.get( 'wgIsArticle' )
|
|
) {
|
|
return;
|
|
}
|
|
|
|
// FIXME: This might be obsolete when the code moves to the this extension
|
|
mw.trackSubscribe( REFERENCE_PREVIEWS_LOGGING_SCHEMA, function ( type, data ) {
|
|
if ( data.action.indexOf( 'anonymous' ) !== -1 ) {
|
|
mw.config.set( 'wgPopupsReferencePreviewsVisible', data.action === 'anonymousEnabled' );
|
|
}
|
|
} );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
$( '#mw-content-text' ).on(
|
|
'click',
|
|
// Footnote links, references block in VisualEditor, and reference content links.
|
|
'.reference a[ href*="#" ], .mw-reference-text a, .reference-text a',
|
|
function () {
|
|
const isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
|
|
mw.eventLog.dispatch( CITE_BASELINE_LOGGING_SCHEMA, {
|
|
action: ( isInReferenceBlock ?
|
|
'clickedReferenceContentLink' :
|
|
'clickedFootnote' ),
|
|
// FIXME: This might be obsolete when the code moves to the this extension and
|
|
// we get state directly.
|
|
// eslint-disable-next-line camelcase
|
|
with_ref_previews: mw.config.get( 'wgPopupsReferencePreviewsVisible' )
|
|
} );
|
|
}
|
|
);
|
|
} );
|
|
} );
|