Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(heatmaps): instrument heatmap mode usage and load failures (#68190)

Paul D'Ambrac9eac2d2d33c
diff --git a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts
index f66321d33863..c66ee86efe29 100644
--- a/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts
+++ b/frontend/src/scenes/heatmaps/components/heatmapsBrowserLogic.ts
@@ -319,6 +319,8 @@ export const heatmapsBrowserLogic = kea<heatmapsBrowserLogicType>([
},
onIframeLoad: () => {
+ actions.stopTrackingLoading()
+
// it should be impossible to load an iframe without a dataUrl
// right?!
const url = values.dataUrl ?? ''
@@ -376,6 +378,11 @@ export const heatmapsBrowserLogic = kea<heatmapsBrowserLogicType>([
cache.disposables.add(() => {
const timerId = setTimeout(() => {
+ // this timer also runs on scenes that never mount an iframe
+ // (screenshot detail, the new-heatmap form), so only capture when one exists
+ if (document.getElementById('heatmap-iframe')) {
+ posthog.capture('in-app heatmap load failed')
+ }
actions.setIframeBanner({
level: 'error',
message: 'The heatmap failed to load (or is very slow).',
diff --git a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx
index 19acf2c17939..9fc87a3eff07 100644
--- a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx
+++ b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapScene.tsx
@@ -45,6 +45,7 @@ export function HeatmapScene({ id }: { id: string }): JSX.Element {
updateHeatmap,
onIframeLoad,
setScreenshotLoaded,
+ setScreenshotError,
exportHeatmap,
setContainerWidth,
} = useActions(logic)
@@ -192,10 +193,12 @@ export function HeatmapScene({ id }: { id: string }): JSX.Element {
}}
onLoad={() => {
setScreenshotLoaded(true)
+ setScreenshotError(null)
}}
className="rounded-b-lg border-l border-r border-b"
onError={() => {
- console.error('Failed to load screenshot')
+ setScreenshotLoaded(false)
+ setScreenshotError('The screenshot failed to load.')
}}
/>
</>
diff --git a/frontend/src/scenes/heatmaps/scenes/heatmap/heatmapLogic.ts b/frontend/src/scenes/heatmaps/scenes/heatmap/heatmapLogic.ts
index b0ffd604a3f2..ff32116b4901 100644
--- a/frontend/src/scenes/heatmaps/scenes/heatmap/heatmapLogic.ts
+++ b/frontend/src/scenes/heatmaps/scenes/heatmap/heatmapLogic.ts
@@ -1,5 +1,6 @@
import { actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
import { router } from 'kea-router'
+import posthog from 'posthog-js'
import api from 'lib/api'
import { exportsLogic } from 'lib/components/ExportButton/exportsLogic'
@@ -150,6 +151,10 @@ export const heatmapLogic = kea<heatmapLogicType>([
actions.setBlockConsentModals(item.block_consent_modals ?? false)
actions.snapshotSavedBlockConsentModals(item.block_consent_modals ?? false)
actions.setType(item.type)
+ posthog.capture('in-app heatmap viewed', {
+ heatmap_type: item.type,
+ heatmap_status: item.status,
+ })
if (item.type === 'screenshot') {
const desiredWidth = values.widthOverride
if (item.status === 'completed' && item.has_content) {
@@ -255,6 +260,7 @@ export const heatmapLogic = kea<heatmapLogicType>([
block_consent_modals: values.blockConsentModals,
}
const created = await api.savedHeatmaps.create(data)
+ posthog.capture('in-app heatmap created', { heatmap_type: values.type })
actions.loadSavedHeatmaps()
// Navigate to the created heatmap detail page
router.actions.push(`/heatmaps/${created.short_id}`)
@@ -316,6 +322,16 @@ export const heatmapLogic = kea<heatmapLogicType>([
actions.regenerateScreenshot()
}
},
+ setScreenshotLoaded: ({ screenshotLoaded }) => {
+ if (screenshotLoaded) {
+ posthog.capture('in-app heatmap screenshot loaded', { width: values.widthOverride })
+ }
+ },
+ setScreenshotError: ({ error }) => {
+ if (error) {
+ posthog.capture('in-app heatmap screenshot failed', { error })
+ }
+ },
exportHeatmap: () => {
if ((values.type === 'screenshot' && !values.screenshotUrl) || (!values.displayUrl && !values.dataUrl)) {
return