2013-09-09 22:28:39 +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
|
|
|
|
* @param {JQuery} notification JQuery representing a single notification
|
|
|
|
* @param {string} context 'flyout'/'archive'
|
2013-12-24 19:27:23 +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
|
|
|
|
* @param {string} clickAction The interaction
|
|
|
|
* @param {string} context 'flyout'/'archive' or undefined for the badge
|
|
|
|
* @param {int} eventId Notification event id
|
|
|
|
* @param {string} eventType notification type
|
2013-12-24 19:27:23 +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
|
|
|
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 ) {
|
|
|
|
myEvt.eventId = eventId;
|
|
|
|
}
|
|
|
|
if ( eventType ) {
|
|
|
|
myEvt.notificationType = eventType;
|
|
|
|
}
|
2013-12-24 19:27:23 +00:00
|
|
|
if ( mobile ) {
|
|
|
|
myEvt.mobile = mobile;
|
|
|
|
}
|
2013-09-09 22:28:39 +00:00
|
|
|
mw.loader.using( 'ext.eventLogging', function() {
|
|
|
|
mw.eventLog.logEvent( 'EchoInteraction', myEvt );
|
2013-02-13 02:08:36 +00:00
|
|
|
} );
|
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 ) {
|
2013-09-09 22:28:39 +00:00
|
|
|
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' )
|
|
|
|
} );
|
2013-06-05 20:44:06 +00:00
|
|
|
} );
|
|
|
|
}
|
2013-09-09 22:28:39 +00:00
|
|
|
} )( mediaWiki );
|