Browse Source

feat(recording): Add analytics.

master
hristoterezov 7 years ago
parent
commit
d3bf0b7862

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

350
     };
350
     };
351
 }
351
 }
352
 
352
 
353
+/**
354
+ * Creates an event which indicates that an action related to recording has
355
+ * occured.
356
+ *
357
+ * @param {string} action - The action (e.g. 'start' or 'stop').
358
+ * @param {string} type - The recording type (e.g. 'file' or 'live').
359
+ * @param {number} value - The duration of the recording in seconds (for stop
360
+ * action).
361
+ * @returns {Object} The event in a format suitable for sending via
362
+ * sendAnalytics.
363
+ */
364
+export function createRecordingEvent(action, type, value) {
365
+    return {
366
+        action,
367
+        actionSubject: `recording.${type}`,
368
+        attributes: {
369
+            value
370
+        }
371
+    };
372
+}
373
+
353
 /**
374
 /**
354
  * Creates an event which specifies that the "confirm" button on the remote
375
  * Creates an event which specifies that the "confirm" button on the remote
355
  * mute dialog has been clicked.
376
  * mute dialog has been clicked.

+ 9
- 3
react/features/recording/actions.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import JitsiMeetJS from '../base/lib-jitsi-meet';
4
-
3
+import JitsiMeetJS, { JitsiRecordingConstants } from '../base/lib-jitsi-meet';
5
 import {
4
 import {
6
     hideNotification,
5
     hideNotification,
7
     showErrorNotification,
6
     showErrorNotification,
138
  * }}
137
  * }}
139
  */
138
  */
140
 export function updateRecordingSessionData(session: Object) {
139
 export function updateRecordingSessionData(session: Object) {
140
+    const status = session.getStatus();
141
+    const timestamp
142
+        = status === JitsiRecordingConstants.status.ON
143
+            ? Date.now() / 1000
144
+            : undefined;
145
+
141
     return {
146
     return {
142
         type: RECORDING_SESSION_UPDATED,
147
         type: RECORDING_SESSION_UPDATED,
143
         sessionData: {
148
         sessionData: {
145
             id: session.getID(),
150
             id: session.getID(),
146
             liveStreamViewURL: session.getLiveStreamViewURL(),
151
             liveStreamViewURL: session.getLiveStreamViewURL(),
147
             mode: session.getMode(),
152
             mode: session.getMode(),
148
-            status: session.getStatus()
153
+            status,
154
+            timestamp
149
         }
155
         }
150
     };
156
     };
151
 }
157
 }

+ 15
- 0
react/features/recording/middleware.js View File

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
+
4
+import {
5
+    createRecordingEvent,
6
+    sendAnalytics
7
+} from '../analytics';
3
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
8
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
4
 import { CONFERENCE_WILL_JOIN, getCurrentConference } from '../base/conference';
9
 import { CONFERENCE_WILL_JOIN, getCurrentConference } from '../base/conference';
5
 import JitsiMeetJS, {
10
 import JitsiMeetJS, {
117
                 && (!oldSessionData || oldSessionData.status !== ON)
122
                 && (!oldSessionData || oldSessionData.status !== ON)
118
                 && updatedSessionData.mode
123
                 && updatedSessionData.mode
119
                     === JitsiRecordingConstants.mode.FILE) {
124
                     === JitsiRecordingConstants.mode.FILE) {
125
+                sendAnalytics(createRecordingEvent('start', 'file'));
120
                 dispatch(playSound(RECORDING_ON_SOUND_ID));
126
                 dispatch(playSound(RECORDING_ON_SOUND_ID));
121
             } else if (updatedSessionData.status === OFF
127
             } else if (updatedSessionData.status === OFF
122
                 && (!oldSessionData || oldSessionData.status !== OFF)) {
128
                 && (!oldSessionData || oldSessionData.status !== OFF)) {
126
 
132
 
127
                 if (updatedSessionData.mode
133
                 if (updatedSessionData.mode
128
                         === JitsiRecordingConstants.mode.FILE) {
134
                         === JitsiRecordingConstants.mode.FILE) {
135
+                    let duration = 0;
136
+
137
+                    // eslint-disable-next-line max-depth
138
+                    if (oldSessionData && oldSessionData.timestamp) {
139
+                        duration
140
+                            = (Date.now() / 1000) - oldSessionData.timestamp;
141
+                    }
142
+                    sendAnalytics(
143
+                        createRecordingEvent('stop', 'file', duration));
129
                     dispatch(stopSound(RECORDING_ON_SOUND_ID));
144
                     dispatch(stopSound(RECORDING_ON_SOUND_ID));
130
                     dispatch(playSound(RECORDING_OFF_SOUND_ID));
145
                     dispatch(playSound(RECORDING_OFF_SOUND_ID));
131
                 }
146
                 }

Loading…
Cancel
Save