Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(polls): Add analytics for polls

Vlad Piersecebb0a206f19a
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<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 ]);
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<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);
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<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();