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.

chore(web-analytics): Clean up the heatmaps UX (#58398)

Jordan Mryyan6b91208a7485
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 98a66ae14e12..5a1f9a6b63d5 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -4271,13 +4271,13 @@ snapshots:
scenes-app-heatmap--iframe-example--light:
hash: v1.k794b7964.82d72b4b351af7a90c3fa41ca60e5b90faf7b89c5a05f9e420fdf8a815161101.S0CiHD71oZXhhHC1XK4aSh505GVqf4n7aY_Hd1WeBPU
scenes-app-heatmap--new--dark:
- hash: v1.k794b7964.d2d666ce58722b5bc91dbcdfeb49e447af73c55d896bd193e7c32c565c65a010.O6EMeGiUajUC9O90fgPQu6__7JWaUW7n-lk1PO8PhDA
+ hash: v1.k794b7964.eebfffb6141fa152d17e856998a2ffd28a6c32594fdfd964bef560c55b6c093d.atMcJIWTo4O4JsB-88fdGTG8tGKqkEM_6aaz4hgHGDI
scenes-app-heatmap--new--light:
- hash: v1.k794b7964.1b3cb1d976938020551a82055a436e2a0bebd4d4a351c15798847c374440cbb6.FxofkfnWZvbvJp38hO_9eXBbZLzJR5WKggGXPOxbixU
+ hash: v1.k794b7964.db738b49d015e243254ad61c075dc056b7f806cfc5c6d824f0c182db579a6b85.IVRJ88fouAhqtoZruYcl3_8wKpNtZeI6ui1H87BDp4w
scenes-app-heatmap-new--new-form--dark:
- hash: v1.k794b7964.d2d666ce58722b5bc91dbcdfeb49e447af73c55d896bd193e7c32c565c65a010.lmkeEiS0NqXV_HJSYwI16688X8qgl0WFpgU0NOQBBjc
+ hash: v1.k794b7964.eebfffb6141fa152d17e856998a2ffd28a6c32594fdfd964bef560c55b6c093d.zWqPSEmr4pX4SQ7fJEYL5iTHi4FFTIeyvk5VRhTMuOA
scenes-app-heatmap-new--new-form--light:
- hash: v1.k794b7964.1b3cb1d976938020551a82055a436e2a0bebd4d4a351c15798847c374440cbb6.xI4STzYTFuGQc9s3WkzyumJptJ6HKZHGMLMPijUXcSs
+ hash: v1.k794b7964.db738b49d015e243254ad61c075dc056b7f806cfc5c6d824f0c182db579a6b85.snJbtyG1U2yFQds8t0Nsy-aFDAYzmrIctCghjFL97nA
scenes-app-heatmaps-saved--list--dark:
hash: v1.k794b7964.7ad8cc210b80f81252bc578e73d81d34da03711247d59d3a6f22d896f1bf8030.d381UYxSFqzSbkHYWMVXUgAe-IUm85hI55Od2MEn8Z8
scenes-app-heatmaps-saved--list--light:
diff --git a/frontend/src/scenes/heatmaps/components/HeatmapsForbiddenURL.tsx b/frontend/src/scenes/heatmaps/components/HeatmapsForbiddenURL.tsx
index 402060dd6506..1d7b0186756f 100644
--- a/frontend/src/scenes/heatmaps/components/HeatmapsForbiddenURL.tsx
+++ b/frontend/src/scenes/heatmaps/components/HeatmapsForbiddenURL.tsx
@@ -1,22 +1,75 @@
-import { useValues } from 'kea'
+import { useActions, useValues } from 'kea'
+import { useMemo } from 'react'
+import { IconPlus } from '@posthog/icons'
import { LemonBanner } from '@posthog/lemon-ui'
-import { AuthorizedUrlList } from 'lib/components/AuthorizedUrlList/AuthorizedUrlList'
-import { AuthorizedUrlListType } from 'lib/components/AuthorizedUrlList/authorizedUrlListLogic'
+import {
+ AuthorizedUrlListType,
+ authorizedUrlListLogic,
+ defaultAuthorizedUrlProperties,
+ sanitizePossibleWildCardedURL,
+ validateProposedUrl,
+} from 'lib/components/AuthorizedUrlList/authorizedUrlListLogic'
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { heatmapLogic } from 'scenes/heatmaps/scenes/heatmap/heatmapLogic'
+const HOST_WILDCARD_REGEX = /^https?:\/\/[^/]*\*/
+
+function deriveAuthorizationCandidate(dataUrl: string): string | null {
+ if (HOST_WILDCARD_REGEX.test(dataUrl)) {
+ const match = dataUrl.match(/^(https?:\/\/[^/]+)/)
+ return match ? match[1] : null
+ }
+ try {
+ return sanitizePossibleWildCardedURL(dataUrl).origin
+ } catch {
+ return null
+ }
+}
+
export function HeatmapsForbiddenURL(): JSX.Element {
- const { dataUrl } = useValues(heatmapLogic)
+ const { dataUrl } = useValues(heatmapLogic({ id: 'new' }))
+ const logic = authorizedUrlListLogic({
+ ...defaultAuthorizedUrlProperties,
+ type: AuthorizedUrlListType.TOOLBAR_URLS,
+ })
+ const { authorizedUrls } = useValues(logic)
+ const { addUrl } = useActions(logic)
+
+ const { urlToAuthorize, validationError } = useMemo(() => {
+ if (!dataUrl) {
+ return { urlToAuthorize: null, validationError: null }
+ }
+ const candidate = deriveAuthorizationCandidate(dataUrl)
+ if (!candidate) {
+ return { urlToAuthorize: null, validationError: 'Enter a valid URL to authorize' }
+ }
+ const error = validateProposedUrl(candidate, authorizedUrls, false, true)
+ return { urlToAuthorize: candidate, validationError: error ?? null }
+ }, [dataUrl, authorizedUrls])
return (
- <div className="flex-1 gap-y-4 my-2">
- <LemonBanner type="error">
- {dataUrl} is not an authorized URL. Please add it to the list of authorized URLs to view heatmaps on
- this page.
+ <div className="my-2">
+ <LemonBanner
+ type="error"
+ action={
+ urlToAuthorize && !validationError
+ ? {
+ children: 'Authorize URL',
+ icon: <IconPlus />,
+ onClick: () => {
+ addUrl(urlToAuthorize)
+ lemonToast.success(`Authorized ${urlToAuthorize}`)
+ },
+ 'data-attr': 'heatmaps-authorize-url',
+ }
+ : undefined
+ }
+ >
+ {dataUrl} is not an authorized URL.
+ {validationError ? <> {validationError}.</> : null}
</LemonBanner>
- <h4 className="my-4">Authorized Toolbar URLs</h4>
- <AuthorizedUrlList type={AuthorizedUrlListType.TOOLBAR_URLS} />
</div>
)
}
diff --git a/frontend/src/scenes/heatmaps/components/HeatmapsInfo.tsx b/frontend/src/scenes/heatmaps/components/HeatmapsInfo.tsx
deleted file mode 100644
index 6c96fc37f737..000000000000
--- a/frontend/src/scenes/heatmaps/components/HeatmapsInfo.tsx
+++ /dev/null
@@ -1,69 +0,0 @@
-import { useActions, useValues } from 'kea'
-
-import { LemonBanner, LemonButton, LemonSkeleton } from '@posthog/lemon-ui'
-
-import { DetectiveHog } from 'lib/components/hedgehogs'
-import { heatmapLogic } from 'scenes/heatmaps/scenes/heatmap/heatmapLogic'
-
-import { heatmapsBrowserLogic } from './heatmapsBrowserLogic'
-
-export function HeatmapsInfoBanner(): JSX.Element {
- return (
- <div className="flex items-center flex-wrap gap-6">
- <div className="w-50">
- <DetectiveHog className="w-full h-full" />
- </div>
-
- <div className="flex-1">
- <h2>Welcome to Heatmaps</h2>
- <p>
- Heatmaps are powered by the embedded JavaScript SDK and allow you to see a range of user
- interactions directly on your website via the Toolbar.
- </p>
- <p>
- You can also view heatmaps for any page on your website by entering the URL above. As long as the
- page has the PostHog Toolbar installed, and can be loaded in an iframe, you can view heatmaps for
- it.
- </p>
- </div>
- </div>
- )
-}
-
-export function HeatmapsUrlsList(): JSX.Element {
- const { topUrls, topUrlsLoading, noPageviews } = useValues(heatmapsBrowserLogic)
-
- const { setDisplayUrl } = useActions(heatmapLogic)
-
- return (
- <div className="flex-1 flex items-center overflow-y-auto">
- <div className=" w-full">
- <div className="gap-y-px p-2 border bg-surface-primary rounded">
- {topUrlsLoading ? (
- <LemonSkeleton className="h-10" repeat={10} />
- ) : noPageviews ? (
- <LemonBanner type="info">
- No pageview events have been received yet. Once you have some data, you'll see the most
- viewed pages here.
- </LemonBanner>
- ) : (
- <>
- <span className="text-sm font-medium text-muted ml-2">Most viewed pages:</span>
- {topUrls?.map(({ url }) => (
- <LemonButton
- key={url}
- fullWidth
- onClick={() => {
- setDisplayUrl(url)
- }}
- >
- {url}
- </LemonButton>
- ))}
- </>
- )}
- </div>
- </div>
- </div>
- )
-}
diff --git a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx
index 6ed6a8d88e5f..e94b6d6d5624 100644
--- a/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx
+++ b/frontend/src/scenes/heatmaps/scenes/heatmap/HeatmapNewScene.tsx
@@ -6,10 +6,11 @@ import { Spinner } from '@posthog/lemon-ui'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonInput } from 'lib/lemon-ui/LemonInput'
+import { LemonInputSelect } from 'lib/lemon-ui/LemonInputSelect/LemonInputSelect'
import { LemonRadio } from 'lib/lemon-ui/LemonRadio'
import { Link } from 'lib/lemon-ui/Link'
+import { heatmapsBrowserLogic } from 'scenes/heatmaps/components/heatmapsBrowserLogic'
import { HeatmapsForbiddenURL } from 'scenes/heatmaps/components/HeatmapsForbiddenURL'
-import { HeatmapsUrlsList } from 'scenes/heatmaps/components/HeatmapsInfo'
import { HeatmapsInvalidURL } from 'scenes/heatmaps/components/HeatmapsInvalidURL'
import { urls } from 'scenes/urls'
@@ -26,6 +27,7 @@ export function HeatmapNewScene(): JSX.Element {
const { loading, displayUrl, isDisplayUrlValid, type, name, dataUrl, isBrowserUrlAuthorized, displayUrlIsPattern } =
useValues(logic)
const { setDisplayUrl, setType, setName, createHeatmap, setDataUrl, setDataUrlUserTouched } = useActions(logic)
+ const { topUrls, topUrlsLoading, noPageviews } = useValues(heatmapsBrowserLogic)
const debouncedOnNameChange = useDebouncedCallback((name: string) => {
setName(name)
@@ -57,7 +59,28 @@ export function HeatmapNewScene(): JSX.Element {
}}
/>
<SceneSection title="Page URL" description="URL to your website">
- <LemonInput value={displayUrl || ''} onChange={setDisplayUrl} placeholder="https://www.example.com" />
+ <LemonInputSelect
+ mode="single"
+ allowCustomValues
+ disableEditing
+ fullWidth
+ placeholder="https://www.example.com"
+ loading={topUrlsLoading}
+ value={displayUrl ? [displayUrl] : []}
+ onChange={(next) => setDisplayUrl(next[0] ?? '')}
+ options={(topUrls ?? []).map(({ url }) => ({
+ key: url,
+ label: url,
+ labelComponent: (
+ <span className="block min-w-0 max-w-full truncate ph-no-capture" title={url}>
+ {url}
+ </span>
+ ),
+ }))}
+ title={topUrls && topUrls.length > 0 ? 'Most viewed pages' : undefined}
+ popoverClassName="max-w-0"
+ data-attr="heatmap-new-page-url"
+ />
{displayUrl && !isDisplayUrlValid ? (
displayUrlIsPattern ? (
<LemonBanner type="error" className="mt-2">
@@ -67,7 +90,9 @@ export function HeatmapNewScene(): JSX.Element {
<HeatmapsInvalidURL />
)
) : null}
- {!displayUrl && <HeatmapsUrlsList />}
+ {!displayUrl && noPageviews && !topUrlsLoading ? (
+ <div className="text-xs text-muted mt-1">No pageview events have been received yet.</div>
+ ) : null}
</SceneSection>
<SceneDivider />
<SceneSection