Debian Codegraph @

extensions/Cite/modules/ext.cite.tracking.js

raw symbols SCIP
1 'use strict';
2
3 /**
4 * Temporary tracking to evaluate the impact of Reference Previews on
5 * users' interaction with references.
6 *
7 * @memberof module:ext.cite.ux-enhancements
8 * @see https://phabricator.wikimedia.org/T214493
9 * @see https://phabricator.wikimedia.org/T231529
10 * @see https://phabricator.wikimedia.org/T353798
11 * @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsBaseline
12 * @see https://meta.wikimedia.org/wiki/Schema:ReferencePreviewsCite
13 */
14
15 const CITE_BASELINE_LOGGING_SCHEMA = 'ext.cite.baseline';
16 // Same as in the Popups extension
17 // FIXME: Could be an extension wide constant when Reference Previews is merged into this code base
18 const REFERENCE_PREVIEWS_LOGGING_SCHEMA = 'event.ReferencePreviewsPopups';
19
20 // EventLogging may not be installed
21 mw.loader.using( 'ext.eventLogging' ).then( () => {
22 $( () => {
23 if ( !navigator.sendBeacon ||
24 !mw.config.get( 'wgIsArticle' )
25 ) {
26 return;
27 }
28
29 // FIXME: This might be obsolete when the code moves to the this extension
30 mw.trackSubscribe( REFERENCE_PREVIEWS_LOGGING_SCHEMA, ( type, data ) => {
31 if ( data.action.indexOf( 'anonymous' ) !== -1 ) {
32 mw.config.set( 'wgCiteReferencePreviewsVisible', data.action === 'anonymousEnabled' );
33 }
34 } );
35
36 // eslint-disable-next-line no-jquery/no-global-selector
37 $( '#mw-content-text' ).on(
38 'click',
39 // Footnote links, references block in VisualEditor, and reference content links.
40 '.reference a[ href*="#" ], .mw-reference-text a, .reference-text a',
41 function () {
42 const isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
43 mw.eventLog.dispatch( CITE_BASELINE_LOGGING_SCHEMA, {
44 action: ( isInReferenceBlock ?
45 'clickedReferenceContentLink' :
46 'clickedFootnote' ),
47 // FIXME: This might be obsolete when the code moves to the this extension and
48 // we get state directly.
49 // eslint-disable-next-line camelcase
50 with_ref_previews: mw.config.get( 'wgCiteReferencePreviewsVisible' )
51 } );
52 }
53 );
54 } );
55 } );