feat(polls): Add analytics for polls

This commit is contained in:
Vlad Piersec 2021-10-13 10:47:55 +03:00 committed by vp8x8
parent 04194ae8a1
commit ebb0a206f1
4 changed files with 34 additions and 2 deletions

View File

@ -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 * Creates an event which indicates that a button in the profile panel was
* clicked. * clicked.

View File

@ -5,6 +5,7 @@ import type { AbstractComponent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { sendAnalytics, createPollEvent } from '../../analytics';
import { getLocalParticipant, getParticipantById } from '../../base/participants'; import { getLocalParticipant, getParticipantById } from '../../base/participants';
import { registerVote } from '../actions'; import { registerVote } from '../actions';
import { COMMAND_ANSWER_POLL } from '../constants'; import { COMMAND_ANSWER_POLL } from '../constants';
@ -60,6 +61,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
newCheckBoxStates[index] = state; newCheckBoxStates[index] = state;
setCheckBoxState(newCheckBoxStates); setCheckBoxState(newCheckBoxStates);
sendAnalytics(createPollEvent('vote.checked'));
}, [ checkBoxStates ]); }, [ checkBoxStates ]);
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -76,6 +78,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
answers: checkBoxStates answers: checkBoxStates
}); });
sendAnalytics(createPollEvent('vote.sent'));
dispatch(registerVote(pollId, checkBoxStates)); dispatch(registerVote(pollId, checkBoxStates));
return false; return false;
@ -83,6 +86,7 @@ const AbstractPollAnswer = (Component: AbstractComponent<AbstractProps>) => (pro
const skipAnswer = useCallback(() => { const skipAnswer = useCallback(() => {
dispatch(registerVote(pollId, null)); dispatch(registerVote(pollId, null));
sendAnalytics(createPollEvent('vote.skipped'));
}, [ pollId ]); }, [ pollId ]);

View File

@ -5,6 +5,7 @@ import type { AbstractComponent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { sendAnalytics, createPollEvent } from '../../analytics';
import { getParticipantDisplayName } from '../../base/participants'; import { getParticipantDisplayName } from '../../base/participants';
import { COMMAND_NEW_POLL } from '../constants'; import { COMMAND_NEW_POLL } from '../constants';
@ -55,18 +56,18 @@ const AbstractPollCreate = (Component: AbstractComponent<AbstractProps>) => (pro
}); });
const addAnswer = useCallback((i: ?number) => { const addAnswer = useCallback((i: ?number) => {
const newAnswers = [ ...answers ]; const newAnswers = [ ...answers ];
sendAnalytics(createPollEvent('option.added'));
newAnswers.splice(typeof i === 'number' ? i : answers.length, 0, ''); newAnswers.splice(typeof i === 'number' ? i : answers.length, 0, '');
setAnswers(newAnswers); setAnswers(newAnswers);
}); });
const moveAnswer = useCallback((i, j) => { const moveAnswer = useCallback((i, j) => {
const newAnswers = [ ...answers ]; const newAnswers = [ ...answers ];
const answer = answers[i]; const answer = answers[i];
sendAnalytics(createPollEvent('option.moved'));
newAnswers.splice(i, 1); newAnswers.splice(i, 1);
newAnswers.splice(j, 0, answer); newAnswers.splice(j, 0, answer);
setAnswers(newAnswers); setAnswers(newAnswers);
@ -78,6 +79,7 @@ const AbstractPollCreate = (Component: AbstractComponent<AbstractProps>) => (pro
} }
const newAnswers = [ ...answers ]; const newAnswers = [ ...answers ];
sendAnalytics(createPollEvent('option.removed'));
newAnswers.splice(i, 1); newAnswers.splice(i, 1);
setAnswers(newAnswers); setAnswers(newAnswers);
}); });
@ -105,6 +107,7 @@ const AbstractPollCreate = (Component: AbstractComponent<AbstractProps>) => (pro
question, question,
answers: filteredAnswers answers: filteredAnswers
}); });
sendAnalytics(createPollEvent('created'));
setCreateMode(false); setCreateMode(false);

View File

@ -5,6 +5,7 @@ import type { AbstractComponent } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { sendAnalytics, createPollEvent } from '../../analytics';
import { getLocalParticipant, getParticipantById } from '../../base/participants/functions'; import { getLocalParticipant, getParticipantById } from '../../base/participants/functions';
import { retractVote } from '../actions'; import { retractVote } from '../actions';
import { COMMAND_ANSWER_POLL } from '../constants'; import { COMMAND_ANSWER_POLL } from '../constants';
@ -54,6 +55,7 @@ const AbstractPollResults = (Component: AbstractComponent<AbstractProps>) => (pr
const [ showDetails, setShowDetails ] = useState(false); const [ showDetails, setShowDetails ] = useState(false);
const toggleIsDetailed = useCallback(() => { const toggleIsDetailed = useCallback(() => {
sendAnalytics(createPollEvent('vote.detailsViewed'));
setShowDetails(!showDetails); setShowDetails(!showDetails);
}); });
@ -107,6 +109,7 @@ const AbstractPollResults = (Component: AbstractComponent<AbstractProps>) => (pr
answers: new Array(pollDetails.answers.length).fill(false) answers: new Array(pollDetails.answers.length).fill(false)
}); });
dispatch(retractVote(pollId)); dispatch(retractVote(pollId));
sendAnalytics(createPollEvent('vote.changed'));
}, [ pollId, localId, localName, pollDetails ]); }, [ pollId, localId, localName, pollDetails ]);
const { t } = useTranslation(); const { t } = useTranslation();