Browse Source

feat(polls): Add analytics for polls

master
Vlad Piersec 3 years ago
parent
commit
ebb0a206f1

+ 22
- 0
react/features/analytics/AnalyticsEvents.js View File

376
     };
376
     };
377
 }
377
 }
378
 
378
 
379
+/**
380
+ * Creates a poll event.
381
+ * The following events will be created:
382
+ * - poll.created
383
+ * - poll.vote.checked
384
+ * - poll.vote.sent
385
+ * - poll.vote.skipped
386
+ * - poll.vote.detailsViewed
387
+ * - poll.vote.changed
388
+ * - poll.option.added
389
+ * - poll.option.moved
390
+ * - poll.option.removed.
391
+ *
392
+ * @param {string} action - The action.
393
+ * @returns {Object}
394
+ */
395
+export function createPollEvent(action) {
396
+    return {
397
+        action: `poll.${action}`
398
+    };
399
+}
400
+
379
 /**
401
 /**
380
  * Creates an event which indicates that a button in the profile panel was
402
  * Creates an event which indicates that a button in the profile panel was
381
  * clicked.
403
  * clicked.

+ 4
- 0
react/features/polls/components/AbstractPollAnswer.js View File

5
 import { useTranslation } from 'react-i18next';
5
 import { useTranslation } from 'react-i18next';
6
 import { useDispatch, useSelector } from 'react-redux';
6
 import { useDispatch, useSelector } from 'react-redux';
7
 
7
 
8
+import { sendAnalytics, createPollEvent } from '../../analytics';
8
 import { getLocalParticipant, getParticipantById } from '../../base/participants';
9
 import { getLocalParticipant, getParticipantById } from '../../base/participants';
9
 import { registerVote } from '../actions';
10
 import { registerVote } from '../actions';
10
 import { COMMAND_ANSWER_POLL } from '../constants';
11
 import { COMMAND_ANSWER_POLL } from '../constants';
60
 
61
 
61
         newCheckBoxStates[index] = state;
62
         newCheckBoxStates[index] = state;
62
         setCheckBoxState(newCheckBoxStates);
63
         setCheckBoxState(newCheckBoxStates);
64
+        sendAnalytics(createPollEvent('vote.checked'));
63
     }, [ checkBoxStates ]);
65
     }, [ checkBoxStates ]);
64
 
66
 
65
     const dispatch = useDispatch();
67
     const dispatch = useDispatch();
76
             answers: checkBoxStates
78
             answers: checkBoxStates
77
         });
79
         });
78
 
80
 
81
+        sendAnalytics(createPollEvent('vote.sent'));
79
         dispatch(registerVote(pollId, checkBoxStates));
82
         dispatch(registerVote(pollId, checkBoxStates));
80
 
83
 
81
         return false;
84
         return false;
83
 
86
 
84
     const skipAnswer = useCallback(() => {
87
     const skipAnswer = useCallback(() => {
85
         dispatch(registerVote(pollId, null));
88
         dispatch(registerVote(pollId, null));
89
+        sendAnalytics(createPollEvent('vote.skipped'));
86
 
90
 
87
     }, [ pollId ]);
91
     }, [ pollId ]);
88
 
92
 

+ 5
- 2
react/features/polls/components/AbstractPollCreate.js View File

5
 import { useTranslation } from 'react-i18next';
5
 import { useTranslation } from 'react-i18next';
6
 import { useSelector } from 'react-redux';
6
 import { useSelector } from 'react-redux';
7
 
7
 
8
+import { sendAnalytics, createPollEvent } from '../../analytics';
8
 import { getParticipantDisplayName } from '../../base/participants';
9
 import { getParticipantDisplayName } from '../../base/participants';
9
 import { COMMAND_NEW_POLL } from '../constants';
10
 import { COMMAND_NEW_POLL } from '../constants';
10
 
11
 
55
     });
56
     });
56
 
57
 
57
     const addAnswer = useCallback((i: ?number) => {
58
     const addAnswer = useCallback((i: ?number) => {
58
-
59
         const newAnswers = [ ...answers ];
59
         const newAnswers = [ ...answers ];
60
 
60
 
61
+        sendAnalytics(createPollEvent('option.added'));
61
         newAnswers.splice(typeof i === 'number' ? i : answers.length, 0, '');
62
         newAnswers.splice(typeof i === 'number' ? i : answers.length, 0, '');
62
         setAnswers(newAnswers);
63
         setAnswers(newAnswers);
63
     });
64
     });
64
 
65
 
65
     const moveAnswer = useCallback((i, j) => {
66
     const moveAnswer = useCallback((i, j) => {
66
         const newAnswers = [ ...answers ];
67
         const newAnswers = [ ...answers ];
67
-
68
         const answer = answers[i];
68
         const answer = answers[i];
69
 
69
 
70
+        sendAnalytics(createPollEvent('option.moved'));
70
         newAnswers.splice(i, 1);
71
         newAnswers.splice(i, 1);
71
         newAnswers.splice(j, 0, answer);
72
         newAnswers.splice(j, 0, answer);
72
         setAnswers(newAnswers);
73
         setAnswers(newAnswers);
78
         }
79
         }
79
         const newAnswers = [ ...answers ];
80
         const newAnswers = [ ...answers ];
80
 
81
 
82
+        sendAnalytics(createPollEvent('option.removed'));
81
         newAnswers.splice(i, 1);
83
         newAnswers.splice(i, 1);
82
         setAnswers(newAnswers);
84
         setAnswers(newAnswers);
83
     });
85
     });
105
             question,
107
             question,
106
             answers: filteredAnswers
108
             answers: filteredAnswers
107
         });
109
         });
110
+        sendAnalytics(createPollEvent('created'));
108
 
111
 
109
         setCreateMode(false);
112
         setCreateMode(false);
110
 
113
 

+ 3
- 0
react/features/polls/components/AbstractPollResults.js View File

5
 import { useTranslation } from 'react-i18next';
5
 import { useTranslation } from 'react-i18next';
6
 import { useDispatch, useSelector } from 'react-redux';
6
 import { useDispatch, useSelector } from 'react-redux';
7
 
7
 
8
+import { sendAnalytics, createPollEvent } from '../../analytics';
8
 import { getLocalParticipant, getParticipantById } from '../../base/participants/functions';
9
 import { getLocalParticipant, getParticipantById } from '../../base/participants/functions';
9
 import { retractVote } from '../actions';
10
 import { retractVote } from '../actions';
10
 import { COMMAND_ANSWER_POLL } from '../constants';
11
 import { COMMAND_ANSWER_POLL } from '../constants';
54
 
55
 
55
     const [ showDetails, setShowDetails ] = useState(false);
56
     const [ showDetails, setShowDetails ] = useState(false);
56
     const toggleIsDetailed = useCallback(() => {
57
     const toggleIsDetailed = useCallback(() => {
58
+        sendAnalytics(createPollEvent('vote.detailsViewed'));
57
         setShowDetails(!showDetails);
59
         setShowDetails(!showDetails);
58
     });
60
     });
59
 
61
 
107
             answers: new Array(pollDetails.answers.length).fill(false)
109
             answers: new Array(pollDetails.answers.length).fill(false)
108
         });
110
         });
109
         dispatch(retractVote(pollId));
111
         dispatch(retractVote(pollId));
112
+        sendAnalytics(createPollEvent('vote.changed'));
110
     }, [ pollId, localId, localName, pollDetails ]);
113
     }, [ pollId, localId, localName, pollDetails ]);
111
 
114
 
112
     const { t } = useTranslation();
115
     const { t } = useTranslation();

Loading…
Cancel
Save