2016-12-13 10:25:17 +00:00
|
|
|
( function ( popups, nextState ) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer for actions that may result in an event being logged via Event
|
|
|
|
* Logging.
|
|
|
|
*
|
|
|
|
* The base data represents data that's shared between all events logged with
|
|
|
|
* the Popups schema ("Popups events"). Very nearly all of it is initialized
|
|
|
|
* during the BOOT action and doesn't change between link interactions, e.g.
|
|
|
|
* the user being an anon or the number of edits they've made.
|
|
|
|
*
|
|
|
|
* The user's number of previews, however, does change between link
|
|
|
|
* interactions and the associated bucket (a computed property) is what is
|
|
|
|
* logged. This is reflected in the state tree: the `previewCount` property is
|
|
|
|
* used to store the user's number of previews and the
|
|
|
|
* `baseData.previewCountBucket` property is used to store the associated
|
|
|
|
* bucket.
|
|
|
|
*
|
|
|
|
* @param {Object} state
|
|
|
|
* @param {Object} action
|
|
|
|
* @return {Object} The state as a result of processing the action
|
|
|
|
*/
|
|
|
|
popups.reducers.eventLogging = function ( state, action ) {
|
|
|
|
var nextCount;
|
|
|
|
|
|
|
|
if ( state === undefined ) {
|
|
|
|
state = {
|
|
|
|
previewCount: undefined,
|
|
|
|
baseData: {},
|
|
|
|
interaction: undefined,
|
|
|
|
event: undefined
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( action.type ) {
|
|
|
|
case popups.actionTypes.BOOT:
|
|
|
|
return nextState( state, {
|
|
|
|
previewCount: action.user.previewCount,
|
|
|
|
baseData: {
|
|
|
|
pageTitleSource: action.page.title,
|
|
|
|
namespaceIdSource: action.page.namespaceID,
|
|
|
|
pageIdSource: action.page.id,
|
|
|
|
isAnon: action.user.isAnon,
|
2016-12-14 14:24:21 +00:00
|
|
|
popupEnabled: action.isEnabled,
|
2016-12-13 10:25:17 +00:00
|
|
|
pageToken: action.pageToken,
|
|
|
|
sessionToken: action.sessionToken,
|
|
|
|
editCountBucket: popups.counts.getEditCountBucket( action.user.editCount ),
|
|
|
|
previewCountBucket: popups.counts.getPreviewCountBucket( action.user.previewCount )
|
|
|
|
},
|
|
|
|
event: {
|
|
|
|
action: 'pageLoaded'
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
Add reading depth
Use schema revision 16163887.
Add the 'checkin' action, which is accompanied by the 'checkin'
property. The action is logged at the following seconds
(Fibonacci numbers) after the page loads: 1, 2, 3, 5, 8, 13, 21,
34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765.
The `checkin` property contains the values listed above.
Bug: T147314
Change-Id: Ib9ec7bd0e60aa34a04e32222b025347f6ee31794
2016-12-13 22:52:20 +00:00
|
|
|
case popups.actionTypes.CHECKIN:
|
|
|
|
return nextState( state, {
|
|
|
|
event: {
|
|
|
|
action: 'checkin',
|
|
|
|
checkin: action.time
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2016-12-13 10:25:17 +00:00
|
|
|
case popups.actionTypes.EVENT_LOGGED:
|
|
|
|
return nextState( state, {
|
|
|
|
event: undefined
|
|
|
|
} );
|
|
|
|
|
|
|
|
case popups.actionTypes.PREVIEW_SHOW:
|
|
|
|
nextCount = state.previewCount + 1;
|
|
|
|
|
|
|
|
return nextState( state, {
|
|
|
|
previewCount: nextCount,
|
|
|
|
baseData: nextState( state.baseData, {
|
|
|
|
previewCountBucket: popups.counts.getPreviewCountBucket( nextCount )
|
|
|
|
} ),
|
|
|
|
interaction: nextState( state.interaction, {
|
|
|
|
timeToPreviewShow: action.timestamp - state.interaction.started
|
|
|
|
} )
|
|
|
|
} );
|
|
|
|
|
|
|
|
case popups.actionTypes.LINK_DWELL:
|
|
|
|
return nextState( state, {
|
|
|
|
interaction: {
|
2017-01-08 13:25:17 +00:00
|
|
|
token: action.token,
|
2016-12-13 10:25:17 +00:00
|
|
|
started: action.timestamp
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
case popups.actionTypes.LINK_CLICK:
|
|
|
|
return nextState( state, {
|
|
|
|
event: {
|
|
|
|
action: 'opened',
|
|
|
|
linkInteractionToken: state.interaction.token,
|
|
|
|
totalInteractionTime: Math.round( action.timestamp - state.interaction.started )
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
2017-01-11 23:33:27 +00:00
|
|
|
case popups.actionTypes.ABANDON_START:
|
2016-12-13 10:25:17 +00:00
|
|
|
return nextState( state, {
|
|
|
|
interaction: nextState( state.interaction, {
|
|
|
|
finished: action.timestamp
|
|
|
|
} )
|
|
|
|
} );
|
|
|
|
|
2017-01-11 23:33:27 +00:00
|
|
|
case popups.actionTypes.ABANDON_END:
|
2016-12-13 10:25:17 +00:00
|
|
|
return nextState( state, {
|
|
|
|
event: {
|
|
|
|
action: state.interaction.timeToPreviewShow ? 'dismissed' : 'dwelledButAbandoned',
|
|
|
|
linkInteractionToken: state.interaction.token,
|
|
|
|
totalInteractionTime: Math.round( state.interaction.finished - state.interaction.started )
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( mediaWiki.popups, mediaWiki.popups.nextState ) );
|