2023-08-21 08:08:23 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-09-20 13:03:16 +00:00
|
|
|
/**
|
2019-10-24 14:56:18 +00:00
|
|
|
* @file Temporary tracking to evaluate the impact of Reference Previews on users' interaction with references.
|
|
|
|
*
|
|
|
|
* The baseline metrics are for a sample of users who don't have ReferencePreviews enabled.
|
|
|
|
*
|
|
|
|
* Users with the feature enabled are not sampled, and events are logged using the ReferencePreviewsCite schema.
|
|
|
|
*
|
|
|
|
* @see https://phabricator.wikimedia.org/T214493
|
2019-09-20 13:03:16 +00:00
|
|
|
* @see https://phabricator.wikimedia.org/T231529
|
|
|
|
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsBaseline
|
2019-10-24 14:56:18 +00:00
|
|
|
* @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsCite
|
2019-09-20 13:03:16 +00:00
|
|
|
*/
|
2020-12-13 17:56:00 +00:00
|
|
|
|
|
|
|
// EventLogging may not be installed
|
|
|
|
mw.loader.using( 'ext.eventLogging' ).then( function () {
|
2019-09-20 13:03:16 +00:00
|
|
|
|
2019-10-24 14:56:18 +00:00
|
|
|
$( function () {
|
2023-08-21 08:08:23 +00:00
|
|
|
const isReferencePreviewsEnabled = mw.config.get( 'wgPopupsReferencePreviews', false );
|
|
|
|
const samplingRate = isReferencePreviewsEnabled ? 1 : 1000;
|
2019-09-20 13:03:16 +00:00
|
|
|
|
2019-11-13 13:23:47 +00:00
|
|
|
if ( !navigator.sendBeacon ||
|
|
|
|
!mw.config.get( 'wgIsArticle' ) ||
|
|
|
|
!mw.eventLog ||
|
|
|
|
!mw.eventLog.eventInSample( samplingRate )
|
|
|
|
) {
|
|
|
|
return;
|
2019-10-24 14:56:18 +00:00
|
|
|
}
|
2019-11-13 13:23:47 +00:00
|
|
|
|
2023-08-21 08:08:23 +00:00
|
|
|
const loggingTopic = isReferencePreviewsEnabled ?
|
2021-11-03 12:28:17 +00:00
|
|
|
'event.ReferencePreviewsCite' :
|
|
|
|
'event.ReferencePreviewsBaseline';
|
2019-11-13 13:23:47 +00:00
|
|
|
// 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 () {
|
2023-08-21 08:08:23 +00:00
|
|
|
const isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
|
2019-11-13 13:23:47 +00:00
|
|
|
mw.track( loggingTopic, {
|
|
|
|
action: ( isInReferenceBlock ?
|
|
|
|
'clickedReferenceContentLink' :
|
|
|
|
'clickedFootnote' )
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
mw.track( loggingTopic, { action: 'pageview' } );
|
2019-10-24 14:56:18 +00:00
|
|
|
} );
|
2020-12-13 17:56:00 +00:00
|
|
|
} );
|