diff --git a/react/features/analytics/AnalyticsEvents.js b/react/features/analytics/AnalyticsEvents.js index 931efc9920..1d4f92cb09 100644 --- a/react/features/analytics/AnalyticsEvents.js +++ b/react/features/analytics/AnalyticsEvents.js @@ -427,6 +427,25 @@ export function createRecordingEvent(action, type, value) { }; } +/** + * Creates an event which indicates that the same conference has been rejoined. + * + * @param {string} url - The full conference URL. + * @param {number} lastConferenceDuration - How many seconds user stayed in the previous conference. + * @param {number} timeSinceLeft - How many seconds since the last conference was left. + * @returns {Object} The event in a format suitable for sending via sendAnalytics. + */ +export function createRejoinedEvent({ url, lastConferenceDuration, timeSinceLeft }) { + return { + action: 'rejoined', + attributes: { + lastConferenceDuration, + timeSinceLeft, + url + } + }; +} + /** * Creates an event which specifies that the "confirm" button on the remote * mute dialog has been clicked. diff --git a/react/features/app/components/AbstractApp.js b/react/features/app/components/AbstractApp.js index 4d07ddfc2f..b81461caf1 100644 --- a/react/features/app/components/AbstractApp.js +++ b/react/features/app/components/AbstractApp.js @@ -7,6 +7,9 @@ import { toURLString } from '../../base/util'; import '../../follow-me'; import { OverlayContainer } from '../../overlay'; +// Enable rejoin analytics +import '../../rejoin'; + import { appNavigate } from '../actions'; import { getDefaultURL } from '../functions'; diff --git a/react/features/rejoin/index.js b/react/features/rejoin/index.js new file mode 100644 index 0000000000..d436892893 --- /dev/null +++ b/react/features/rejoin/index.js @@ -0,0 +1 @@ +import './middleware'; diff --git a/react/features/rejoin/middleware.js b/react/features/rejoin/middleware.js new file mode 100644 index 0000000000..fb8158ae27 --- /dev/null +++ b/react/features/rejoin/middleware.js @@ -0,0 +1,27 @@ +import { createRejoinedEvent, sendAnalytics } from '../analytics'; + +import { StateListenerRegistry } from '../base/redux'; + +StateListenerRegistry.register( + /* selector */ state => { + const recentList = state['features/recent-list']; + + // Return the most recent conference entry + return recentList && recentList.length && recentList[recentList.length - 1]; + }, + // eslint-disable-next-line no-empty-pattern + /* listener */ (newMostRecent, { }, prevMostRecent) => { + if (prevMostRecent && newMostRecent) { + + // Send the rejoined event just before the duration is reset on the most recent entry + if (prevMostRecent.conference === newMostRecent.conference && newMostRecent.duration === 0) { + sendAnalytics( + createRejoinedEvent({ + lastConferenceDuration: prevMostRecent.duration / 1000, + timeSinceLeft: (Date.now() - (prevMostRecent.date + prevMostRecent.duration)) / 1000, + url: prevMostRecent.conference + }) + ); + } + } + });