mon-entreprise/source/middlewares/trackDomainActions.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-06-06 16:17:13 +00:00
import {
currentQuestionSelector,
formattedSituationSelector
2018-06-06 16:17:13 +00:00
} from 'Selectors/analyseSelectors'
export default tracker => ({ getState }) => next => action => {
next(action)
const newState = getState()
if (action.type == 'STEP_ACTION' && action.name == 'fold') {
tracker.push([
'trackEvent',
'answer:' + action.source,
action.step,
2018-06-06 16:17:13 +00:00
formattedSituationSelector(newState)[action.step]
])
2018-06-06 16:17:13 +00:00
if (!currentQuestionSelector(newState)) {
tracker.push([
'trackEvent',
'done',
'after ' + newState.conversationSteps.foldedSteps.length + ' questions'
])
}
}
if (action.type === 'SET_ACTIVE_TARGET_INPUT') {
tracker.push(['trackEvent', 'select', newState.activeTargetInput])
}
if (action.type === 'START_CONVERSATION') {
tracker.push([
'trackEvent',
'refine',
newState.activeTargetInput,
2018-06-06 16:17:13 +00:00
formattedSituationSelector(newState)[newState.activeTargetInput]
])
}
if (action.type == 'STEP_ACTION' && action.name == 'unfold') {
tracker.push(['trackEvent', 'unfold', action.step])
}
if (action.type === 'RESET_SIMULATION') {
tracker.push(['trackEvent', 'restart', ''])
}
if (action.type === 'USER_INPUT_UPDATE') {
tracker.push(['trackEvent', 'input', action.meta.field, action.payload])
}
if (action.type === 'LOAD_PREVIOUS_SIMULATION') {
tracker.push(['trackEvent', 'loadPreviousSimulation'])
}
if (action.type === 'DELETE_PREVIOUS_SIMULATION') {
tracker.push(['trackEvent', 'deletePreviousSimulation'])
}
}