mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-24 07:34:11 +00:00
f4dbd455c6
This rate was decided in T88173 Bug: T88167 Change-Id: I22776582c271fa83ba5b98d38dd01775ebbfcef1
63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
( function ( $, mw ) {
|
|
|
|
/**
|
|
* @class mw.popups.logger
|
|
* @singleton
|
|
*/
|
|
var logger = {};
|
|
|
|
/**
|
|
* Sampling rate at which events are logged
|
|
* @property samplingRate
|
|
*/
|
|
logger.samplingRate = 10;
|
|
|
|
/**
|
|
* Get action based on click event
|
|
*
|
|
* @method getAction
|
|
* @param {Object} event
|
|
*/
|
|
logger.getAction = function ( event ) {
|
|
if ( event.which === 2 ) { // middle click
|
|
return 'opened in new tab';
|
|
} else if ( event.which === 1 ) {
|
|
if ( event.ctrlKey || event.metaKey ) {
|
|
return 'opened in new tab';
|
|
} else if ( event.shiftKey ) {
|
|
return 'opened in new window';
|
|
} else {
|
|
return 'opened in same tab';
|
|
}
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Logs the popup event as defined in the following schema-
|
|
* https://meta.wikimedia.org/wiki/Schema:Popups
|
|
*
|
|
* @method log
|
|
* @param {Object} event
|
|
* @return {jQuery.Promise}
|
|
*/
|
|
logger.log = function ( event ) {
|
|
if (
|
|
mw.eventLog === undefined ||
|
|
Math.floor( Math.random() * logger.samplingRate ) !== 0
|
|
) {
|
|
return $.Deferred().resolve();
|
|
}
|
|
|
|
// Get duration from time
|
|
if ( $.isNumeric( event.time ) ) {
|
|
event.duration = Math.floor( mw.now() - event.time );
|
|
delete event.time;
|
|
}
|
|
|
|
return mw.eventLog.logEvent( 'Popups', event );
|
|
};
|
|
|
|
mw.popups.logger = logger;
|
|
|
|
} ) ( jQuery, mediaWiki );
|