2015-09-16 19:29:01 +00:00
|
|
|
( function ( $, mw ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
mw.echo = mw.echo || {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Echo logger
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration object
|
|
|
|
* @cfg {boolean} [clickThroughEnabled] Whether logging is enabled
|
|
|
|
*/
|
|
|
|
mw.echo.Logger = function MwEchoUiLogger( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
this.clickThroughEnabled = config.clickThroughEnabled || this.constructor.static.clickThroughEnabled;
|
|
|
|
this.notificationsIdCache = [];
|
2015-09-16 19:29:01 +00:00
|
|
|
if ( this.clickThroughEnabled ) {
|
|
|
|
// This should usually already be loaded, but not always
|
|
|
|
this.deferred = mw.loader.using( 'ext.eventLogging', function () {
|
|
|
|
mw.eventLog.setDefaults( 'EchoInteraction', {
|
|
|
|
version: mw.config.get( 'wgEchoConfig' ).version,
|
|
|
|
userId: +mw.config.get( 'wgUserId' ),
|
|
|
|
editCount: +mw.config.get( 'wgUserEditCount' )
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
this.deferred = $.Deferred().resolve();
|
|
|
|
}
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
OO.initClass( mw.echo.Logger );
|
|
|
|
|
|
|
|
/* Static methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default behavior in MediaWiki for whether logging Echo interactions
|
|
|
|
* is enabled
|
|
|
|
*
|
|
|
|
* @static
|
2016-03-25 18:47:00 +00:00
|
|
|
* @property {boolean}
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.Logger.static.clickThroughEnabled = OO.getProp(
|
|
|
|
mw.config.get( 'wgEchoConfig' ),
|
|
|
|
'eventlogging',
|
|
|
|
'EchoInteraction',
|
|
|
|
'enabled'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context definitions.
|
|
|
|
*
|
|
|
|
* 'flyout': Interactions from the popup content
|
|
|
|
* 'archive': Interactions from the Special:Notifications page
|
|
|
|
* 'badge': Interactions from the badge button
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
*/
|
|
|
|
mw.echo.Logger.static.context = {
|
|
|
|
popup: 'flyout',
|
|
|
|
archive: 'archive',
|
|
|
|
badge: undefined
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Logging action names for consistency.
|
|
|
|
*
|
|
|
|
* 'notificationClick': Click interaction
|
|
|
|
* 'notificationImpression': Impression interaction
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @property {Object}
|
|
|
|
*/
|
|
|
|
mw.echo.Logger.static.actions = {
|
|
|
|
notificationClick: 'notification-link-click',
|
2015-12-23 17:41:48 +00:00
|
|
|
notificationBundleExpand: 'notification-bundle-expand',
|
2016-08-04 20:46:46 +00:00
|
|
|
notificationImpression: 'notification-impression',
|
2016-08-05 20:32:31 +00:00
|
|
|
markAllReadClick: 'mark-all-read-click',
|
|
|
|
markXWikiReadClick: 'mark-entire-xwiki-bundle-read-click'
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log all Echo interaction related events
|
|
|
|
*
|
|
|
|
* @param {string} action The interaction
|
|
|
|
* @param {string} [context] 'flyout'/'archive' or undefined for the badge
|
2016-05-11 20:33:17 +00:00
|
|
|
* @param {number} [eventId] Notification event id
|
2015-08-13 00:54:16 +00:00
|
|
|
* @param {string} [eventType] notification type
|
|
|
|
* @param {boolean} [mobile] True if interaction was on a mobile device
|
2016-03-02 07:29:40 +00:00
|
|
|
* @param {string} [notifWiki] Foreign wiki the notification came from
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2015-12-10 18:07:20 +00:00
|
|
|
mw.echo.Logger.prototype.logInteraction = function ( action, context, eventId, eventType, mobile, notifWiki ) {
|
2016-02-29 23:18:06 +00:00
|
|
|
var myEvt;
|
|
|
|
|
2015-10-08 22:20:31 +00:00
|
|
|
if ( !this.constructor.static.clickThroughEnabled ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-29 23:18:06 +00:00
|
|
|
myEvt = {
|
2015-08-13 00:54:16 +00:00
|
|
|
action: action
|
|
|
|
};
|
|
|
|
|
|
|
|
// All the fields below are optional
|
|
|
|
if ( context ) {
|
|
|
|
myEvt.context = context;
|
|
|
|
}
|
|
|
|
if ( eventId ) {
|
|
|
|
myEvt.eventId = Number( eventId );
|
|
|
|
}
|
|
|
|
if ( eventType ) {
|
|
|
|
myEvt.notificationType = eventType;
|
|
|
|
}
|
2016-08-04 20:46:46 +00:00
|
|
|
if ( mobile !== undefined || mw.config.get( 'skin' ) === 'minerva' ) {
|
|
|
|
myEvt.mobile = mobile || mw.config.get( 'skin' ) === 'minerva';
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 07:29:40 +00:00
|
|
|
if ( notifWiki && notifWiki !== mw.config.get( 'wgDBname' ) && notifWiki !== 'local' ) {
|
2015-12-10 18:07:20 +00:00
|
|
|
myEvt.notifWiki = notifWiki;
|
|
|
|
}
|
|
|
|
|
2015-09-16 19:29:01 +00:00
|
|
|
this.deferred.done( function () {
|
|
|
|
mw.eventLog.logEvent( 'EchoInteraction', myEvt );
|
|
|
|
} );
|
2015-08-13 00:54:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log the impression of notifications. This will log each notification exactly once.
|
|
|
|
*
|
|
|
|
* @param {string} type Notification type; 'alert' or 'message'
|
|
|
|
* @param {number[]} notificationIds Array of notification ids
|
|
|
|
* @param {string} context 'flyout'/'archive' or undefined for the badge
|
2016-03-02 07:29:40 +00:00
|
|
|
* @param {string} [notifWiki='local'] Foreign wiki the notifications came from
|
|
|
|
* @param {boolean} [mobile=false] True if interaction was on a mobile device
|
2015-08-13 00:54:16 +00:00
|
|
|
*/
|
2016-03-02 07:29:40 +00:00
|
|
|
mw.echo.Logger.prototype.logNotificationImpressions = function ( type, notificationIds, context, notifWiki, mobile ) {
|
|
|
|
var i, len, key;
|
2015-08-13 00:54:16 +00:00
|
|
|
|
|
|
|
for ( i = 0, len = notificationIds.length; i < len; i++ ) {
|
2016-03-02 07:29:40 +00:00
|
|
|
key = notifWiki && notifWiki !== mw.config.get( 'wgDBname' ) && notifWiki !== 'local' ?
|
|
|
|
notificationIds[ i ] + '-' + notifWiki :
|
|
|
|
notificationIds[ i ];
|
|
|
|
|
|
|
|
if ( !this.notificationsIdCache[ key ] ) {
|
2015-08-13 00:54:16 +00:00
|
|
|
// Log notification impression
|
2016-03-02 07:29:40 +00:00
|
|
|
this.logInteraction( 'notification-impression', context, notificationIds[ i ], type, mobile, notifWiki );
|
2015-08-13 00:54:16 +00:00
|
|
|
// Cache
|
2016-03-02 07:29:40 +00:00
|
|
|
this.notificationsIdCache[ key ] = true;
|
2015-08-13 00:54:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
mw.echo.logger = new mw.echo.Logger();
|
2015-09-16 19:29:01 +00:00
|
|
|
} )( jQuery, mediaWiki );
|