: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(toolbar): warn when a heatmap URL pattern matches too little (#95576)
Paul D'Ambra2d84e1260290
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 671f0b97aa53..9f01bd7d563f 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -9597,13 +9597,13 @@ snapshots:scenes-other-toolbar--feature-flags-dark--light:hash: v1.k794b7964.df69f67c93107fd027ba9495b59e812c069dd15b31d4c656c019a1215ea4c4e1.abSIANsON5AV9z9X0y95CA0ow4mrmZ_h2EI-jGxEFNYscenes-other-toolbar--heatmap--dark:- hash: v1.k794b7964.e47aba7195bbee4551f408b338643bf637df8be8ceda7d63856518fa194fccdb.pNs2LDGOGK0vRJ1EoQeE8FMpMaQ4jsxe7L7OAmxwcbc+ hash: v1.k794b7964.086fd8b0d97e595878b1ff4fffd5f23cfbc66ab145366ba2d42723ab347ba470.5ylwJ-It7Bv1vnDjPJ9V9qEl4HeoElTzXTO2j9ZwaP0scenes-other-toolbar--heatmap--light:- hash: v1.k794b7964.a00d413c90e2c9e2a9a0d5717f2dc6f414d9378817ae5d021cd03bf4c4ca3907.QT8viiKJlL6fSzuW9WRO1em3-HEeSZ65G0Oy6tOkySA+ hash: v1.k794b7964.f2acdd290f2691313aa08790fefeabc1ff2af3030e39c163f6c90d35766f7266.XDWRR7ac9tHkz54q8yC6U0xWmMDL8bqSsBi7uZHjtl4scenes-other-toolbar--heatmap-dark--dark:- hash: v1.k794b7964.ec7108aa94325cd3b24cde23dc47b45ad382e40e79442506bb379bd1c9703da9.836RpRCYHtzxeoYlYzuvg8ql-b34ekMCw4XzqdJP8SI+ hash: v1.k794b7964.b5c5685fbf4362ffdeb86b71403d992895bc7f465a89e3950e73d805659120cd.LflCqOqs_3HllO3yAenQoTU4XkVLmdFgiMZdver44EIscenes-other-toolbar--heatmap-dark--light:- hash: v1.k794b7964.0b1ae494f3a3319201571bf87f01e9e4c95d5824d5684ddf43c0c52b50081a51.GkwhAC2JFtQKQpc9FJGEOH-kruGDAHc4I4v9tRKETr4+ hash: v1.k794b7964.54ea6dd30881be4b788facdce098a207fb5171f6ed969451c4f378ed9bb17f67.kmPM0TK8dLKElYiLRmgDMvswiByHAMWOmC2nhEaeCTMscenes-other-toolbar--inspect--dark:hash: v1.k794b7964.37fa05b873d6876ff8a932209f515de7c81b3cf80af3810489d1e101acb61aa5.00b1XmAvLslDcl3T7oSAyL01QePjoUOaDM3CoV_roaYscenes-other-toolbar--inspect--light:diff --git a/frontend/src/toolbar/stats/HeatmapToolbarMenu.tsx b/frontend/src/toolbar/stats/HeatmapToolbarMenu.tsxindex 478b102c40fb..4a00b036d4b0 100644--- a/frontend/src/toolbar/stats/HeatmapToolbarMenu.tsx+++ b/frontend/src/toolbar/stats/HeatmapToolbarMenu.tsx@@ -80,7 +80,8 @@ const SectionButton = ({}export const HeatmapToolbarMenu = (): JSX.Element => {- const { wildcardHref, autoWildcardEnabled } = useValues(currentPageLogic)+ const { wildcardHref, autoWildcardEnabled, wildcardHrefTooSpecific, wildcardHrefEndsWithSlash } =+ useValues(currentPageLogic)const { setWildcardHref, autoWildcardHref, setAutoWildcardEnabled } = useActions(currentPageLogic)const areaFilterFlagEnabled = useToolbarFeatureFlag('toolbar-heatmap-area-filter')@@ -163,6 +164,21 @@ export const HeatmapToolbarMenu = (): JSX.Element => {}}/></div>+ {wildcardHrefTooSpecific && (+ <p className="text-xs text-secondary mt-1 mb-0">+ {wildcardHrefEndsWithSlash ? (+ <>+ A trailing slash matches only URLs that end there, so deeper pages and query strings+ drop out. Use <code>*</code> to include them.+ </>+ ) : (+ <>+ This URL is specific, so it matches less data. Use <code>*</code> as a wildcard to match+ more.+ </>+ )}+ </p>+ )}<div className="flex flex-row items-center gap-2 py-2 border-b"><DateFilterdiff --git a/frontend/src/toolbar/stats/currentPageLogic.test.ts b/frontend/src/toolbar/stats/currentPageLogic.test.tsindex 1aad6eef2e67..4477a2464ef5 100644--- a/frontend/src/toolbar/stats/currentPageLogic.test.ts+++ b/frontend/src/toolbar/stats/currentPageLogic.test.ts@@ -1,4 +1,4 @@-import { withoutPostHogInit } from '~/toolbar/stats/currentPageLogic'+import { endsWithTrailingSlash, isTooSpecificWildcardHref, withoutPostHogInit } from '~/toolbar/stats/currentPageLogic'const posthogInitHashParam ='__posthog={%22action%22:%20%22ph_authorize%22,%20%22token%22:%20%the-ph-token%22,%20%22temporaryToken%22:%20%the-posthog-token%22,%20%22actionId%22:%20null,%20%22userIntent%22:%20%22heatmaps%22,%20%22toolbarVersion%22:%20%22toolbar%22,%20%22apiURL%22:%20%22https://eu.posthog.com%22,%20%22dataAttributes%22:%20[%22data-attr%22],%20%22instrument%22:%20true,%20%22userEmail%22:%20%[email protected]%22,%20%22distinctId%22:%20%the-distinct-id%22}'@@ -33,4 +33,27 @@ describe('current page logic', () => {)})})++ describe('spotting a pattern that matches too little', () => {+ it.each([+ ['https://*.wat.io/project/*/', true],+ ['https://wat.io/pricing', true],+ ['https://*.wat.io/project/*', false],+ ['https://wat.io/*', false],+ ['https://wat.io/* ', true],+ ['', false],+ [' ', false],+ ])('%s is too specific: %s', (wildcardHref, expected) => {+ expect(isTooSpecificWildcardHref(wildcardHref)).toBe(expected)+ })++ it.each([+ ['https://*.wat.io/project/*/', true],+ ['https://wat.io/', true],+ ['https://*.wat.io/project/*', false],+ ['https://wat.io/pricing', false],+ ])('%s ends with a trailing slash: %s', (wildcardHref, expected) => {+ expect(endsWithTrailingSlash(wildcardHref)).toBe(expected)+ })+ })})diff --git a/frontend/src/toolbar/stats/currentPageLogic.ts b/frontend/src/toolbar/stats/currentPageLogic.tsindex bc9599b05fcc..02c1359c4995 100644--- a/frontend/src/toolbar/stats/currentPageLogic.ts+++ b/frontend/src/toolbar/stats/currentPageLogic.ts@@ -1,4 +1,4 @@-import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers } from 'kea'+import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'import { makeNavigateWrapper } from '~/toolbar/utils'@@ -65,11 +65,27 @@ export function withoutPostHogInit(href: string): string {}}+// A pattern that does not end in a wildcard only matches the URLs it spells out. A trailing slash is+// the common way to get this by accident, and it drops every deeper page from the match.+// a trailing slash is the common way to land on a pattern that matches nothing, and it takes its own+// advice: the fix is to remove it or cover what sits below it, not to add a wildcard anywhere+export function endsWithTrailingSlash(wildcardHref: string): boolean {+ return wildcardHref.endsWith('/')+}++export function isTooSpecificWildcardHref(wildcardHref: string): boolean {+ // judge the stored string, not a trimmed copy of it: the match runs on what is in the box, so a+ // pattern ending in a space matches nothing and must still warn+ return wildcardHref.trim().length > 0 && !wildcardHref.endsWith('*')+}+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface currentPageLogicValues {autoWildcardEnabled: booleanhref: stringwildcardHref: string+ wildcardHrefEndsWithSlash: boolean+ wildcardHrefTooSpecific: boolean}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -88,7 +104,20 @@ export interface currentPageLogicActions {}}-export type currentPageLogicType = MakeLogicType<currentPageLogicValues, currentPageLogicActions>+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.+export interface currentPageLogicMeta {+ __keaTypeGenInternalSelectorTypes: {+ wildcardHrefTooSpecific: (wildcardHref: string) => boolean+ wildcardHrefEndsWithSlash: (wildcardHref: string) => boolean+ }+}++export type currentPageLogicType = MakeLogicType<+ currentPageLogicValues,+ currentPageLogicActions,+ Record<string, any>,+ currentPageLogicMeta+>export const currentPageLogic = kea<currentPageLogicType>([path(['toolbar', 'stats', 'currentPageLogic']),@@ -117,6 +146,17 @@ export const currentPageLogic = kea<currentPageLogicType>([],})),+ selectors(() => ({+ wildcardHrefTooSpecific: [+ (s) => [s.wildcardHref],+ (wildcardHref: string): boolean => isTooSpecificWildcardHref(wildcardHref),+ ],+ wildcardHrefEndsWithSlash: [+ (s) => [s.wildcardHref],+ (wildcardHref: string): boolean => endsWithTrailingSlash(wildcardHref),+ ],+ })),+listeners(({ actions, values }) => ({autoWildcardHref: () => {actions.setWildcardHref(autoWildcardHref(values.wildcardHref))