2015-10-29 17:58:30 +00:00
|
|
|
// See https://meta.wikimedia.org/wiki/Schema:RelatedArticles
|
|
|
|
( function ( $ ) {
|
|
|
|
var $readMore,
|
2015-11-14 00:03:39 +00:00
|
|
|
schemaRelatedPages,
|
2015-10-29 17:58:30 +00:00
|
|
|
skin = mw.config.get( 'skin' ),
|
|
|
|
$window = $( window );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log when ReadMore is seen by the user
|
|
|
|
*/
|
|
|
|
function logReadMoreSeen() {
|
2016-04-07 16:23:38 +00:00
|
|
|
if ( mw.viewport.isElementInViewport( $readMore.get( 0 ) ) ) {
|
2015-10-29 17:58:30 +00:00
|
|
|
$window.off( 'scroll', logReadMoreSeen );
|
2015-11-14 00:03:39 +00:00
|
|
|
schemaRelatedPages.log( { eventName: 'seen' } );
|
2015-10-29 17:58:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mw.trackSubscribe( 'ext.relatedArticles.logReady', function ( _, data ) {
|
2015-11-14 00:03:39 +00:00
|
|
|
schemaRelatedPages = new mw.eventLog.Schema(
|
2015-10-29 17:58:30 +00:00
|
|
|
'RelatedArticles',
|
|
|
|
// not sampled if the config variable is not set
|
|
|
|
mw.config.get( 'wgRelatedArticlesLoggingSamplingRate', 0 ),
|
|
|
|
{
|
|
|
|
pageId: mw.config.get( 'wgArticleId' ),
|
|
|
|
skin: ( skin === 'minerva' ) ? skin + '-' + mw.config.get( 'wgMFMode' ) : skin,
|
|
|
|
// We cannot depend on the uniqueness of mw.user.generateRandomSessionId(),
|
|
|
|
// thus append the timestamp. See mw.user documentation for more info.
|
|
|
|
userSessionToken: mw.user.generateRandomSessionId() +
|
|
|
|
( new Date() ).getTime().toString()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$readMore = data.$readMore;
|
|
|
|
|
|
|
|
// log ready
|
2015-11-14 00:03:39 +00:00
|
|
|
schemaRelatedPages.log( { eventName: 'ready' } );
|
2015-10-29 17:58:30 +00:00
|
|
|
|
|
|
|
// log when ReadMore is seen by the user
|
|
|
|
$window.on(
|
|
|
|
'scroll',
|
|
|
|
$.debounce( 250, logReadMoreSeen )
|
|
|
|
);
|
|
|
|
logReadMoreSeen();
|
|
|
|
|
|
|
|
// track the clicked event
|
|
|
|
// TODO: This should be moved into the PageList component or, preferably, the CardList/Card views.
|
|
|
|
$readMore.on( 'click', 'a', function () {
|
|
|
|
var index = $( this ).parents( 'li' ).index();
|
|
|
|
|
2015-11-14 00:03:39 +00:00
|
|
|
schemaRelatedPages.log( {
|
2015-10-29 17:58:30 +00:00
|
|
|
eventName: 'clicked',
|
|
|
|
clickIndex: index + 1
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2015-12-07 18:19:16 +00:00
|
|
|
}( jQuery, mediaWiki ) );
|