Skip to content

Commit 42371f9

Browse files
committed
add analytics events for preview
1 parent 491bd1b commit 42371f9

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
lines changed

src/browser/modules/App/App.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ export function App(props: any) {
149149
props.bus && props.bus.send(initAction.type, initAction)
150150
}, [props.bus])
151151

152+
useEffect(() => {
153+
if (!isRunningE2ETest() && props.telemetrySettings.allowUserStats) {
154+
const hasTriedPreviewUI =
155+
localStorage.getItem('hasTriedPreviewUI') === 'true'
156+
segmentTrackCallback &&
157+
segmentTrackCallback.current &&
158+
segmentTrackCallback.current({
159+
category: 'preview',
160+
label: 'PREVIEW_PAGE_LOAD',
161+
data: { previewUI: false, hasTriedPreviewUI }
162+
})
163+
}
164+
}, [props.telemetrySettings.allowUserStats])
165+
152166
const {
153167
browserSyncAuthStatus,
154168
browserSyncConfig,

src/browser/modules/Stream/PlayFrame.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { getEdition, isEnterprise } from 'shared/modules/dbMeta/dbMetaDuck'
4848
import { DARK_THEME } from 'shared/modules/settings/settingsDuck'
4949
import { LAST_GUIDE_SLIDE } from 'shared/modules/udc/udcDuck'
5050
import { PreviewFrame } from './StartPreviewFrame'
51+
import { getTelemetrySettings, TelemetrySettings } from 'shared/utils/selectors'
5152

5253
const AuraPromotion = () => {
5354
const theme = useContext(ThemeContext)
@@ -89,13 +90,15 @@ type PlayFrameProps = {
8990
showPromotion: boolean
9091
isFullscreen: boolean
9192
isCollapsed: boolean
93+
telemetrySettings: TelemetrySettings
9294
}
9395
export function PlayFrame({
9496
stack,
9597
bus,
9698
showPromotion,
9799
isFullscreen,
98-
isCollapsed
100+
isCollapsed,
101+
telemetrySettings
99102
}: PlayFrameProps): JSX.Element {
100103
const [stackIndex, setStackIndex] = useState(0)
101104
const [atSlideStart, setAtSlideStart] = useState<boolean | null>(null)
@@ -124,7 +127,8 @@ export function PlayFrame({
124127
bus,
125128
onSlide,
126129
initialPlay,
127-
showPromotion
130+
showPromotion,
131+
telemetrySettings
128132
)
129133
if (stillMounted) {
130134
setInitialPlay(false)
@@ -207,7 +211,8 @@ function generateContent(
207211
bus: Bus,
208212
onSlide: any,
209213
shouldUseSlidePointer: boolean,
210-
showPromotion = false
214+
showPromotion = false,
215+
telemetrySettings: TelemetrySettings
211216
): Content | Promise<Content> {
212217
// Not found
213218
if (stackFrame.response && stackFrame.response.status === 404) {
@@ -296,11 +301,15 @@ function generateContent(
296301
const updatedContent =
297302
isPlayStart && showPromotion ? (
298303
<>
299-
{isPreviewAvailable ? <PreviewFrame /> : content}
304+
{isPreviewAvailable ? (
305+
<PreviewFrame telemetrySettings={telemetrySettings} />
306+
) : (
307+
content
308+
)}
300309
<AuraPromotion />
301310
</>
302311
) : isPreviewAvailable ? (
303-
<PreviewFrame />
312+
<PreviewFrame telemetrySettings={telemetrySettings} />
304313
) : (
305314
content
306315
)
@@ -383,7 +392,8 @@ const mapStateToProps = (state: GlobalState) => ({
383392
(getEdition(state) !== null &&
384393
!isEnterprise(state) &&
385394
!isConnectedAuraHost(state)) ||
386-
inDesktop(state)
395+
inDesktop(state),
396+
telemetrySettings: getTelemetrySettings(state)
387397
})
388398

389399
export default connect(mapStateToProps)(withBus(PlayFrame))

src/browser/modules/Stream/StartPreviewFrame.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
* You should have received a copy of the GNU General Public License
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
import React from 'react'
20+
import React, { useRef } from 'react'
21+
import { isRunningE2ETest } from 'services/utils'
22+
import { TelemetrySettings } from 'shared/utils/selectors'
23+
import { MetricsData } from '../Segment'
2124

2225
export const navigateToPreview = (): void => {
2326
const path = window.location.pathname
@@ -26,7 +29,51 @@ export const navigateToPreview = (): void => {
2629
}
2730
}
2831

29-
export const PreviewFrame = () => {
32+
const useTrackAndNavigateToPreview = (
33+
telemetrySettings: TelemetrySettings
34+
): (() => void) => {
35+
const segmentTrackCallback = useRef((_: MetricsData) => _)
36+
const path = window.location.pathname
37+
38+
return () => {
39+
if (!path.endsWith('/preview/')) {
40+
if (!isRunningE2ETest() && telemetrySettings.allowUserStats) {
41+
const now = Date.now()
42+
localStorage.setItem('hasTriedPreviewUI', 'true')
43+
44+
const timeSinceLastSwitchMs =
45+
localStorage.getItem('timeSinceLastSwitchMs') ?? null
46+
localStorage.setItem('timeSinceLastSwitchMs', now.toString())
47+
48+
let timeSinceLastSwitch = null
49+
if (timeSinceLastSwitchMs !== null) {
50+
timeSinceLastSwitch = now - parseInt(timeSinceLastSwitchMs)
51+
}
52+
53+
segmentTrackCallback &&
54+
segmentTrackCallback.current &&
55+
segmentTrackCallback.current({
56+
category: 'preview',
57+
label: 'PREVIEW_UI_SWITCH',
58+
data: {
59+
switchedTo: 'preview',
60+
timeSinceLastSwitch: timeSinceLastSwitch ?? 0
61+
}
62+
})
63+
}
64+
65+
navigateToPreview()
66+
}
67+
}
68+
}
69+
70+
type PreviewFrameProps = {
71+
telemetrySettings: TelemetrySettings
72+
}
73+
export const PreviewFrame = ({ telemetrySettings }: PreviewFrameProps) => {
74+
const trackAndNavigateToPreview =
75+
useTrackAndNavigateToPreview(telemetrySettings)
76+
3077
return (
3178
<>
3279
<div className="teasers">
@@ -36,7 +83,10 @@ export const PreviewFrame = () => {
3683
<p>
3784
Switch to the preview experience to access all the latest features.
3885
</p>
39-
<button onClick={navigateToPreview} className="btn btn-advertise">
86+
<button
87+
onClick={trackAndNavigateToPreview}
88+
className="btn btn-advertise"
89+
>
4090
{"Let's go"}
4191
</button>
4292
</div>

0 commit comments

Comments
 (0)