feat(polls): Add analytics for polls
This commit is contained in:
parent
04194ae8a1
commit
ebb0a206f1
|
@ -376,6 +376,28 @@ export function createPinnedEvent(action, participantId, attributes) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a poll event.
|
||||
* The following events will be created:
|
||||
* - poll.created
|
||||
* - poll.vote.checked
|
||||
* - poll.vote.sent
|
||||
* - poll.vote.skipped
|
||||
* - poll.vote.detailsViewed
|
||||
* - poll.vote.changed
|
||||
* - poll.option.added
|
||||
* - poll.option.moved
|
||||
* - poll.option.removed.
|
||||
*
|
||||
* @param {string} action - The action.
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function createPollEvent(action) {
|
||||
return {
|
||||
action: `poll.${action}`
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an event which indicates that a button in the profile panel was
|
||||
* clicked.
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { AbstractComponent } from 'react';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
import { sendAnalytics, createPollEvent } from '../../analytics';
|
||||
import { getLocalParticipant, getParticipantById } from '../../base/participants';
|
||||
import { registerVote } from '../actions';
|
||||
import { COMMAND_ANSWER_POLL } from '../constants';
|
||||
|
@ -60,6 +61,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
|
|||
|
||||
newCheckBoxStates[index] = state;
|
||||
setCheckBoxState(newCheckBoxStates);
|
||||
sendAnalytics(createPollEvent('vote.checked'));
|
||||
}, [ checkBoxStates ]);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
@ -76,6 +78,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
|
|||
answers: checkBoxStates
|
||||
});
|
||||
|
||||
sendAnalytics(createPollEvent('vote.sent'));
|
||||
dispatch(registerVote(pollId, checkBoxStates));
|
||||
|
||||
return false;
|
||||
|
@ -83,6 +86,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
|
|||
|
||||
const skipAnswer = useCallback(() => {
|
||||
dispatch(registerVote(pollId, null));
|
||||
sendAnalytics(createPollEvent('vote.skipped'));
|
||||
|
||||
}, [ pollId ]);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { AbstractComponent } from 'react';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import { sendAnalytics, createPollEvent } from '../../analytics';
|
||||
import { getParticipantDisplayName } from '../../base/participants';
|
||||
import { COMMAND_NEW_POLL } from '../constants';
|
||||
|
||||
|
@ -55,18 +56,18 @@ const AbstractPollCreate = (Component: AbstractComponent<AbstractProps>) => (pro
|
|||
});
|
||||
|
||||
const addAnswer = useCallback((i: ?number) => {
|
||||
|
||||
const newAnswers = [ ...answers ];
|
||||
|
||||
sendAnalytics(createPollEvent('option.added'));
|
||||
newAnswers.splice(typeof i === 'number' ? i : answers.length, 0, '');
|
||||
setAnswers(newAnswers);
|
||||
});
|
||||
|
||||
const moveAnswer = useCallback((i, j) => {
|
||||
const newAnswers = [ ...answers ];
|
||||
|
||||
const answer = answers[i];
|
||||
|
||||
sendAnalytics(createPollEvent('option.moved'));
|
||||
newAnswers.splice(i, 1);
|
||||
newAnswers.splice(j, 0, answer);
|
||||
setAnswers(newAnswers);
|
||||
|
@ -78,6 +79,7 @@ const AbstractPollCreate = (Component: AbstractComponent<AbstractProps>) => (pro
|
|||
}
|
||||
const newAnswers = [ ...answers ];
|
||||
|
||||
sendAnalytics(createPollEvent('option.removed'));
|
||||
newAnswers.splice(i, 1);
|
||||
setAnswers(newAnswers);
|
||||
});
|
||||
|
@ -105,6 +107,7 @@ const AbstractPollCreate = (Component: AbstractComponent<AbstractProps>) => (pro
|
|||
question,
|
||||
answers: filteredAnswers
|
||||
});
|
||||
sendAnalytics(createPollEvent('created'));
|
||||
|
||||
setCreateMode(false);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import type { AbstractComponent } from 'react';
|
|||
import { useTranslation } from 'react-i18next';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
import { sendAnalytics, createPollEvent } from '../../analytics';
|
||||
import { getLocalParticipant, getParticipantById } from '../../base/participants/functions';
|
||||
import { retractVote } from '../actions';
|
||||
import { COMMAND_ANSWER_POLL } from '../constants';
|
||||
|
@ -54,6 +55,7 @@ const AbstractPollResults = (Component: AbstractComponent<AbstractProps>) => (pr
|
|||
|
||||
const [ showDetails, setShowDetails ] = useState(false);
|
||||
const toggleIsDetailed = useCallback(() => {
|
||||
sendAnalytics(createPollEvent('vote.detailsViewed'));
|
||||
setShowDetails(!showDetails);
|
||||
});
|
||||
|
||||
|
@ -107,6 +109,7 @@ const AbstractPollResults = (Component: AbstractComponent<AbstractProps>) => (pr
|
|||
answers: new Array(pollDetails.answers.length).fill(false)
|
||||
});
|
||||
dispatch(retractVote(pollId));
|
||||
sendAnalytics(createPollEvent('vote.changed'));
|
||||
}, [ pollId, localId, localName, pollDetails ]);
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
|
Loading…
Reference in New Issue