From ebb0a206f19aee52f6c3aa9b40936d2b79fb6cdf Mon Sep 17 00:00:00 2001 From: Vlad Piersec Date: Wed, 13 Oct 2021 10:47:55 +0300 Subject: [PATCH] feat(polls): Add analytics for polls --- react/features/analytics/AnalyticsEvents.js | 22 +++++++++++++++++++ .../polls/components/AbstractPollAnswer.js | 4 ++++ .../polls/components/AbstractPollCreate.js | 7 ++++-- .../polls/components/AbstractPollResults.js | 3 +++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/react/features/analytics/AnalyticsEvents.js b/react/features/analytics/AnalyticsEvents.js index cf566b7a5f..bffac73e41 100644 --- a/react/features/analytics/AnalyticsEvents.js +++ b/react/features/analytics/AnalyticsEvents.js @@ -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. diff --git a/react/features/polls/components/AbstractPollAnswer.js b/react/features/polls/components/AbstractPollAnswer.js index 4cd61fc5ac..ee1dcde1bd 100644 --- a/react/features/polls/components/AbstractPollAnswer.js +++ b/react/features/polls/components/AbstractPollAnswer.js @@ -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) => (pro newCheckBoxStates[index] = state; setCheckBoxState(newCheckBoxStates); + sendAnalytics(createPollEvent('vote.checked')); }, [ checkBoxStates ]); const dispatch = useDispatch(); @@ -76,6 +78,7 @@ const AbstractPollAnswer = (Component: AbstractComponent) => (pro answers: checkBoxStates }); + sendAnalytics(createPollEvent('vote.sent')); dispatch(registerVote(pollId, checkBoxStates)); return false; @@ -83,6 +86,7 @@ const AbstractPollAnswer = (Component: AbstractComponent) => (pro const skipAnswer = useCallback(() => { dispatch(registerVote(pollId, null)); + sendAnalytics(createPollEvent('vote.skipped')); }, [ pollId ]); diff --git a/react/features/polls/components/AbstractPollCreate.js b/react/features/polls/components/AbstractPollCreate.js index 0f2f1d17fd..8498956739 100644 --- a/react/features/polls/components/AbstractPollCreate.js +++ b/react/features/polls/components/AbstractPollCreate.js @@ -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) => (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) => (pro } const newAnswers = [ ...answers ]; + sendAnalytics(createPollEvent('option.removed')); newAnswers.splice(i, 1); setAnswers(newAnswers); }); @@ -105,6 +107,7 @@ const AbstractPollCreate = (Component: AbstractComponent) => (pro question, answers: filteredAnswers }); + sendAnalytics(createPollEvent('created')); setCreateMode(false); diff --git a/react/features/polls/components/AbstractPollResults.js b/react/features/polls/components/AbstractPollResults.js index c49b4e6802..1be0209a4c 100644 --- a/react/features/polls/components/AbstractPollResults.js +++ b/react/features/polls/components/AbstractPollResults.js @@ -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) => (pr const [ showDetails, setShowDetails ] = useState(false); const toggleIsDetailed = useCallback(() => { + sendAnalytics(createPollEvent('vote.detailsViewed')); setShowDetails(!showDetails); }); @@ -107,6 +109,7 @@ const AbstractPollResults = (Component: AbstractComponent) => (pr answers: new Array(pollDetails.answers.length).fill(false) }); dispatch(retractVote(pollId)); + sendAnalytics(createPollEvent('vote.changed')); }, [ pollId, localId, localName, pollDetails ]); const { t } = useTranslation();