Skip to content

Commit

Permalink
add analytics events for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
daveajrussell committed Oct 25, 2024
1 parent 491bd1b commit 42371f9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/browser/modules/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ export function App(props: any) {
props.bus && props.bus.send(initAction.type, initAction)
}, [props.bus])

useEffect(() => {
if (!isRunningE2ETest() && props.telemetrySettings.allowUserStats) {
const hasTriedPreviewUI =
localStorage.getItem('hasTriedPreviewUI') === 'true'
segmentTrackCallback &&
segmentTrackCallback.current &&
segmentTrackCallback.current({
category: 'preview',
label: 'PREVIEW_PAGE_LOAD',
data: { previewUI: false, hasTriedPreviewUI }
})
}
}, [props.telemetrySettings.allowUserStats])

const {
browserSyncAuthStatus,
browserSyncConfig,
Expand Down
22 changes: 16 additions & 6 deletions src/browser/modules/Stream/PlayFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { getEdition, isEnterprise } from 'shared/modules/dbMeta/dbMetaDuck'
import { DARK_THEME } from 'shared/modules/settings/settingsDuck'
import { LAST_GUIDE_SLIDE } from 'shared/modules/udc/udcDuck'
import { PreviewFrame } from './StartPreviewFrame'
import { getTelemetrySettings, TelemetrySettings } from 'shared/utils/selectors'

const AuraPromotion = () => {
const theme = useContext(ThemeContext)
Expand Down Expand Up @@ -89,13 +90,15 @@ type PlayFrameProps = {
showPromotion: boolean
isFullscreen: boolean
isCollapsed: boolean
telemetrySettings: TelemetrySettings
}
export function PlayFrame({
stack,
bus,
showPromotion,
isFullscreen,
isCollapsed
isCollapsed,
telemetrySettings
}: PlayFrameProps): JSX.Element {
const [stackIndex, setStackIndex] = useState(0)
const [atSlideStart, setAtSlideStart] = useState<boolean | null>(null)
Expand Down Expand Up @@ -124,7 +127,8 @@ export function PlayFrame({
bus,
onSlide,
initialPlay,
showPromotion
showPromotion,
telemetrySettings
)
if (stillMounted) {
setInitialPlay(false)
Expand Down Expand Up @@ -207,7 +211,8 @@ function generateContent(
bus: Bus,
onSlide: any,
shouldUseSlidePointer: boolean,
showPromotion = false
showPromotion = false,
telemetrySettings: TelemetrySettings
): Content | Promise<Content> {
// Not found
if (stackFrame.response && stackFrame.response.status === 404) {
Expand Down Expand Up @@ -296,11 +301,15 @@ function generateContent(
const updatedContent =
isPlayStart && showPromotion ? (
<>
{isPreviewAvailable ? <PreviewFrame /> : content}
{isPreviewAvailable ? (
<PreviewFrame telemetrySettings={telemetrySettings} />
) : (
content
)}
<AuraPromotion />
</>
) : isPreviewAvailable ? (
<PreviewFrame />
<PreviewFrame telemetrySettings={telemetrySettings} />
) : (
content
)
Expand Down Expand Up @@ -383,7 +392,8 @@ const mapStateToProps = (state: GlobalState) => ({
(getEdition(state) !== null &&
!isEnterprise(state) &&
!isConnectedAuraHost(state)) ||
inDesktop(state)
inDesktop(state),
telemetrySettings: getTelemetrySettings(state)
})

export default connect(mapStateToProps)(withBus(PlayFrame))
56 changes: 53 additions & 3 deletions src/browser/modules/Stream/StartPreviewFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react'
import React, { useRef } from 'react'
import { isRunningE2ETest } from 'services/utils'
import { TelemetrySettings } from 'shared/utils/selectors'
import { MetricsData } from '../Segment'

export const navigateToPreview = (): void => {
const path = window.location.pathname
Expand All @@ -26,7 +29,51 @@ export const navigateToPreview = (): void => {
}
}

export const PreviewFrame = () => {
const useTrackAndNavigateToPreview = (
telemetrySettings: TelemetrySettings
): (() => void) => {
const segmentTrackCallback = useRef((_: MetricsData) => _)
const path = window.location.pathname

return () => {
if (!path.endsWith('/preview/')) {
if (!isRunningE2ETest() && telemetrySettings.allowUserStats) {
const now = Date.now()
localStorage.setItem('hasTriedPreviewUI', 'true')

const timeSinceLastSwitchMs =
localStorage.getItem('timeSinceLastSwitchMs') ?? null
localStorage.setItem('timeSinceLastSwitchMs', now.toString())

let timeSinceLastSwitch = null
if (timeSinceLastSwitchMs !== null) {
timeSinceLastSwitch = now - parseInt(timeSinceLastSwitchMs)
}

segmentTrackCallback &&
segmentTrackCallback.current &&
segmentTrackCallback.current({
category: 'preview',
label: 'PREVIEW_UI_SWITCH',
data: {
switchedTo: 'preview',
timeSinceLastSwitch: timeSinceLastSwitch ?? 0
}
})
}

navigateToPreview()
}
}
}

type PreviewFrameProps = {
telemetrySettings: TelemetrySettings
}
export const PreviewFrame = ({ telemetrySettings }: PreviewFrameProps) => {
const trackAndNavigateToPreview =
useTrackAndNavigateToPreview(telemetrySettings)

return (
<>
<div className="teasers">
Expand All @@ -36,7 +83,10 @@ export const PreviewFrame = () => {
<p>
Switch to the preview experience to access all the latest features.
</p>
<button onClick={navigateToPreview} className="btn btn-advertise">
<button
onClick={trackAndNavigateToPreview}
className="btn btn-advertise"
>
{"Let's go"}
</button>
</div>
Expand Down

0 comments on commit 42371f9

Please sign in to comment.