Pārlūkot izejas kodu

feat(polls): Add analytics for polls

master
Vlad Piersec 3 gadus atpakaļ
vecāks
revīzija
ebb0a206f1

+ 22
- 0
react/features/analytics/AnalyticsEvents.js Parādīt failu

@@ -376,6 +376,28 @@ export function createPinnedEvent(action, participantId, attributes) {
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 402
  * Creates an event which indicates that a button in the profile panel was
381 403
  * clicked.

+ 4
- 0
react/features/polls/components/AbstractPollAnswer.js Parādīt failu

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

+ 5
- 2
react/features/polls/components/AbstractPollCreate.js Parādīt failu

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

+ 3
- 0
react/features/polls/components/AbstractPollResults.js Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt