2018-06-20 14:09:14 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-06-20 14:28:00 +00:00
|
|
|
// $FlowFixMe
|
2018-06-20 14:09:14 +00:00
|
|
|
import { actionTypes } from 'redux-form'
|
2018-06-06 16:17:13 +00:00
|
|
|
import {
|
2018-06-18 16:03:52 +00:00
|
|
|
currentQuestionSelector,
|
|
|
|
formattedSituationSelector
|
2018-06-06 16:17:13 +00:00
|
|
|
} from 'Selectors/analyseSelectors'
|
2018-06-20 14:09:14 +00:00
|
|
|
import { debounce } from '../utils'
|
2018-07-12 08:09:41 +00:00
|
|
|
import type { Tracker } from 'Components/utils/withTracker'
|
2018-06-20 14:09:14 +00:00
|
|
|
|
|
|
|
export default (tracker: Tracker) => {
|
|
|
|
const debouncedUserInputTracking = debounce(1000, action =>
|
|
|
|
tracker.push(['trackEvent', 'input', action.meta.field, action.payload])
|
|
|
|
)
|
2018-06-06 16:17:13 +00:00
|
|
|
|
2018-07-12 08:09:41 +00:00
|
|
|
// $FlowFixMe
|
|
|
|
return ({ getState }) => next => action => {
|
2018-06-20 14:09:14 +00:00
|
|
|
next(action)
|
|
|
|
const newState = getState()
|
|
|
|
if (action.type == 'STEP_ACTION' && action.name == 'fold') {
|
2018-05-24 15:36:17 +00:00
|
|
|
tracker.push([
|
|
|
|
'trackEvent',
|
2018-06-20 14:09:14 +00:00
|
|
|
'answer:' + action.source,
|
|
|
|
action.step,
|
|
|
|
formattedSituationSelector(newState)[action.step]
|
2018-05-24 15:36:17 +00:00
|
|
|
])
|
2018-06-20 14:09:14 +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])
|
2018-05-24 15:36:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-20 14:09:14 +00:00
|
|
|
if (action.type === 'START_CONVERSATION') {
|
|
|
|
tracker.push([
|
|
|
|
'trackEvent',
|
|
|
|
'refine',
|
|
|
|
newState.activeTargetInput,
|
2018-07-31 14:11:59 +00:00
|
|
|
action.question
|
2018-06-20 14:09:14 +00:00
|
|
|
])
|
|
|
|
}
|
|
|
|
if (action.type == 'STEP_ACTION' && action.name == 'unfold') {
|
|
|
|
tracker.push(['trackEvent', 'unfold', action.step])
|
|
|
|
}
|
2018-05-24 15:36:17 +00:00
|
|
|
|
2018-06-20 14:09:14 +00:00
|
|
|
if (action.type === 'RESET_SIMULATION') {
|
|
|
|
tracker.push(['trackEvent', 'restart', ''])
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === actionTypes.CHANGE) {
|
|
|
|
debouncedUserInputTracking(action)
|
|
|
|
}
|
2018-06-18 16:03:52 +00:00
|
|
|
|
2018-06-20 14:09:14 +00:00
|
|
|
if (action.type === 'LOAD_PREVIOUS_SIMULATION') {
|
|
|
|
tracker.push(['trackEvent', 'loadPreviousSimulation'])
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'DELETE_PREVIOUS_SIMULATION') {
|
|
|
|
tracker.push(['trackEvent', 'deletePreviousSimulation'])
|
|
|
|
}
|
2018-06-18 16:03:52 +00:00
|
|
|
}
|
2018-05-24 15:36:17 +00:00
|
|
|
}
|