Track pageviews only on content page views, not edits

This code is typically not executed on special pages and such, so we
assume the isArticle check doesn't make much of a difference. The main
difference we are aware of is that this will exclude previews.

Bug: T214493
Change-Id: I5155329b8a549adbd3b17c1f1014bb8bbc6768f4
This commit is contained in:
Thiemo Kreuz 2019-11-13 14:23:47 +01:00 committed by Thiemo Kreuz (WMDE)
parent 668ad80c58
commit 4619cb24f6

View file

@ -18,28 +18,31 @@
loggingTopic = isReferencePreviewsEnabled ?
'event.ReferencePreviewsCite' :
'event.ReferencePreviewsBaseline',
samplingRate = isReferencePreviewsEnabled ?
1 :
1000,
isSampling = navigator.sendBeacon && mw.eventLog.eventInSample( samplingRate );
samplingRate = isReferencePreviewsEnabled ? 1 : 1000;
if ( isSampling ) {
// 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 () {
var isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
mw.track( loggingTopic, {
action: ( isInReferenceBlock ?
'clickedReferenceContentLink' :
'clickedFootnote' )
} );
}
);
mw.track( loggingTopic, { action: 'pageview' } );
if ( !navigator.sendBeacon ||
!mw.config.get( 'wgIsArticle' ) ||
!mw.eventLog ||
!mw.eventLog.eventInSample( samplingRate )
) {
return;
}
// 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 () {
var isInReferenceBlock = $( this ).parents( '.references' ).length > 0;
mw.track( loggingTopic, {
action: ( isInReferenceBlock ?
'clickedReferenceContentLink' :
'clickedFootnote' )
} );
}
);
mw.track( loggingTopic, { action: 'pageview' } );
} );
}() );