2014-08-06 19:29:17 +00:00
|
|
|
( function ( mw, $ ) {
|
2012-09-26 05:09:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
2013-02-13 02:08:36 +00:00
|
|
|
mw.echo = {
|
|
|
|
|
2013-06-12 00:44:01 +00:00
|
|
|
clickThroughEnabled: mw.config.get( 'wgEchoConfig' ).eventlogging.EchoInteraction.enabled,
|
2013-06-05 20:44:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up event logging for individual notification
|
2014-05-27 18:28:37 +00:00
|
|
|
* @param {jQuery} notification JQuery representing a single notification
|
2013-06-05 20:44:06 +00:00
|
|
|
* @param {string} context 'flyout'/'archive'
|
2014-05-27 18:28:37 +00:00
|
|
|
* @param {boolean} [mobile] True if interaction was on a mobile device
|
2013-06-05 20:44:06 +00:00
|
|
|
*/
|
2013-12-24 19:27:23 +00:00
|
|
|
setupNotificationLogging: function ( notification, context, mobile ) {
|
2013-06-05 20:44:06 +00:00
|
|
|
var eventId = +notification.attr( 'data-notification-event' ),
|
|
|
|
eventType = notification.attr( 'data-notification-type' );
|
|
|
|
|
|
|
|
// Check if Schema:EchoInteraction is enabled
|
|
|
|
if ( !mw.echo.clickThroughEnabled ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Log the impression
|
2013-12-24 19:27:23 +00:00
|
|
|
mw.echo.logInteraction( 'notification-impression', context, eventId, eventType, mobile );
|
2013-06-05 20:44:06 +00:00
|
|
|
// Set up logging for clickthrough
|
2013-06-18 15:23:35 +00:00
|
|
|
notification.find( 'a' ).click( function () {
|
2013-12-24 19:27:23 +00:00
|
|
|
mw.echo.logInteraction( 'notification-link-click', context, eventId, eventType, mobile );
|
2013-06-05 20:44:06 +00:00
|
|
|
} );
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log all Echo interaction related events
|
2014-05-27 18:28:37 +00:00
|
|
|
* @param {string} action The interaction
|
|
|
|
* @param {string} [context] 'flyout'/'archive' or undefined for the badge
|
|
|
|
* @param {int} [eventId] Notification event id
|
|
|
|
* @param {string} [eventType] notification type
|
|
|
|
* @param {boolean} [mobile] True if interaction was on a mobile device
|
2013-06-05 20:44:06 +00:00
|
|
|
*/
|
2013-12-24 19:27:23 +00:00
|
|
|
logInteraction: function ( action, context, eventId, eventType, mobile ) {
|
2013-06-05 20:44:06 +00:00
|
|
|
// Check if Schema:EchoInteraction is enabled
|
|
|
|
if ( !mw.echo.clickThroughEnabled ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var myEvt = {
|
|
|
|
action: action
|
|
|
|
};
|
|
|
|
|
2013-12-24 19:27:23 +00:00
|
|
|
// All the fields below are optional
|
2013-06-05 20:44:06 +00:00
|
|
|
if ( context ) {
|
|
|
|
myEvt.context = context;
|
|
|
|
}
|
|
|
|
if ( eventId ) {
|
2015-04-15 04:18:14 +00:00
|
|
|
myEvt.eventId = Number( eventId );
|
2013-06-05 20:44:06 +00:00
|
|
|
}
|
|
|
|
if ( eventType ) {
|
|
|
|
myEvt.notificationType = eventType;
|
|
|
|
}
|
2013-12-24 19:27:23 +00:00
|
|
|
if ( mobile ) {
|
|
|
|
myEvt.mobile = mobile;
|
|
|
|
}
|
2015-05-04 19:24:37 +00:00
|
|
|
mw.loader.using( 'ext.eventLogging', function () {
|
2013-09-09 22:28:39 +00:00
|
|
|
mw.eventLog.logEvent( 'EchoInteraction', myEvt );
|
2013-02-13 02:08:36 +00:00
|
|
|
} );
|
2014-08-06 19:29:17 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @method
|
|
|
|
* @return jQuery element corresponding to the badge reflecting the notification count
|
|
|
|
*/
|
2015-05-04 19:24:37 +00:00
|
|
|
getBadge: function () {
|
2014-08-06 19:29:17 +00:00
|
|
|
return $( '.mw-echo-notifications-badge' );
|
2013-03-06 01:14:32 +00:00
|
|
|
}
|
2013-02-13 02:08:36 +00:00
|
|
|
|
|
|
|
};
|
2013-06-05 20:44:06 +00:00
|
|
|
|
|
|
|
if ( mw.echo.clickThroughEnabled ) {
|
2015-05-04 19:24:37 +00:00
|
|
|
mw.loader.using( 'ext.eventLogging', function () {
|
2013-09-09 22:28:39 +00:00
|
|
|
mw.eventLog.setDefaults( 'EchoInteraction', {
|
|
|
|
version: mw.config.get( 'wgEchoConfig' ).version,
|
|
|
|
userId: +mw.config.get( 'wgUserId' ),
|
|
|
|
editCount: +mw.config.get( 'wgUserEditCount' )
|
|
|
|
} );
|
2013-06-05 20:44:06 +00:00
|
|
|
} );
|
|
|
|
}
|
2014-08-06 19:29:17 +00:00
|
|
|
} )( mediaWiki, jQuery );
|