Browse Source

feat: send analytics event when conference is rejoined

j8
paweldomas 5 years ago
parent
commit
1c27f567ee

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

427
     };
427
     };
428
 }
428
 }
429
 
429
 
430
+/**
431
+ * Creates an event which indicates that the same conference has been rejoined.
432
+ *
433
+ * @param {string} url - The full conference URL.
434
+ * @param {number} lastConferenceDuration - How many seconds user stayed in the previous conference.
435
+ * @param {number} timeSinceLeft - How many seconds since the last conference was left.
436
+ * @returns {Object} The event in a format suitable for sending via sendAnalytics.
437
+ */
438
+export function createRejoinedEvent({ url, lastConferenceDuration, timeSinceLeft }) {
439
+    return {
440
+        action: 'rejoined',
441
+        attributes: {
442
+            lastConferenceDuration,
443
+            timeSinceLeft,
444
+            url
445
+        }
446
+    };
447
+}
448
+
430
 /**
449
 /**
431
  * Creates an event which specifies that the "confirm" button on the remote
450
  * Creates an event which specifies that the "confirm" button on the remote
432
  * mute dialog has been clicked.
451
  * mute dialog has been clicked.

+ 3
- 0
react/features/app/components/AbstractApp.js View File

7
 import '../../follow-me';
7
 import '../../follow-me';
8
 import { OverlayContainer } from '../../overlay';
8
 import { OverlayContainer } from '../../overlay';
9
 
9
 
10
+// Enable rejoin analytics
11
+import '../../rejoin';
12
+
10
 import { appNavigate } from '../actions';
13
 import { appNavigate } from '../actions';
11
 import { getDefaultURL } from '../functions';
14
 import { getDefaultURL } from '../functions';
12
 
15
 

+ 1
- 0
react/features/rejoin/index.js View File

1
+import './middleware';

+ 27
- 0
react/features/rejoin/middleware.js View File

1
+import { createRejoinedEvent, sendAnalytics } from '../analytics';
2
+
3
+import { StateListenerRegistry } from '../base/redux';
4
+
5
+StateListenerRegistry.register(
6
+    /* selector */ state => {
7
+        const recentList = state['features/recent-list'];
8
+
9
+        // Return the most recent conference entry
10
+        return recentList && recentList.length && recentList[recentList.length - 1];
11
+    },
12
+    // eslint-disable-next-line no-empty-pattern
13
+    /* listener */ (newMostRecent, { }, prevMostRecent) => {
14
+        if (prevMostRecent && newMostRecent) {
15
+
16
+            // Send the rejoined event just before the duration is reset on the most recent entry
17
+            if (prevMostRecent.conference === newMostRecent.conference && newMostRecent.duration === 0) {
18
+                sendAnalytics(
19
+                    createRejoinedEvent({
20
+                        lastConferenceDuration: prevMostRecent.duration / 1000,
21
+                        timeSinceLeft: (Date.now() - (prevMostRecent.date + prevMostRecent.duration)) / 1000,
22
+                        url: prevMostRecent.conference
23
+                    })
24
+                );
25
+            }
26
+        }
27
+    });

Loading…
Cancel
Save