: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(web-analytics): add heatmap capture settings ui (#102558)
Jordan Mryyan023c8adb14df
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 39650810766f..f461dc5d285b 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -10949,13 +10949,13 @@ snapshots:scenes-app-settings-environment--settings-environment-feature-flags--light:hash: v1.k794b7964.2254e82614b9ae96c0801fbe3657ee60cf94f03ed89ccef973ba931646dd02b6.KnVQosUnK2-W1vnz6CB_xsgqUDD6cq6U3hbl7Cm6z8Iscenes-app-settings-environment--settings-environment-heatmaps--dark:- hash: v1.k794b7964.56d4d5c292ebe5f9f9d4b50ea5971c349bfee6c568793196a89b708e0854128c.qruKvRiNvDGPiIFgoj86f7HqbuJTKsjQ2ZYylgETlLw+ hash: v1.k794b7964.80d38f67698046c091de56d8604a32b4ba8d2763b3cd893807d1a9137fa3f8ff.0CNdzzBd2C_sFGP8MVLbjmpadj2Smqrq7tytoedmBhEscenes-app-settings-environment--settings-environment-heatmaps--light:- hash: v1.k794b7964.51682ed4e0137094f4b04b0d640db418079717a20f6f1785fa529dc5889e0982.SjItpbYYDctTGcSRBFPy-QxFIjP3Ps_Am6w3p4-40d4+ hash: v1.k794b7964.01a2fcc9f12b37abe9734c9e86a6efd2b0f395d05a658e0bdcde6629b4772be3.42mMjpkDzzoIMIeY1LBSG_FeF1RvSKr-p-y17B2W-iUscenes-app-settings-environment--settings-environment-heatmaps-screenshot-cookie--dark:- hash: v1.k794b7964.47e7c9c63e39119de1fa0e82b279a5b57a62ee06f2ff89a5aa4fed345df5fa52.zElyJ5sL6qvHar4FcXKBDlwX-iPNfyRWiZJG4-pj8Jc+ hash: v1.k794b7964.573093b22817326871e7cad2d252c51c5b43e4f57cb9f401068faebe89c24356.iPBeYLJKYhbQyYNDIC0yAGVCviBulFU3jz7IYLvJdCMscenes-app-settings-environment--settings-environment-heatmaps-screenshot-cookie--light:- hash: v1.k794b7964.71b85d9e6f36e2124e6dcdc1c730d34c8decf294a925ddbb7a40f4cf54c1c1e3.Mx1ByTft2OS71PEi3g0HYYyb77DXuEWtu4R-9dtYfvI+ hash: v1.k794b7964.32b1f5f6d9cfb399cb097cb13ebe6b9106ee763f92aaf93a9e8fc364c2521f7d.cjrINU6otQ0ckqJ8tOJeoRd2PciUG3lQOeWA-bHE7poscenes-app-settings-environment--settings-environment-integrations--dark:hash: v1.k794b7964.bf31464f10d36bfd3279dabc491f218cb2963722f82bcbb493e5dc33d29c86b5.fbO-nOzwF7Wo3Hp8O9FbuDPU-9GXMErI99YgmcOUxI8scenes-app-settings-environment--settings-environment-integrations--light:diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 45c043cc93a5..298b17fdbc1d 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -208,6 +208,7 @@ export const FEATURE_FLAGS = {BILLING_SKIP_FORECASTING: 'billing-skip-forecasting', // owner: @zachEXPERIMENT_INTERVAL_TIMESERIES: 'experiments-interval-timeseries', // owner: @jurajmajerik #team-experimentsGATEWAY_PERSONAL_API_KEY: 'gateway-personal-api-key', // owner: #team-platform-features+ HEATMAPS_CAPTURE_ALLOWLIST_NOTICE: 'heatmaps-capture-allowlist-notice', // owner: #team-web-analytics, gates the pre-enforcement notice about heatmap capture URL rulesHEATMAPS_CLICKMAP_DISCRIMINATORS: 'heatmaps-clickmap-discriminators', // owner: #team-web-analyticsHEATMAPS_CLICKMAP_PAGINATION: 'heatmaps-clickmap-pagination', // owner: #team-web-analyticsHEATMAPS_COHORT_FILTER: 'heatmaps-cohort-filter', // owner: #team-web-analyticsdiff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsxindex bd7937fe7cef..acc2c753103b 100644--- a/frontend/src/scenes/settings/SettingsMap.tsx+++ b/frontend/src/scenes/settings/SettingsMap.tsx@@ -75,6 +75,7 @@ import { LogsMetricRulesSection } from 'products/logs/frontend/components/LogsMeimport { LogsRetentionSection } from 'products/logs/frontend/components/LogsRetention/LogsRetentionSection'import { LogsSamplingSection } from 'products/logs/frontend/components/LogsSampling/LogsSamplingSection'import { LogsFeatureFlagKeys } from 'products/logs/frontend/logsFeatureFlagKeys'+import { HeatmapCaptureSettings } from 'products/web_analytics/frontend/heatmaps/components/HeatmapCaptureSettings'import { HeatmapScreenshotCookieSettings } from 'products/web_analytics/frontend/heatmaps/components/HeatmapScreenshotCookieSettings'import { WorkflowsEmailTrackingConsentSettings } from 'products/workflows/frontend/scenes/settings/WorkflowsEmailTrackingConsentSettings'import { WorkflowsEngagementEventsSettings } from 'products/workflows/frontend/scenes/settings/WorkflowsEngagementEventsSettings'@@ -902,6 +903,15 @@ export const SETTINGS_MAP: SettingSection[] = ['cookie',],},+ {+ id: 'heatmaps-capture',+ title: 'Heatmap capture URLs',+ description: 'Choose which pages send heatmap data: every page, or only the URLs you list.',+ docsUrl: 'https://posthog.com/docs/toolbar/heatmaps',+ platformSupport: FEATURE_SUPPORT.heatmaps,+ component: <HeatmapCaptureSettings />,+ keywords: ['allow list', 'allowlist', 'url', 'capture', 'restrict'],+ },],},{diff --git a/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx b/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsxindex bec5eb5a169f..abd086adc55f 100644--- a/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx+++ b/frontend/src/scenes/settings/stories/SettingsEnvironment.stories.tsx@@ -44,6 +44,14 @@ const meta: Meta<StoryProps> = {has_secret: false,cookie_delivery_enabled: true,},+ '/api/projects/:id/heatmap_capture/settings/': {+ capture_mode: 'url_allowlist',+ url_allowlist: ['https://example.com/pricing'],+ enforcement_enabled: false,+ can_capture_all_urls: true,+ capture_url_limit: null,+ },+ '/api/projects/:id/heatmap_capture/pages/': { pages: [] },// The GitHub section fetches both on mount; unmocked, their error toasts land in the snapshot.'/api/projects/:id/integrations/github/available_installations/': {installations: [],diff --git a/frontend/src/scenes/settings/types.ts b/frontend/src/scenes/settings/types.tsindex b901998b3455..1189f350e209 100644--- a/frontend/src/scenes/settings/types.ts+++ b/frontend/src/scenes/settings/types.ts@@ -191,6 +191,7 @@ export type SettingId =| 'group-analytics'| 'heatmaps'| 'heatmap-screenshot-cookie'+ | 'heatmaps-capture'| 'hedgehog-mode'| 'homepage'| 'human-friendly-comparison-periods'diff --git a/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureAllowlistNotice.test.ts b/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureAllowlistNotice.test.tsnew file mode 100644index 000000000000..d9bc16c84ea3--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureAllowlistNotice.test.ts@@ -0,0 +1,19 @@+import { shouldShowHeatmapCaptureAllowlistNotice } from './HeatmapCaptureAllowlistNotice'+import { HeatmapCaptureMode } from './heatmapCaptureSettingsLogic'++describe('shouldShowHeatmapCaptureAllowlistNotice', () => {+ it.each<+ [string, { heatmapsOptIn: boolean; captureMode: HeatmapCaptureMode; enforcementEnabled: boolean }, boolean]+ >([+ [+ 'enabled, allowlist mode, not yet enforced',+ { heatmapsOptIn: true, captureMode: 'url_allowlist', enforcementEnabled: false },+ true,+ ],+ ['heatmaps off', { heatmapsOptIn: false, captureMode: 'url_allowlist', enforcementEnabled: false }, false],+ ['allow-all mode', { heatmapsOptIn: true, captureMode: 'all', enforcementEnabled: false }, false],+ ['already enforced', { heatmapsOptIn: true, captureMode: 'url_allowlist', enforcementEnabled: true }, false],+ ])('%s', (_name, params, expected) => {+ expect(shouldShowHeatmapCaptureAllowlistNotice(params)).toBe(expected)+ })+})diff --git a/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureAllowlistNotice.tsx b/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureAllowlistNotice.tsxnew file mode 100644index 000000000000..625b1f8161ea--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureAllowlistNotice.tsx@@ -0,0 +1,72 @@+import { useValues } from 'kea'+import { router } from 'kea-router'++import { LemonBanner, Link } from '@posthog/lemon-ui'++import { FEATURE_FLAGS } from 'lib/constants'+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'+import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'++import { HeatmapCaptureMode, heatmapCaptureSettingsLogic } from './heatmapCaptureSettingsLogic'++export function shouldShowHeatmapCaptureAllowlistNotice(params: {+ heatmapsOptIn: boolean+ captureMode: HeatmapCaptureMode+ enforcementEnabled: boolean+}): boolean {+ return params.heatmapsOptIn && params.captureMode === 'url_allowlist' && !params.enforcementEnabled+}++export function HeatmapCaptureAllowlistNotice(): JSX.Element | null {+ const { featureFlags } = useValues(featureFlagLogic)+ const { currentTeam, currentTeamId } = useValues(teamLogic)+ const { settings, urlAllowlist, canCaptureAllUrls, captureUrlLimit } = useValues(+ heatmapCaptureSettingsLogic({ teamId: currentTeamId ?? 0 })+ )++ if (!featureFlags[FEATURE_FLAGS.HEATMAPS_CAPTURE_ALLOWLIST_NOTICE] || !settings) {+ return null+ }++ if (+ !shouldShowHeatmapCaptureAllowlistNotice({+ heatmapsOptIn: !!currentTeam?.heatmaps_opt_in,+ captureMode: settings.capture_mode ?? 'url_allowlist',+ enforcementEnabled: settings.enforcement_enabled,+ })+ ) {+ return null+ }++ if (!canCaptureAllUrls) {+ return (+ <LemonBanner+ type="warning"+ dismissKey="heatmaps-capture-allowlist-notice"+ action={{ children: 'Upgrade', to: urls.organizationBilling() }}+ >+ {urlAllowlist.length === 0+ ? `When capture limits take effect, heatmaps stop collecting from every page. `+ : `When capture limits take effect, heatmaps only collect from your listed URLs (up to ${captureUrlLimit}). Every other page stops. `}+ <Link to={urls.settings('environment-heatmaps')}>Review capture URLs</Link> to choose which pages to+ keep.+ </LemonBanner>+ )+ }++ return (+ <LemonBanner+ type="warning"+ dismissKey="heatmaps-capture-allowlist-notice"+ action={{+ children: 'Manage capture URLs',+ onClick: () => router.actions.push(urls.settings('environment-heatmaps')),+ }}+ >+ {urlAllowlist.length === 0+ ? 'Heatmap capture will soon use the URL rules in settings. Add at least one URL, or choose Allow all URLs, to keep collecting heatmap data.'+ : 'Heatmap capture will soon be limited to the URLs you list in settings. Review them to keep collecting the heatmap data you need.'}+ </LemonBanner>+ )+}diff --git a/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureSettings.tsx b/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureSettings.tsxnew file mode 100644index 000000000000..cd82497e040e--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/components/HeatmapCaptureSettings.tsx@@ -0,0 +1,175 @@+import { useActions, useValues } from 'kea'++import {+ LemonBanner,+ LemonButton,+ LemonInputSelect,+ LemonLabel,+ LemonSegmentedButton,+ LemonSkeleton,+} from '@posthog/lemon-ui'++import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'+import { TeamMembershipLevel } from 'lib/constants'+import { teamLogic } from 'scenes/teamLogic'+import { urls } from 'scenes/urls'++import { heatmapCaptureSettingsLogic } from './heatmapCaptureSettingsLogic'++export function HeatmapCaptureSettings(): JSX.Element {+ const { currentTeamId } = useValues(teamLogic)+ const logic = heatmapCaptureSettingsLogic({ teamId: currentTeamId ?? 0 })+ const {+ settings,+ settingsLoading,+ captureMode,+ urlAllowlist,+ hasChanges,+ loadError,+ saveError,+ canCaptureAllUrls,+ captureUrlLimit,+ disabledPages,+ pagesLoading,+ pagesError,+ } = useValues(logic)+ const { loadSettings, loadPages, setCaptureMode, setUrlAllowlist, saveSettings } = useActions(logic)+ const restrictedReason = useRestrictedArea({+ scope: RestrictionScope.Project,+ minimumAccessLevel: TeamMembershipLevel.Admin,+ })++ if (loadError) {+ return (+ <LemonBanner type="error" action={{ children: 'Retry', onClick: loadSettings }}>+ Could not load heatmap capture settings. Try again.+ </LemonBanner>+ )+ }+ if (!settings) {+ return <LemonSkeleton />+ }++ const isAllowlist = captureMode === 'url_allowlist'+ const emptyAllowlist = isAllowlist && urlAllowlist.length === 0++ return (+ <div className="flex flex-col gap-3 max-w-160">+ <p className="mb-0">+ Choose which pages send heatmap data. Capture from every page, or only from the URLs you list. Data from+ pages that are not covered is not collected.+ </p>++ {!canCaptureAllUrls && (+ <LemonBanner type="warning" action={{ children: 'Upgrade', to: urls.organizationBilling() }}>+ Your plan captures heatmaps on up to {captureUrlLimit} URLs. Pick the pages that matter most, or+ upgrade to capture every page.+ </LemonBanner>+ )}++ {settings.enforcement_enabled ? (+ emptyAllowlist && (+ <LemonBanner type="warning">+ No URLs are listed, so no heatmap data is being collected. Add at least one URL+ {canCaptureAllUrls ? ', or choose Allow all URLs' : ''}.+ </LemonBanner>+ )+ ) : (+ <LemonBanner type="info">+ These rules are not enforced yet. Heatmap data is still collected from every page for now, but that+ will change. Set them up so capture keeps working when they take effect.+ </LemonBanner>+ )}++ <div className="flex flex-col gap-2">+ <LemonLabel>Pages to capture</LemonLabel>+ <LemonSegmentedButton+ value={captureMode}+ onChange={(value) => setCaptureMode(value as typeof captureMode)}+ disabledReason={restrictedReason || undefined}+ options={[+ { value: 'url_allowlist', label: 'Only listed URLs' },+ {+ value: 'all',+ label: 'Allow all URLs',+ disabledReason: canCaptureAllUrls ? undefined : 'Upgrade to capture all pages',+ },+ ]}+ />+ </div>++ {isAllowlist && (+ <div className="flex flex-col gap-2">+ <LemonLabel>Allowed URLs</LemonLabel>+ <LemonInputSelect+ mode="multiple"+ allowCustomValues+ value={urlAllowlist}+ options={urlAllowlist.map((url) => ({ key: url, label: url }))}+ onChange={(value) =>+ setUrlAllowlist(captureUrlLimit != null ? value.slice(0, captureUrlLimit) : value)+ }+ placeholder="https://example.com/pricing"+ limit={captureUrlLimit ?? undefined}+ disabled={!!restrictedReason || settingsLoading}+ data-attr="heatmap-capture-url-allowlist"+ />+ <p className="text-secondary mb-0">+ {captureUrlLimit != null ? `Your plan captures up to ${captureUrlLimit} URLs. ` : ''}+ Enter full URLs. Use <code>*</code> to match any characters, for example{' '}+ <code>https://example.com/docs/*</code>.+ </p>+ </div>+ )}++ {!canCaptureAllUrls && isAllowlist && (+ <div className="flex flex-col gap-2">+ <LemonLabel>Pages that will stop capturing</LemonLabel>+ {pagesLoading ? (+ <LemonSkeleton className="h-16" />+ ) : pagesError ? (+ <LemonBanner type="error" action={{ children: 'Retry', onClick: loadPages }}>+ Could not check which pages your listed URLs cover. Try again.+ </LemonBanner>+ ) : disabledPages.length === 0 ? (+ <p className="text-secondary mb-0">+ Your listed URLs cover every page we currently collect heatmaps on.+ </p>+ ) : (+ <ul className="flex flex-col gap-1 m-0 p-0 border rounded divide-y">+ {disabledPages.map((page) => (+ <li+ key={page.url}+ className="flex items-center justify-between gap-2 list-none px-3 py-2"+ >+ <span className="truncate">{page.url}</span>+ <span className="text-secondary whitespace-nowrap">+ {page.count.toLocaleString()} events+ </span>+ </li>+ ))}+ </ul>+ )}+ </div>+ )}++ {saveError && (+ <LemonBanner type="error">+ Could not save. Check that each entry is a full http or https URL, then try again.+ </LemonBanner>+ )}++ {!restrictedReason && (+ <LemonButton+ className="self-start"+ type="primary"+ onClick={saveSettings}+ loading={settingsLoading}+ disabled={!hasChanges}+ >+ Save capture URLs+ </LemonButton>+ )}+ </div>+ )+}diff --git a/products/web_analytics/frontend/heatmaps/components/heatmapCaptureSettingsLogic.ts b/products/web_analytics/frontend/heatmaps/components/heatmapCaptureSettingsLogic.tsnew file mode 100644index 000000000000..e1178f27d4be--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/components/heatmapCaptureSettingsLogic.ts@@ -0,0 +1,234 @@+import { MakeLogicType, actions, afterMount, kea, key, listeners, path, props, reducers, selectors } from 'kea'+import { loaders } from 'kea-loaders'++import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'++import * as api from '../../generated/api'+import type { HeatmapCapturePageApi, HeatmapCaptureSettingsApi } from '../../generated/api.schemas'++export type HeatmapCaptureMode = 'all' | 'url_allowlist'++export function urlMatchesCaptureAllowlistPattern(url: string, pattern: string): boolean {+ const segments = pattern.split('*')+ if (segments.length === 1) {+ return url === pattern+ }+ const first = segments[0]+ const last = segments[segments.length - 1]+ if (url.length < first.length + last.length || !url.startsWith(first) || !url.endsWith(last)) {+ return false+ }+ const end = url.length - last.length+ let position = first.length+ for (const segment of segments.slice(1, -1)) {+ const index = url.indexOf(segment, position)+ if (index === -1 || index + segment.length > end) {+ return false+ }+ position = index + segment.length+ }+ return true+}++export function isUrlCoveredByAllowlist(url: string, allowlist: string[]): boolean {+ return allowlist.some((pattern) => urlMatchesCaptureAllowlistPattern(url, pattern))+}++export interface HeatmapCaptureSettingsLogicProps {+ teamId: number+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface heatmapCaptureSettingsLogicValues {+ canCaptureAllUrls: boolean+ captureMode: HeatmapCaptureMode+ captureUrlLimit: number | null+ disabledPages: HeatmapCapturePageApi[]+ hasChanges: boolean+ loadError: boolean+ pages: HeatmapCapturePageApi[]+ pagesError: boolean+ pagesLoading: boolean+ saveError: string | null+ settings: HeatmapCaptureSettingsApi | null+ settingsLoading: boolean+ urlAllowlist: string[]+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface heatmapCaptureSettingsLogicActions {+ loadPages: () => any+ loadPagesFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadPagesSuccess: (+ pages: HeatmapCapturePageApi[],+ payload?: any+ ) => {+ pages: HeatmapCapturePageApi[]+ payload?: any+ }+ loadSettings: () => any+ loadSettingsFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ loadSettingsSuccess: (+ settings: HeatmapCaptureSettingsApi,+ payload?: any+ ) => {+ settings: HeatmapCaptureSettingsApi+ payload?: any+ }+ saveSettings: () => any+ saveSettingsFailure: (+ error: string,+ errorObject?: any+ ) => {+ error: string+ errorObject?: any+ }+ saveSettingsSuccess: (+ settings: HeatmapCaptureSettingsApi,+ payload?: any+ ) => {+ settings: HeatmapCaptureSettingsApi+ payload?: any+ }+ setCaptureMode: (captureMode: HeatmapCaptureMode) => {+ captureMode: HeatmapCaptureMode+ }+ setUrlAllowlist: (urlAllowlist: string[]) => {+ urlAllowlist: string[]+ }+}++// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface heatmapCaptureSettingsLogicMeta {+ key: number+ __keaTypeGenInternalSelectorTypes: {+ hasChanges: (+ settings: HeatmapCaptureSettingsApi | null,+ captureMode: HeatmapCaptureMode,+ urlAllowlist: string[]+ ) => boolean+ canCaptureAllUrls: (settings: HeatmapCaptureSettingsApi | null) => boolean+ captureUrlLimit: (settings: HeatmapCaptureSettingsApi | null) => number | null+ disabledPages: (pages: HeatmapCapturePageApi[], urlAllowlist: string[]) => HeatmapCapturePageApi[]+ }+}++export type heatmapCaptureSettingsLogicType = MakeLogicType<+ heatmapCaptureSettingsLogicValues,+ heatmapCaptureSettingsLogicActions,+ HeatmapCaptureSettingsLogicProps,+ heatmapCaptureSettingsLogicMeta+>++export const heatmapCaptureSettingsLogic = kea<heatmapCaptureSettingsLogicType>([+ props({} as HeatmapCaptureSettingsLogicProps),+ key((props) => props.teamId),+ path((key) => ['products', 'web_analytics', 'heatmaps', 'heatmapCaptureSettingsLogic', key]),+ actions({+ setCaptureMode: (captureMode: HeatmapCaptureMode) => ({ captureMode }),+ setUrlAllowlist: (urlAllowlist: string[]) => ({ urlAllowlist }),+ }),+ loaders(({ props, values }) => ({+ settings: [+ null as HeatmapCaptureSettingsApi | null,+ {+ loadSettings: async () => api.heatmapCaptureSettingsRetrieve(String(props.teamId)),+ saveSettings: async () => {+ const result = await api.heatmapCaptureSettingsUpdate(String(props.teamId), {+ capture_mode: values.captureMode,+ url_allowlist: values.urlAllowlist,+ })+ lemonToast.success('Heatmap capture URLs saved.')+ return result+ },+ },+ ],+ pages: [+ [] as HeatmapCapturePageApi[],+ {+ loadPages: async () => (await api.heatmapCapturePagesRetrieve(String(props.teamId))).pages,+ },+ ],+ })),+ reducers({+ captureMode: [+ 'url_allowlist' as HeatmapCaptureMode,+ {+ setCaptureMode: (_, { captureMode }) => captureMode,+ loadSettingsSuccess: (_, { settings }) => settings.capture_mode ?? 'url_allowlist',+ saveSettingsSuccess: (_, { settings }) => settings.capture_mode ?? 'url_allowlist',+ },+ ],+ urlAllowlist: [+ [] as string[],+ {+ setUrlAllowlist: (_, { urlAllowlist }) => urlAllowlist,+ loadSettingsSuccess: (_, { settings }) => settings.url_allowlist ?? [],+ saveSettingsSuccess: (_, { settings }) => settings.url_allowlist ?? [],+ },+ ],+ loadError: [+ false,+ { loadSettings: () => false, loadSettingsFailure: () => true, loadSettingsSuccess: () => false },+ ],+ pagesError: [false, { loadPages: () => false, loadPagesFailure: () => true, loadPagesSuccess: () => false }],+ saveError: [+ null as string | null,+ {+ saveSettings: () => null,+ saveSettingsFailure: (_, { error }) => error,+ setCaptureMode: () => null,+ setUrlAllowlist: () => null,+ },+ ],+ }),+ selectors({+ hasChanges: [+ (s) => [s.settings, s.captureMode, s.urlAllowlist],+ (+ settings: HeatmapCaptureSettingsApi | null,+ captureMode: HeatmapCaptureMode,+ urlAllowlist: string[]+ ): boolean =>+ settings?.capture_mode !== captureMode ||+ JSON.stringify(settings?.url_allowlist) !== JSON.stringify(urlAllowlist),+ ],+ canCaptureAllUrls: [+ (s) => [s.settings],+ (settings: HeatmapCaptureSettingsApi | null): boolean => settings?.can_capture_all_urls ?? true,+ ],+ captureUrlLimit: [+ (s) => [s.settings],+ (settings: HeatmapCaptureSettingsApi | null): number | null => settings?.capture_url_limit ?? null,+ ],+ disabledPages: [+ (s) => [s.pages, s.urlAllowlist],+ (pages: HeatmapCapturePageApi[], urlAllowlist: string[]): HeatmapCapturePageApi[] =>+ pages.filter((page) => !isUrlCoveredByAllowlist(page.url, urlAllowlist)),+ ],+ }),+ listeners(({ actions, values }) => ({+ loadSettingsSuccess: () => {+ if (!values.canCaptureAllUrls) {+ actions.loadPages()+ }+ },+ })),+ afterMount(({ actions, props }) => {+ if (props.teamId) {+ actions.loadSettings()+ }+ }),+])diff --git a/products/web_analytics/frontend/heatmaps/components/heatmapCaptureUrlMatch.test.ts b/products/web_analytics/frontend/heatmaps/components/heatmapCaptureUrlMatch.test.tsnew file mode 100644index 000000000000..1df5ce35dd55--- /dev/null+++ b/products/web_analytics/frontend/heatmaps/components/heatmapCaptureUrlMatch.test.ts@@ -0,0 +1,28 @@+import { isUrlCoveredByAllowlist } from './heatmapCaptureSettingsLogic'++describe('isUrlCoveredByAllowlist', () => {+ it.each<[string, string, string[], boolean]>([+ ['exact match', 'https://example.com/pricing', ['https://example.com/pricing'], true],+ ['no match', 'https://example.com/blog', ['https://example.com/pricing'], false],+ ['wildcard matches deeper path', 'https://example.com/docs/setup', ['https://example.com/docs/*'], true],+ ['wildcard matches zero characters', 'https://example.com/docs/', ['https://example.com/docs/*'], true],+ ['dot is literal, not a wildcard', 'https://exampleXcom/a', ['https://example.com/a'], false],+ ['empty allowlist covers nothing', 'https://example.com/a', [], false],+ ['several wildcards match in order', 'https://example.com/a/x/b/y', ['https://example.com/*/x/*/y'], true],+ [+ 'several wildcards reject out of order',+ 'https://example.com/a/y/b/x',+ ['https://example.com/*/x/*/y'],+ false,+ ],+ ['wildcard segment cannot overlap the suffix', 'https://example.com/ab', ['https://example.com/*ab*b'], false],+ [+ 'repeated wildcards reject a long url without backtracking',+ `https://example.com/${'a'.repeat(5000)}`,+ [`https://example.com/${'*a'.repeat(12)}b`],+ false,+ ],+ ])('%s', (_name, url, allowlist, expected) => {+ expect(isUrlCoveredByAllowlist(url, allowlist)).toBe(expected)+ })+})diff --git a/products/web_analytics/frontend/heatmaps/scenes/heatmap/HeatmapNewScene.tsx b/products/web_analytics/frontend/heatmaps/scenes/heatmap/HeatmapNewScene.tsxindex ce40cf78ebb8..f8ea1f034811 100644--- a/products/web_analytics/frontend/heatmaps/scenes/heatmap/HeatmapNewScene.tsx+++ b/products/web_analytics/frontend/heatmaps/scenes/heatmap/HeatmapNewScene.tsx@@ -20,6 +20,7 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'import { AccessControlLevel, AccessControlResourceType, HeatmapType } from '~/types'import { HeatmapAdvancedSettings } from '../../components/HeatmapAdvancedSettings'+import { heatmapCaptureSettingsLogic, isUrlCoveredByAllowlist } from '../../components/heatmapCaptureSettingsLogic'import { HeatmapRecording } from '../../components/HeatmapRecording'import { HeatmapRecordingFallback } from '../../components/HeatmapRecordingFallback'import { heatmapsBrowserLogic } from '../../components/heatmapsBrowserLogic'@@ -124,6 +125,40 @@ function CaptureReadiness(): JSX.Element {)}+function CaptureUrlReadiness(): JSX.Element | null {+ const { captureEnabled } = useValues(heatmapCreationLogic)+ const { displayUrl } = useValues(heatmapLogic({ id: 'new' }))+ const { currentTeamId } = useValues(teamLogic)+ const { settings, urlAllowlist } = useValues(heatmapCaptureSettingsLogic({ teamId: currentTeamId ?? 0 }))++ if (!captureEnabled || !settings || settings.capture_mode !== 'url_allowlist' || !displayUrl?.trim()) {+ return null+ }++ const covered = isUrlCoveredByAllowlist(displayUrl, urlAllowlist)++ if (covered) {+ return (+ <div className="flex items-center gap-2 text-success">+ <IconCheckCircle className="size-5 shrink-0" />+ <span>This page is covered by your heatmap capture URLs.</span>+ </div>+ )+ }++ return (+ <LemonBanner+ type="warning"+ action={{ children: 'Manage capture URLs', to: urls.settings('environment-heatmaps') }}+ >+ {settings.enforcement_enabled+ ? 'This page is not in your heatmap capture URLs, so it is not collecting new data. '+ : 'This page is not in your heatmap capture URLs. When capture limits take effect, it will stop collecting new data. '}+ Add it to your capture URLs, or switch to Allow all URLs.+ </LemonBanner>+ )+}+function MatchingDataReadiness(): JSX.Element {const { currentPageDataCheck, pageDataCheckLoading } = useValues(heatmapCreationLogic)const { requestPageDataCheck } = useActions(heatmapCreationLogic)@@ -232,6 +267,7 @@ function ChoosePageStep(): JSX.Element {<div className="flex flex-col gap-3"><h3 className="mb-0">Readiness</h3><CaptureReadiness />+ <CaptureUrlReadiness /><MatchingDataReadiness /></div>diff --git a/products/web_analytics/frontend/heatmaps/scenes/heatmaps/HeatmapsScene.tsx b/products/web_analytics/frontend/heatmaps/scenes/heatmaps/HeatmapsScene.tsxindex 18037ebdb6d5..95c4eb8b93c8 100644--- a/products/web_analytics/frontend/heatmaps/scenes/heatmaps/HeatmapsScene.tsx+++ b/products/web_analytics/frontend/heatmaps/scenes/heatmaps/HeatmapsScene.tsx@@ -1,7 +1,15 @@import { useActions, useValues } from 'kea'-import { IconPlusSmall } from '@posthog/icons'-import { LemonButton, LemonInput, LemonTable, LemonTableColumn, LemonTableColumns, Link } from '@posthog/lemon-ui'+import { IconHide, IconPlusSmall } from '@posthog/icons'+import {+ LemonButton,+ LemonInput,+ LemonTable,+ LemonTableColumn,+ LemonTableColumns,+ Link,+ Tooltip,+} from '@posthog/lemon-ui'import { AccessControlAction } from 'lib/components/AccessControlAction'import { MemberSelect } from 'lib/components/MemberSelect'@@ -13,6 +21,7 @@ import { More } from 'lib/lemon-ui/LemonButton/More'import { createdByColumn } from 'lib/lemon-ui/LemonTable/columnUtils'import { sceneConfigurations } from 'scenes/scenes'import { Scene, SceneExport } from 'scenes/sceneTypes'+import { teamLogic } from 'scenes/teamLogic'import { urls } from 'scenes/urls'import { SceneContent } from '~/layout/scenes/components/SceneContent'@@ -20,6 +29,8 @@ import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'import { ProductKey } from '~/queries/schema/schema-general'import { AccessControlLevel, AccessControlResourceType, HeatmapScreenshotType } from '~/types'+import { HeatmapCaptureAllowlistNotice } from '../../components/HeatmapCaptureAllowlistNotice'+import { heatmapCaptureSettingsLogic, isUrlCoveredByAllowlist } from '../../components/heatmapCaptureSettingsLogic'import { HeatmapsWarnings } from '../../components/HeatmapsWarnings'import { heatmapsEmptyState } from '../../emptyState/heatmapsEmptyState'import { HEATMAPS_PER_PAGE, heatmapsSceneLogic } from './heatmapsSceneLogic'@@ -34,6 +45,14 @@ export const scene: SceneExport = {export function HeatmapsScene(): JSX.Element {const { savedHeatmaps, savedHeatmapsLoading, filters, totalCount } = useValues(heatmapsSceneLogic)const { deleteHeatmap, setHeatmapsFilters } = useActions(heatmapsSceneLogic)+ const { currentTeamId } = useValues(teamLogic)+ const { settings, urlAllowlist, captureMode } = useValues(+ heatmapCaptureSettingsLogic({ teamId: currentTeamId ?? 0 })+ )+ const showCaptureStatus = !!settings && captureMode === 'url_allowlist'+ const wontCaptureTooltip = settings?.enforcement_enabled+ ? 'Not in your capture URLs, so this page is not collecting new heatmap data.'+ : 'Not in your capture URLs. When capture limits take effect, this page stops collecting new heatmap data.'const columns: LemonTableColumns<HeatmapScreenshotType> = [{@@ -48,11 +67,21 @@ export function HeatmapsScene(): JSX.Element {{title: 'Page',dataIndex: 'url',- render: (_, row) => (- <Link to={urls.heatmap(row.short_id)}>- <span className="truncate max-w-[32rem] inline-block align-middle">{row.url}</span>- </Link>- ),+ render: (_, row) => {+ const wontCapture = showCaptureStatus && !!row.url && !isUrlCoveredByAllowlist(row.url, urlAllowlist)+ return (+ <div className="flex items-center gap-2">+ <Link to={urls.heatmap(row.short_id)}>+ <span className="truncate max-w-[28rem] inline-block align-middle">{row.url}</span>+ </Link>+ {wontCapture && (+ <Tooltip title={wontCaptureTooltip}>+ <IconHide className="text-muted shrink-0" />+ </Tooltip>+ )}+ </div>+ )+ },},{title: 'Heatmap data URL',@@ -146,6 +175,7 @@ export function HeatmapsScene(): JSX.Element {</Shortcut>}/>+ <HeatmapCaptureAllowlistNotice /><LemonBannertype="info"dismissKey="heatmaps-beta-banner"