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(web-analytics): Simplify Web Analytics charts / dashboard (#59105)

Jordan Mryyan440328c778b0
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 51b7b6d567aa..7563b4755075 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5651,13 +5651,13 @@ snapshots:
scenes-app-surveys-surveyresponsekeysreference--webhook--light:
hash: v1.k794b7964.9b5c484a3a1bd7a09c266a1f164e3ed9eef3ffabbcd12253f0843b3f0b69a808.cc6Rai2vShlFJA_KypMbVcc1IIaVX0nTcZ29RPEEZjo
scenes-app-web-analytics--web-analytics-dashboard--dark:
- hash: v1.k794b7964.73d195932e14b7f1ed1492148f30bb401d83f5fe2195454d11b1f8a25d27cf18.b3y1l14OGUaGshoCcw-UeRucPusmKqg_P9hrSKkTVEc
+ hash: v1.k794b7964.4b46c2f6fe707da2296bb53689b78800c6478ee779b197f1c311e2fea63de47c.0idZJlmr3jSbs5CaHGbFEeReoC41p1zUD0S9g6TdzdI
scenes-app-web-analytics--web-analytics-dashboard--light:
- hash: v1.k794b7964.d39a7db817febb31fd2e2f6be9478a531ed200cca876c15bb4471769321688a6.fuln1AuN_ed6kQrQmdORheyl1Mv0Gs3XE2MKkU6BXso
+ hash: v1.k794b7964.1a9d085f23feb03cee402959f38286106f3e6201e54b2da29ce257da3433965a.7K4YAMqJHpqG_Z7jmf2Gki7X9dJk7SpanYq_mEo4V14
scenes-app-web-analytics--web-analytics-dashboard-loading--dark:
- hash: v1.k794b7964.5b686cb6b3dc8f35afc5a40b19b54a5c65d5c62423bae2040b74ab8347bff101.m4Kq3_tjQi_x7bcj0cmphcuTIBT2QJt068bOJkJq_Pw
+ hash: v1.k794b7964.1396963ac1b7fa949a14ff560871decc5622769b2a0aea9d64e590214348836f.Kk2iDi-dCZLh6dhYUIG7BeaGFJLke_ifbsPvQupPDTg
scenes-app-web-analytics--web-analytics-dashboard-loading--light:
- hash: v1.k794b7964.c506ce14be8868021d46d08505c68b4aa02e8ba365c96b1846a6b0c29b8ef012.yiG8H3DQPa0nm5g6439G2rS9pQMzYdT-Pd92LODS_Hg
+ hash: v1.k794b7964.133ccd88e47f023f7ed62a7d061a9bace5dbfa19b90096da72f171f966880233.cYFsJznbj_wqUBrfvtZ4ovRfUESxGDZVEtUAyEZ7EIY
scenes-other-billing--billing--dark:
hash: v1.k794b7964.0fbd211a7ee299a4abb1afb6d3d1e0589eb349c82c59bd5997b16e434356ee18.HyWfDl8iMD41jnar9y2uxNCx2MJJ6DuHch0n18cCWBA
scenes-other-billing--billing--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 4e04bf44fdd2..267bb33e53c1 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -508,6 +508,7 @@ export const FEATURE_FLAGS = {
WEB_ANALYTICS_PRECOMPUTE_TOGGLE: 'web-analytics-precompute-toggle', // owner: @lricoy #team-web-analytics
WEB_ANALYTICS_REGIONS_MAP: 'web-analytics-regions-map', // owner: @jordanm-posthog #team-web-analytics
WEB_ANALYTICS_SESSION_PROPERTY_CHARTS: 'web-analytics-session-property-charts', // owner: @lricoy #team-web-analytics
+ WEB_ANALYTICS_TILE_HEADER_V2: 'web-analytics-tile-header-v2', // owner: @jordanm-posthog #team-web-analytics multivariate=control,test
WEB_ANALYTICS_TILE_SKELETONS: 'web-analytics-tile-skeletons', // owner: @jordanm-posthog #team-web-analytics
WEB_ANALYTICS_TILE_TOGGLES: 'web-analytics-tile-toggles', // owner: @lricoy #team-web-analytics
WEB_ANALYTICS_TOOLTIP_COMPARISON_LABELS: 'web-analytics-tooltip-comparison-labels', // owner: @lricoy #team-web-analytics
diff --git a/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx b/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx
index 74d396cbceb7..31152b2ec0c0 100644
--- a/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx
+++ b/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx
@@ -7,6 +7,7 @@ import { LemonSegmentedButton, LemonSegmentedDropdown, LemonSkeleton } from '@po
import { keyBinds } from 'lib/components/AppShortcuts/shortcuts'
import { useAppShortcut } from 'lib/components/AppShortcuts/useAppShortcut'
+import { IntervalFilterStandalone } from 'lib/components/IntervalFilter/IntervalFilter'
import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'
import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'
import { FEATURE_FLAGS } from 'lib/constants'
@@ -46,6 +47,8 @@ import { WebAnalyticsHealthCheck } from 'scenes/web-analytics/WebAnalyticsHealth
import { webAnalyticsLoadTimeLogic } from 'scenes/web-analytics/webAnalyticsLoadTimeLogic'
import { webAnalyticsLogic } from 'scenes/web-analytics/webAnalyticsLogic'
import { WebAnalyticsModal } from 'scenes/web-analytics/WebAnalyticsModal'
+import { WebTileHeader } from 'scenes/web-analytics/WebTileHeader'
+import { useWebTileOpenInsight, useWebTileOverflowMenuItems } from 'scenes/web-analytics/webTileHeaderHooks'
import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'
@@ -99,7 +102,110 @@ export const Tiles = (props: { tiles?: WebAnalyticsTile[]; compact?: boolean }):
const QueryTileItem = ({ tile }: { tile: QueryTile }): JSX.Element => {
const { query, title, layout, insightProps, control, showIntervalSelect, docs } = tile
+ const { featureFlags } = useValues(featureFlagLogic)
+ const useTileHeaderV2 = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_HEADER_V2] === 'test'
+
+ const containerClassName = clsx(
+ 'col-span-1 row-span-1 flex flex-col',
+ layout.colSpanClassName ?? 'md:col-span-1',
+ layout.rowSpanClassName ?? 'md:row-span-1',
+ layout.orderWhenLargeClassName ?? '2xl:order-12',
+ layout.className
+ )
+
+ if (useTileHeaderV2) {
+ return (
+ <QueryTileItemV2
+ tile={tile}
+ containerClassName={containerClassName}
+ query={query}
+ title={title}
+ insightProps={insightProps}
+ control={control}
+ showIntervalSelect={showIntervalSelect}
+ docs={docs}
+ />
+ )
+ }
+
+ return (
+ <QueryTileItemLegacy
+ tile={tile}
+ containerClassName={containerClassName}
+ query={query}
+ title={title}
+ insightProps={insightProps}
+ control={control}
+ showIntervalSelect={showIntervalSelect}
+ docs={docs}
+ />
+ )
+}
+
+interface QueryTileItemVariantProps {
+ tile: QueryTile
+ containerClassName: string
+ query: QuerySchema
+ title?: string
+ insightProps: InsightLogicProps
+ control?: JSX.Element
+ showIntervalSelect?: boolean
+ docs?: QueryTile['docs']
+}
+
+const QueryTileItemV2 = ({
+ tile,
+ containerClassName,
+ query,
+ title,
+ insightProps,
+ control,
+ showIntervalSelect,
+ docs,
+}: QueryTileItemVariantProps): JSX.Element => {
+ const overflowMenuItems = useWebTileOverflowMenuItems({
+ tileId: tile.tileId,
+ query,
+ insightProps,
+ canOpenModal: tile.canOpenModal,
+ extraMenuItems: tile.extraMenuItems,
+ })
+ const openInsight = useWebTileOpenInsight({ tileId: tile.tileId, canOpenInsight: !!tile.canOpenInsight })
+
+ return (
+ <div className={containerClassName}>
+ <WebQuery
+ attachTo={webAnalyticsLogic}
+ uniqueKey={`WebAnalytics.${tile.tileId}`}
+ query={query}
+ insightProps={insightProps}
+ control={control}
+ showIntervalSelect={showIntervalSelect}
+ tileId={tile.tileId}
+ headerSlot={
+ <WebTileHeader
+ tileId={tile.tileId}
+ title={title}
+ docs={docs}
+ openInsight={openInsight}
+ overflowMenuItems={overflowMenuItems}
+ />
+ }
+ />
+ </div>
+ )
+}
+const QueryTileItemLegacy = ({
+ tile,
+ containerClassName,
+ query,
+ title,
+ insightProps,
+ control,
+ showIntervalSelect,
+ docs,
+}: QueryTileItemVariantProps): JSX.Element => {
const { openModal } = useActions(webAnalyticsModalLogic)
const { getNewInsightUrl } = useValues(webAnalyticsModalLogic)
@@ -137,15 +243,7 @@ const QueryTileItem = ({ tile }: { tile: QueryTile }): JSX.Element => {
].filter(isNotNil)
return (
- <div
- className={clsx(
- 'col-span-1 row-span-1 flex flex-col',
- layout.colSpanClassName ?? 'md:col-span-1',
- layout.rowSpanClassName ?? 'md:row-span-1',
- layout.orderWhenLargeClassName ?? '2xl:order-12',
- layout.className
- )}
- >
+ <div className={containerClassName}>
{title && (
<div className="flex flex-row items-center mb-2">
<h2>{title}</h2>
@@ -170,7 +268,117 @@ const QueryTileItem = ({ tile }: { tile: QueryTile }): JSX.Element => {
)
}
+const TABS_TILE_VISUALIZATION_TOGGLE_TILES = [TileId.SOURCES, TileId.DEVICES, TileId.PATHS]
+
+const TILES_WHERE_DROPDOWN_IS_TITLE = new Set<TileId>([TileId.GRAPHS, TileId.PATHS])
+
+const TILE_TITLE_PREFIX: Partial<Record<TileId, string>> = {
+ [TileId.SOURCES]: 'Sources by',
+ [TileId.DEVICES]: 'Devices by',
+ [TileId.GEOGRAPHY]: 'Geography by',
+ [TileId.ACTIVE_HOURS]: 'Active hours by',
+}
+
const TabsTileItem = ({ tile }: { tile: TabsTile }): JSX.Element => {
+ const { featureFlags } = useValues(featureFlagLogic)
+ const useTileHeaderV2 = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_HEADER_V2] === 'test'
+
+ if (useTileHeaderV2) {
+ return <TabsTileItemV2 tile={tile} />
+ }
+ return <TabsTileItemLegacy tile={tile} />
+}
+
+const TabsTileItemV2 = ({ tile }: { tile: TabsTile }): JSX.Element => {
+ const { layout, tileId, activeTabId, setTabId, tabs } = tile
+
+ const { setDateInterval, setTileVisualization } = useActions(webAnalyticsLogic)
+ const {
+ dateFilter: { interval },
+ tileVisualizations,
+ } = useValues(webAnalyticsLogic)
+
+ const activeTab = tabs.find((t) => t.id === activeTabId)
+ const useLongLabels = TILES_WHERE_DROPDOWN_IS_TITLE.has(tileId)
+ const titlePrefix = TILE_TITLE_PREFIX[tileId]
+ const dropdownOptions = tabs.map((t) => ({
+ value: t.id,
+ label: (useLongLabels ? t.title : t.linkText) as string | JSX.Element,
+ }))
+
+ const showIntervalInHeader = tileId === TileId.GRAPHS && !!activeTab?.showIntervalSelect
+ const showVisualizationToggle = TABS_TILE_VISUALIZATION_TOGGLE_TILES.includes(tileId)
+
+ const overflowMenuItems = useWebTileOverflowMenuItems({
+ tileId,
+ tabId: activeTabId,
+ query: activeTab?.query,
+ insightProps: activeTab?.insightProps,
+ canOpenModal: activeTab?.canOpenModal,
+ extraMenuItems: activeTab?.extraMenuItems,
+ })
+ const openInsight = useWebTileOpenInsight({
+ tileId,
+ tabId: activeTabId,
+ canOpenInsight: !!activeTab?.canOpenInsight,
+ })
+
+ const header = (
+ <WebTileHeader
+ tileId={tileId}
+ titlePrefix={titlePrefix}
+ titleDropdown={{ value: activeTabId, options: dropdownOptions, onChange: setTabId }}
+ docs={activeTab?.docs}
+ intervalSelector={
+ showIntervalInHeader
+ ? {
+ node: <IntervalFilterStandalone interval={interval} onIntervalChange={setDateInterval} />,
+ }
+ : undefined
+ }
+ visualizationToggle={
+ showVisualizationToggle
+ ? {
+ value: tileVisualizations[tileId],
+ onChange: (value) => setTileVisualization(tileId, value),
+ }
+ : undefined
+ }
+ openInsight={openInsight}
+ overflowMenuItems={overflowMenuItems}
+ />
+ )
+
+ return (
+ <div
+ className={clsx(
+ 'col-span-1 row-span-1 flex flex-col',
+ layout.colSpanClassName ?? 'md:col-span-1',
+ layout.rowSpanClassName ?? 'md:row-span-1',
+ layout.orderWhenLargeClassName ?? '2xl:order-12',
+ layout.className
+ )}
+ >
+ {activeTab ? (
+ <WebQuery
+ attachTo={webAnalyticsLogic}
+ uniqueKey={`WebAnalytics.${tileId}.${activeTab.id}`}
+ key={activeTab.id}
+ query={activeTab.query}
+ showIntervalSelect={showIntervalInHeader ? false : activeTab.showIntervalSelect}
+ control={activeTab.control}
+ insightProps={activeTab.insightProps}
+ tileId={tileId}
+ headerSlot={header}
+ />
+ ) : (
+ <div className="border rounded bg-surface-primary flex-1 flex flex-col">{header}</div>
+ )}
+ </div>
+ )
+}
+
+const TabsTileItemLegacy = ({ tile }: { tile: TabsTile }): JSX.Element => {
const { layout } = tile
const { getNewInsightUrl } = useValues(webAnalyticsModalLogic)
@@ -215,27 +423,6 @@ const TabsTileItem = ({ tile }: { tile: TabsTile }): JSX.Element => {
)
}
-export const SectionTileItem = ({ tile, separator }: { tile: SectionTile; separator?: boolean }): JSX.Element => {
- return (
- <div className="col-span-full">
- {tile.title && <h2 className="text-lg font-semibold mb-4">{tile.title}</h2>}
- <div className={tile.layout.className ? `grid ${tile.layout.className} mb-4` : 'mb-4'}>
- {tile.tiles.map((subTile, i) => {
- if (subTile.kind === 'query') {
- return (
- <div key={`${subTile.tileId}-${i}`} className="col-span-1">
- <QueryTileItem tile={subTile} />
- </div>
- )
- }
- return null
- })}
- </div>
- {separator && <LemonDivider className="my-3" />}
- </div>
- )
-}
-
export const WebTabs = ({
className,
activeTabId,
@@ -363,6 +550,27 @@ export const WebTabs = ({
)
}
+export const SectionTileItem = ({ tile, separator }: { tile: SectionTile; separator?: boolean }): JSX.Element => {
+ return (
+ <div className="col-span-full">
+ {tile.title && <h2 className="text-lg font-semibold mb-4">{tile.title}</h2>}
+ <div className={tile.layout.className ? `grid ${tile.layout.className} mb-4` : 'mb-4'}>
+ {tile.tiles.map((subTile, i) => {
+ if (subTile.kind === 'query') {
+ return (
+ <div key={`${subTile.tileId}-${i}`} className="col-span-1">
+ <QueryTileItem tile={subTile} />
+ </div>
+ )
+ }
+ return null
+ })}
+ </div>
+ {separator && <LemonDivider className="my-3" />}
+ </div>
+ )
+}
+
export interface LearnMorePopoverProps {
url?: PostHogComDocsURL
title: string
@@ -404,7 +612,13 @@ export const LearnMorePopover = ({ url, title, description }: LearnMorePopoverPr
</div>
}
>
- <LemonButton onClick={() => setIsOpen(!isOpen)} size="small" icon={<IconInfo />} className="ml-1 mb-1" />
+ <LemonButton
+ onClick={() => setIsOpen(!isOpen)}
+ size="small"
+ noPadding
+ icon={<IconInfo />}
+ aria-label="More info"
+ />
</Popover>
)
}
diff --git a/frontend/src/scenes/web-analytics/WebAnalyticsExport.tsx b/frontend/src/scenes/web-analytics/WebAnalyticsExport.tsx
index 87b19f2c5d8c..15820c60ee70 100644
--- a/frontend/src/scenes/web-analytics/WebAnalyticsExport.tsx
+++ b/frontend/src/scenes/web-analytics/WebAnalyticsExport.tsx
@@ -1,19 +1,11 @@
-import { useValues } from 'kea'
-
import { IconCopy } from '@posthog/icons'
import { LemonButton, LemonMenu } from '@posthog/lemon-ui'
-import { QuerySchema, TrendsQueryResponse, WebStatsTableQueryResponse } from '~/queries/schema/schema-general'
+import { QuerySchema } from '~/queries/schema/schema-general'
import { ExporterFormat, InsightLogicProps } from '~/types'
-import { insightDataLogic } from '../insights/insightDataLogic'
-import {
- CalendarHeatmapAdapter,
- TrendsAdapter,
- WebAnalyticsTableAdapter,
- WorldMapAdapter,
- exportTableData,
-} from './webAnalyticsExportUtils'
+import { exportTableData } from './webAnalyticsExportUtils'
+import { useWebTileExportAdapter } from './webTileHeaderHooks'
interface WebAnalyticsExportProps {
query: QuerySchema
@@ -21,21 +13,7 @@ interface WebAnalyticsExportProps {
}
export function WebAnalyticsExport({ query, insightProps }: WebAnalyticsExportProps): JSX.Element | null {
- const builtInsightDataLogic = insightDataLogic(insightProps)
- const { insightDataRaw } = useValues(builtInsightDataLogic)
-
- if (!insightDataRaw) {
- return null
- }
-
- // Try to find an appropriate adapter for this query and response
- const adapters = [
- new CalendarHeatmapAdapter(insightDataRaw as TrendsQueryResponse, query),
- new WorldMapAdapter(insightDataRaw as TrendsQueryResponse, query),
- new WebAnalyticsTableAdapter(insightDataRaw as WebStatsTableQueryResponse, query),
- new TrendsAdapter(insightDataRaw as TrendsQueryResponse, query),
- ]
- const adapter = adapters.find((a) => a.canHandle())
+ const adapter = useWebTileExportAdapter(query, insightProps)
if (!adapter) {
return null
diff --git a/frontend/src/scenes/web-analytics/WebTileHeader.test.tsx b/frontend/src/scenes/web-analytics/WebTileHeader.test.tsx
new file mode 100644
index 000000000000..e786a0249c7a
--- /dev/null
+++ b/frontend/src/scenes/web-analytics/WebTileHeader.test.tsx
@@ -0,0 +1,110 @@
+import { cleanup, fireEvent, render, within } from '@testing-library/react'
+
+import { LemonMenuItem } from '@posthog/lemon-ui'
+
+import { queryByDataAttr } from '~/test/byDataAttr'
+
+import { TileId } from './common'
+import { WebTileHeader } from './WebTileHeader'
+
+const noopMenuItems: LemonMenuItem[] = [
+ { label: 'Copy', items: [{ label: 'Link', onClick: () => {} }] },
+ { label: 'Show more', onClick: () => {} },
+]
+
+describe('WebTileHeader', () => {
+ afterEach(() => {
+ cleanup()
+ })
+
+ test('renders a plain title (no dropdown)', () => {
+ const { container } = render(
+ <WebTileHeader tileId={TileId.RETENTION} title="Retention" overflowMenuItems={noopMenuItems} />
+ )
+ expect(within(container).getByText('Retention')).toBeTruthy()
+ })
+
+ test('always renders the overflow menu trigger with a tile-scoped data-attr', () => {
+ const { container } = render(<WebTileHeader tileId={TileId.GRAPHS} overflowMenuItems={noopMenuItems} />)
+ expect(queryByDataAttr(container, 'web-analytics-tile-overflow-GRAPHS')).toBeTruthy()
+ })
+
+ test('renders the title dropdown when titleDropdown is provided', () => {
+ const onChange = jest.fn()
+ const { container } = render(
+ <WebTileHeader
+ tileId={TileId.PATHS}
+ titleDropdown={{
+ value: 'a',
+ options: [
+ { value: 'a', label: 'Paths' },
+ { value: 'b', label: 'Entry paths' },
+ ],
+ onChange,
+ }}
+ overflowMenuItems={noopMenuItems}
+ />
+ )
+ expect(queryByDataAttr(container, 'web-analytics-title-dropdown-PATHS')).toBeTruthy()
+ })
+
+ test('renders the title prefix before the dropdown when both are provided', () => {
+ const onChange = jest.fn()
+ const { container } = render(
+ <WebTileHeader
+ tileId={TileId.SOURCES}
+ titlePrefix="Sources by"
+ titleDropdown={{
+ value: 'channel',
+ options: [
+ { value: 'channel', label: 'Channel' },
+ { value: 'utm_source', label: 'UTM Source' },
+ ],
+ onChange,
+ }}
+ overflowMenuItems={noopMenuItems}
+ />
+ )
+ expect(within(container).getByText('Sources by')).toBeTruthy()
+ expect(queryByDataAttr(container, 'web-analytics-title-dropdown-SOURCES')).toBeTruthy()
+ })
+
+ test('renders no title nor dropdown when none provided', () => {
+ const { container } = render(<WebTileHeader tileId={TileId.RETENTION} overflowMenuItems={noopMenuItems} />)
+ expect(within(container).queryByText('Retention')).toBeNull()
+ expect(within(container).queryByText('Sources by')).toBeNull()
+ })
+
+ test('renders interval selector label when intervalSelector prop is provided', () => {
+ const { container } = render(
+ <WebTileHeader
+ tileId={TileId.GRAPHS}
+ intervalSelector={{ node: <span data-attr="my-interval">node</span> }}
+ overflowMenuItems={noopMenuItems}
+ />
+ )
+ expect(within(container).getByText('Interval')).toBeTruthy()
+ expect(queryByDataAttr(container, 'my-interval')).toBeTruthy()
+ })
+
+ test('renders the open-insight button, links to `to`, and fires `onClick` when clicked', () => {
+ const onClick = jest.fn()
+ const { container } = render(
+ <WebTileHeader
+ tileId={TileId.SOURCES}
+ openInsight={{ to: '/insights/new?web-source', onClick }}
+ overflowMenuItems={noopMenuItems}
+ />
+ )
+ const button = queryByDataAttr(container, 'web-analytics-open-insight-SOURCES')
+ expect(button).toBeTruthy()
+ expect(button?.getAttribute('href')).toBe('/insights/new?web-source')
+ fireEvent.click(button!)
+ expect(onClick).toHaveBeenCalledTimes(1)
+ })
+
+ test('does not render the open-insight button when openInsight is omitted', () => {
+ const { container } = render(<WebTileHeader tileId={TileId.SOURCES} overflowMenuItems={noopMenuItems} />)
+ expect(queryByDataAttr(container, 'web-analytics-open-insight-SOURCES')).toBeNull()
+ })
+})
diff --git a/frontend/src/scenes/web-analytics/WebTileHeader.tsx b/frontend/src/scenes/web-analytics/WebTileHeader.tsx
new file mode 100644
index 000000000000..1636905aed8f
--- /dev/null
+++ b/frontend/src/scenes/web-analytics/WebTileHeader.tsx
@@ -0,0 +1,128 @@
+import { IconChevronDown, IconEllipsis, IconLineGraph } from '@posthog/icons'
+import { LemonButton, LemonMenu, LemonMenuItem, LemonSelectOptionLeaf } from '@posthog/lemon-ui'
+
+import { IconOpenInNew, IconTableChart } from 'lib/lemon-ui/icons'
+
+import { TileId, TileVisualizationOption } from './common'
+import { LearnMorePopover, LearnMorePopoverProps } from './WebAnalyticsDashboard'
+import { WebTileOpenInsightProps } from './webTileHeaderHooks'
+
+interface DropdownConfig<T extends string> {
+ value: T
+ options: LemonSelectOptionLeaf<T>[]
+ onChange: (value: T) => void
+}
+
+export interface WebTileHeaderProps {
+ tileId: TileId
+ title?: React.ReactNode
+ titlePrefix?: string
+ titleDropdown?: DropdownConfig<string>
+ docs?: LearnMorePopoverProps
+ intervalSelector?: {
+ node: React.ReactNode
+ }
+ visualizationToggle?: {
+ value: TileVisualizationOption | undefined
+ onChange: (value: TileVisualizationOption) => void
+ }
+ openInsight?: WebTileOpenInsightProps
+ overflowMenuItems: LemonMenuItem[]
+}
+
+function TitleDropdown({ tileId, dropdown }: { tileId: TileId; dropdown: DropdownConfig<string> }): JSX.Element {
+ const currentLabel = dropdown.options.find((o) => o.value === dropdown.value)?.label ?? dropdown.value
+ const items: LemonMenuItem[] = dropdown.options.map((opt) => ({
+ label: opt.label ?? String(opt.value),
+ active: opt.value === dropdown.value,
+ onClick: () => dropdown.onChange(opt.value),
+ }))
+
+ return (
+ <LemonMenu items={items} placement="bottom-start">
+ <button
+ type="button"
+ className="inline-flex items-center gap-1 m-0 p-0 bg-transparent border-0 cursor-pointer text-base font-semibold text-current hover:text-accent underline decoration-dotted decoration-from-font underline-offset-4"
+ data-attr={`web-analytics-title-dropdown-${tileId}`}
+ >
+ <span>{currentLabel}</span>
+ <IconChevronDown className="text-lg" />
+ </button>
+ </LemonMenu>
+ )
+}
+
+export function WebTileHeader({
+ tileId,
+ title,
+ titlePrefix,
+ titleDropdown,
+ docs,
+ intervalSelector,
+ visualizationToggle,
+ openInsight,
+ overflowMenuItems,
+}: WebTileHeaderProps): JSX.Element {
+ const isGraph = visualizationToggle?.value === 'graph'
+ const titleNode =
+ titleDropdown || title || docs ? (
+ <h2 className="flex-1 m-0 flex flex-row items-center gap-1.5 text-base font-semibold">
+ {titlePrefix && <span>{titlePrefix}</span>}
+ {titleDropdown ? (
+ <TitleDropdown tileId={tileId} dropdown={titleDropdown} />
+ ) : (
+ title && <span>{title}</span>
+ )}
+ {docs && <LearnMorePopover url={docs.url} title={docs.title} description={docs.description} />}
+ </h2>
+ ) : (
+ <div className="flex-1" />
+ )
+
+ return (
+ <div className="flex flex-row items-center self-stretch gap-2 min-h-10 px-3 py-2">
+ {titleNode}
+
+ {intervalSelector && (
+ <span className="flex items-center gap-1">
+ <span className="text-secondary text-xs">Interval</span>
+ {intervalSelector.node}
+ </span>
+ )}
+
+ {visualizationToggle && (
+ <LemonButton
+ size="small"
+ icon={isGraph ? <IconTableChart /> : <IconLineGraph />}
+ tooltip={isGraph ? 'Show as table' : 'Show as graph'}
+ aria-label={isGraph ? 'Show as table' : 'Show as graph'}
+ onClick={() => visualizationToggle.onChange(isGraph ? 'table' : 'graph')}
+ data-attr={`web-analytics-viz-toggle-${tileId}`}
+ />
+ )}
+
+ {openInsight && (
+ <LemonButton
+ size="small"
+ icon={<IconOpenInNew />}
+ tooltip="Open as new insight"
+ aria-label="Open as new insight"
+ to={openInsight.to}
+ onClick={openInsight.onClick}
+ data-attr={`web-analytics-open-insight-${tileId}`}
+ >
+ Open as insight
+ </LemonButton>
+ )}
+
+ <LemonMenu items={overflowMenuItems} placement="bottom-end">
+ <LemonButton
+ icon={<IconEllipsis />}
+ size="small"
+ aria-label="More actions"
+ data-attr={`web-analytics-tile-overflow-${tileId}`}
+ />
+ </LemonMenu>
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/web-analytics/common.ts b/frontend/src/scenes/web-analytics/common.ts
index a6cd2941da82..59b606acd279 100644
--- a/frontend/src/scenes/web-analytics/common.ts
+++ b/frontend/src/scenes/web-analytics/common.ts
@@ -1,5 +1,7 @@
import { BreakPointFunction } from 'kea'
+import { LemonMenuItem } from '@posthog/lemon-ui'
+
import { PostHogComDocsURL } from 'lib/lemon-ui/Link/Link'
import { UnexpectedNeverError, getDefaultInterval } from 'lib/utils'
@@ -269,6 +271,7 @@ export interface QueryTile extends BaseTile {
insightProps: InsightLogicProps
canOpenModal?: boolean
canOpenInsight?: boolean
+ extraMenuItems?: LemonMenuItem[]
}
export interface TabsTileTab {
@@ -282,6 +285,7 @@ export interface TabsTileTab {
canOpenModal?: boolean
canOpenInsight?: boolean
docs?: Docs
+ extraMenuItems?: LemonMenuItem[]
}
export interface TabsTile extends BaseTile {
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx
index 950a93265ae7..1b7c8e924e72 100644
--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx
+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx
@@ -1,10 +1,12 @@
import clsx from 'clsx'
-import { useActions } from 'kea'
+import { useActions, useValues } from 'kea'
import { TZLabel } from 'lib/components/TZLabel'
+import { FEATURE_FLAGS } from 'lib/constants'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonTableLink } from 'lib/lemon-ui/LemonTable/LemonTableLink'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { humanFriendlyLargeNumber } from 'lib/utils'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -72,6 +74,26 @@ export const WebAnalyticsErrorTrackingTile = ({ tile }: { tile: ErrorTrackingTil
const { layout, query } = tile
const to = urls.errorTracking()
const { addProductIntentForCrossSell } = useActions(teamLogic)
+ const { featureFlags } = useValues(featureFlagLogic)
+ const useTileHeaderV2 = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_HEADER_V2] === 'test'
+
+ const viewAllButton = (
+ <LemonButton
+ to={to}
+ icon={<IconOpenInNew />}
+ onClick={() => {
+ addProductIntentForCrossSell({
+ from: ProductKey.WEB_ANALYTICS,
+ to: ProductKey.ERROR_TRACKING,
+ intent_context: ProductIntentContext.WEB_ANALYTICS_ERRORS,
+ })
+ }}
+ size="small"
+ type="secondary"
+ >
+ View all
+ </LemonButton>
+ )
return (
<div
@@ -83,27 +105,23 @@ export const WebAnalyticsErrorTrackingTile = ({ tile }: { tile: ErrorTrackingTil
layout.className
)}
>
- <h2 className="m-0 mb-3">Error tracking</h2>
- <div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
- <Query attachTo={webAnalyticsLogic} query={query} embedded={true} context={context} />
- </div>
- <div className="flex flex-row-reverse my-2">
- <LemonButton
- to={to}
- icon={<IconOpenInNew />}
- onClick={() => {
- addProductIntentForCrossSell({
- from: ProductKey.WEB_ANALYTICS,
- to: ProductKey.ERROR_TRACKING,
- intent_context: ProductIntentContext.WEB_ANALYTICS_ERRORS,
- })
- }}
- size="small"
- type="secondary"
- >
- View all
- </LemonButton>
- </div>
+ {useTileHeaderV2 ? (
+ <div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
+ <div className="flex flex-row items-center self-stretch gap-2 min-h-10 px-3 py-2">
+ <h2 className="flex-1 m-0 text-base font-semibold">Error tracking</h2>
+ {viewAllButton}
+ </div>
+ <Query attachTo={webAnalyticsLogic} query={query} embedded={true} context={context} />
+ </div>
+ ) : (
+ <>
+ <h2 className="m-0 mb-3">Error tracking</h2>
+ <div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
+ <Query attachTo={webAnalyticsLogic} query={query} embedded={true} context={context} />
+ </div>
+ <div className="flex flex-row-reverse my-2">{viewAllButton}</div>
+ </>
+ )}
</div>
)
}
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsRecordings.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsRecordings.tsx
index d4ba3bbc2cc9..076d03cc3c50 100644
--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsRecordings.tsx
+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsRecordings.tsx
@@ -4,9 +4,11 @@ import { useActions, useValues } from 'kea'
import { EmptyMessage } from 'lib/components/EmptyMessage/EmptyMessage'
import ViewRecordingButton from 'lib/components/ViewRecordingButton/ViewRecordingButton'
import ViewRecordingsPlaylistButton from 'lib/components/ViewRecordingButton/ViewRecordingsPlaylistButton'
+import { FEATURE_FLAGS } from 'lib/constants'
import { LemonSkeleton } from 'lib/lemon-ui/LemonSkeleton'
import { LemonTable } from 'lib/lemon-ui/LemonTable'
import { ProfilePicture } from 'lib/lemon-ui/ProfilePicture'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { humanFriendlyDuration } from 'lib/utils'
import { asDisplay } from 'scenes/persons/person-utils'
import { ActivityScoreLabel } from 'scenes/session-recordings/components/RecordingRow'
@@ -24,6 +26,8 @@ export function WebAnalyticsRecordingsTile({ tile }: { tile: ReplayTile }): JSX.
const { replayFilters, webAnalyticsFilters } = useValues(webAnalyticsLogic)
const { currentTeam } = useValues(teamLogic)
const { addProductIntentForCrossSell } = useActions(teamLogic)
+ const { featureFlags } = useValues(featureFlagLogic)
+ const useTileHeaderV2 = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_HEADER_V2] === 'test'
const sessionRecordingsListLogicInstance = sessionRecordingsPlaylistLogic({
logicKey: 'webAnalytics',
@@ -53,6 +57,76 @@ export function WebAnalyticsRecordingsTile({ tile }: { tile: ReplayTile }): JSX.
buttonText: 'Learn more',
buttonTo: 'https://posthog.com/docs/user-guides/recordings',
}
+ const viewAllButton = (
+ <div
+ onClick={() => {
+ addProductIntentForCrossSell({
+ from: ProductKey.WEB_ANALYTICS,
+ to: ProductKey.SESSION_REPLAY,
+ intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
+ })
+ }}
+ >
+ <ViewRecordingsPlaylistButton filters={replayFilters} size="small" type="secondary" label="View all" />
+ </div>
+ )
+
+ const tableContent = sessionRecordingsResponseLoading ? (
+ <div className="p-2 deprecated-space-y-6">
+ {Array.from({ length: 6 }, (_, index) => (
+ <LemonSkeleton key={index} />
+ ))}
+ </div>
+ ) : items.length === 0 && emptyMessage ? (
+ <EmptyMessage {...emptyMessage} />
+ ) : (
+ <LemonTable
+ className="mt-4"
+ columns={[
+ {
+ title: 'Person',
+ render: (_, recording: SessionRecordingType) => (
+ <>
+ <ProfilePicture size="sm" name={asDisplay(recording.person)} className="mr-2" />
+ {asDisplay(recording.person)}{' '}
+ </>
+ ),
+ },
+ {
+ title: 'Activity',
+ render: (_, recording: SessionRecordingType) => (
+ <>
+ <ActivityScoreLabel score={recording.activity_score} clean={true} />
+ </>
+ ),
+ },
+ {
+ title: 'Duration',
+ render: (_, recording: SessionRecordingType) => (
+ <>{humanFriendlyDuration(recording.recording_duration)}</>
+ ),
+ },
+ {
+ title: 'Recording',
+ render: (_, recording: SessionRecordingType) => (
+ <div
+ onClick={() => {
+ addProductIntentForCrossSell({
+ from: ProductKey.WEB_ANALYTICS,
+ to: ProductKey.SESSION_REPLAY,
+ intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
+ })
+ }}
+ >
+ <ViewRecordingButton sessionId={recording.id ?? ''} size="xsmall" />
+ </div>
+ ),
+ },
+ ]}
+ dataSource={items}
+ />
+ )
+
return (
<>
<div
@@ -64,86 +138,23 @@ export function WebAnalyticsRecordingsTile({ tile }: { tile: ReplayTile }): JSX.
layout.className
)}
>
- <h2 className="m-0 mb-3">Session replay</h2>
- <div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
- {sessionRecordingsResponseLoading ? (
- <div className="p-2 deprecated-space-y-6">
- {Array.from({ length: 6 }, (_, index) => (
- <LemonSkeleton key={index} />
- ))}
+ {useTileHeaderV2 ? (
+ <div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
+ <div className="flex flex-row items-center self-stretch gap-2 min-h-10 px-3 py-2">
+ <h2 className="flex-1 m-0 text-base font-semibold">Session replay</h2>
+ {viewAllButton}
</div>
- ) : items.length === 0 && emptyMessage ? (
- <EmptyMessage {...emptyMessage} />
- ) : (
- <LemonTable
- className="mt-4"
- columns={[
- {
- title: 'Person',
- render: (_, recording: SessionRecordingType) => (
- <>
- <ProfilePicture
- size="sm"
- name={asDisplay(recording.person)}
- className="mr-2"
- />
- {asDisplay(recording.person)}{' '}
- </>
- ),
- },
- {
- title: 'Activity',
- render: (_, recording: SessionRecordingType) => (
- <>
- <ActivityScoreLabel score={recording.activity_score} clean={true} />
- </>
- ),
- },
- {
- title: 'Duration',
- render: (_, recording: SessionRecordingType) => (
- <>{humanFriendlyDuration(recording.recording_duration)}</>
- ),
- },
- {
- title: 'Recording',
- render: (_, recording: SessionRecordingType) => (
- <div
- onClick={() => {
- addProductIntentForCrossSell({
- from: ProductKey.WEB_ANALYTICS,
- to: ProductKey.SESSION_REPLAY,
- intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
- })
- }}
- >
- <ViewRecordingButton sessionId={recording.id ?? ''} size="xsmall" />
- </div>
- ),
- },
- ]}
- dataSource={items}
- />
- )}
- </div>
- <div className="flex flex-row-reverse my-2">
- <div
- onClick={() => {
- addProductIntentForCrossSell({
- from: ProductKey.WEB_ANALYTICS,
- to: ProductKey.SESSION_REPLAY,
- intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
- })
- }}
- >
- <ViewRecordingsPlaylistButton
- filters={replayFilters}
- size="small"
- type="secondary"
- label="View all"
- />
+ {tableContent}
</div>
- </div>
+ ) : (
+ <>
+ <h2 className="m-0 mb-3">Session replay</h2>
+ <div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
+ {tableContent}
+ </div>
+ <div className="flex flex-row-reverse my-2">{viewAllButton}</div>
+ </>
+ )}
</div>
</>
)
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
index 1003477695ab..5125d02155b5 100644
--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsTile.tsx
@@ -633,7 +633,11 @@ export const WebStatsTrendTile = ({
showIntervalTile,
insightProps,
attachTo,
-}: QueryWithInsightProps<InsightVizNode> & { showIntervalTile?: boolean }): JSX.Element => {
+ headerSlot,
+}: QueryWithInsightProps<InsightVizNode> & {
+ showIntervalTile?: boolean
+ headerSlot?: React.ReactNode
+}): JSX.Element => {
const { togglePropertyFilter, setDateInterval, zoomIntoPeriod, resetZoom } = useActions(webAnalyticsLogic)
const {
hasCountryFilter,
@@ -760,6 +764,7 @@ export const WebStatsTrendTile = ({
return (
<div className="border rounded bg-surface-primary flex-1 flex flex-col">
+ {headerSlot}
{(showIntervalTile || preZoomDateFilter) && (
<div className="flex flex-row items-center justify-end m-2 mr-4">
<div className="flex flex-row items-center gap-2">
@@ -885,10 +890,12 @@ export const WebStatsTableTile = ({
insightProps,
control,
attachTo,
+ headerSlot,
}: QueryWithInsightProps<DataTableNode> & {
breakdownBy: WebStatsBreakdown
control?: JSX.Element
tileId: TileId
+ headerSlot?: React.ReactNode
}): JSX.Element => {
const { togglePropertyFilter } = useActions(webAnalyticsLogic)
const { productTab } = useValues(webAnalyticsLogic)
@@ -1054,6 +1061,7 @@ export const WebStatsTableTile = ({
return (
<div className="border rounded bg-surface-primary flex-1 flex flex-col">
+ {headerSlot}
{control != null && <div className="flex flex-row items-center justify-end m-2 mr-4">{control}</div>}
<WebAnalyticsTileSkeletonGate
dataNodeLogicProps={dataNodeLogicProps}
@@ -1129,7 +1137,8 @@ export const WebGoalsTile = ({
query,
insightProps,
attachTo,
-}: QueryWithInsightProps<DataTableNode>): JSX.Element | null => {
+ headerSlot,
+}: QueryWithInsightProps<DataTableNode> & { headerSlot?: React.ReactNode }): JSX.Element | null => {
const { actions, actionsLoading } = useValues(actionsModel)
const { updateHasSeenProductIntroFor } = useActions(userLogic)
@@ -1153,10 +1162,15 @@ export const WebGoalsTile = ({
)
}
- return <WebGoalsTileContent query={query} insightProps={insightProps} attachTo={attachTo} />
+ return <WebGoalsTileContent query={query} insightProps={insightProps} attachTo={attachTo} headerSlot={headerSlot} />
}
-const WebGoalsTileContent = ({ query, insightProps, attachTo }: QueryWithInsightProps<DataTableNode>): JSX.Element => {
+const WebGoalsTileContent = ({
+ query,
+ insightProps,
+ attachTo,
+ headerSlot,
+}: QueryWithInsightProps<DataTableNode> & { headerSlot?: React.ReactNode }): JSX.Element => {
const { addProductIntentForCrossSell } = useActions(teamLogic)
const context = useMemo((): QueryContext => {
@@ -1166,23 +1180,25 @@ const WebGoalsTileContent = ({ query, insightProps, attachTo }: QueryWithInsight
return (
<div className="border rounded bg-surface-primary flex-1">
- <div className="flex flex-row-reverse p-2">
- <LemonButton
- to={urls.actions()}
- onClick={() => {
- addProductIntentForCrossSell({
- from: ProductKey.WEB_ANALYTICS,
- to: ProductKey.ACTIONS,
- intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
- })
- }}
- sideIcon={<IconOpenInNew />}
- type="secondary"
- size="small"
- >
- Manage actions
- </LemonButton>
- </div>
+ {headerSlot ?? (
+ <div className="flex flex-row-reverse p-2">
+ <LemonButton
+ to={urls.actions()}
+ onClick={() => {
+ addProductIntentForCrossSell({
+ from: ProductKey.WEB_ANALYTICS,
+ to: ProductKey.ACTIONS,
+ intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
+ })
+ }}
+ sideIcon={<IconOpenInNew />}
+ type="secondary"
+ size="small"
+ >
+ Manage actions
+ </LemonButton>
+ </div>
+ )}
<WebAnalyticsTileSkeletonGate
dataNodeLogicProps={dataNodeLogicProps}
skeleton={<TableTileSkeleton numericColumns={4} />}
@@ -1197,7 +1213,8 @@ export const WebExternalClicksTile = ({
query,
insightProps,
attachTo,
-}: QueryWithInsightProps<DataTableNode>): JSX.Element | null => {
+ headerSlot,
+}: QueryWithInsightProps<DataTableNode> & { headerSlot?: React.ReactNode }): JSX.Element | null => {
const { productTab, shouldStripQueryParams } = useValues(webAnalyticsLogic)
const { setShouldStripQueryParams } = useActions(webAnalyticsLogic)
@@ -1210,6 +1227,7 @@ export const WebExternalClicksTile = ({
return (
<div className="border rounded bg-surface-primary flex-1 flex flex-col">
+ {headerSlot}
{!isPageReportsPage && (
<div className="flex flex-row items-center justify-end m-2 mr-4">
<div className="flex flex-row items-center deprecated-space-x-2">
@@ -1274,6 +1292,7 @@ interface HogQLTableTileProps {
query: DataTableNode
insightProps: InsightLogicProps
tileId: TileId
+ headerSlot?: React.ReactNode
}
// Bot tiles get their own variant so botAnalyticsLogic only mounts on the Bot Analytics tab —
@@ -1347,6 +1366,7 @@ const HogQLTableTile = (props: HogQLTableTileProps): JSX.Element => {
}
return (
<div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
+ {props.headerSlot}
<Query
uniqueKey={props.uniqueKey}
attachTo={props.attachTo}
@@ -1366,11 +1386,13 @@ export const WebQuery = ({
tileId,
attachTo,
uniqueKey,
+ headerSlot,
}: QueryWithInsightProps<QuerySchema> & {
showIntervalSelect?: boolean
control?: JSX.Element
tileId: TileId
uniqueKey: string
+ headerSlot?: React.ReactNode
}): JSX.Element => {
const { productTab, shouldStripQueryParams: stripQueryParamsDashboard } = useValues(webAnalyticsLogic)
const { stripQueryParams: stripQueryParamsPageReports } = useValues(pageReportsLogic)
@@ -1384,6 +1406,7 @@ export const WebQuery = ({
query={query}
insightProps={insightProps}
uniqueKey={uniqueKey}
+ headerSlot={headerSlot}
/>
)
}
@@ -1396,6 +1419,7 @@ export const WebQuery = ({
insightProps={insightProps}
control={control}
tileId={tileId}
+ headerSlot={headerSlot}
/>
)
}
@@ -1411,7 +1435,14 @@ export const WebQuery = ({
stripQueryParams: effectiveStripQueryParams,
},
}
- return <WebExternalClicksTile attachTo={attachTo} query={adjustedQuery} insightProps={insightProps} />
+ return (
+ <WebExternalClicksTile
+ attachTo={attachTo}
+ query={adjustedQuery}
+ insightProps={insightProps}
+ headerSlot={headerSlot}
+ />
+ )
}
if (query.kind === NodeKind.InsightVizNode && tileId === TileId.MARKETING) {
@@ -1430,12 +1461,13 @@ export const WebQuery = ({
query={query}
showIntervalTile={showIntervalSelect}
insightProps={insightProps}
+ headerSlot={headerSlot}
/>
)
}
if (query.kind === NodeKind.DataTableNode && query.source.kind === NodeKind.WebGoalsQuery) {
- return <WebGoalsTile attachTo={attachTo} query={query} insightProps={insightProps} />
+ return <WebGoalsTile attachTo={attachTo} query={query} insightProps={insightProps} headerSlot={headerSlot} />
}
if (query.kind === NodeKind.DataTableNode && query.source.kind === NodeKind.MarketingAnalyticsTableQuery) {
@@ -1470,18 +1502,22 @@ export const WebQuery = ({
query={query}
insightProps={insightProps}
tileId={tileId}
+ headerSlot={headerSlot}
/>
)
}
return (
- <Query
- uniqueKey={uniqueKey}
- attachTo={attachTo}
- query={query}
- readOnly={true}
- context={{ ...webAnalyticsDataTableQueryContext, insightProps }}
- />
+ <div className="border rounded bg-surface-primary flex-1 flex flex-col">
+ {headerSlot}
+ <Query
+ uniqueKey={uniqueKey}
+ attachTo={attachTo}
+ query={query}
+ readOnly={true}
+ context={{ ...webAnalyticsDataTableQueryContext, insightProps }}
+ />
+ </div>
)
}
@@ -1490,11 +1526,13 @@ const FrustrationMetricsTile = ({
insightProps,
attachTo,
uniqueKey,
+ headerSlot,
}: {
query: DataTableNode
insightProps: InsightLogicProps
attachTo?: BuiltLogic | LogicWrapper
uniqueKey: string
+ headerSlot?: React.ReactNode
}): JSX.Element => {
const context = useMemo((): QueryContext => {
return {
@@ -1509,6 +1547,7 @@ const FrustrationMetricsTile = ({
return (
<div className="border rounded bg-surface-primary flex-1 flex flex-col py-2 px-1">
+ {headerSlot}
<WebAnalyticsTileSkeletonGate
dataNodeLogicProps={dataNodeLogicProps}
skeleton={<TableTileSkeleton numericColumns={3} />}
diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
index 62bf2d8b61b8..443c38fd09fc 100644
--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
@@ -5,12 +5,14 @@ import { windowValues } from 'kea-window-values'
import posthog from 'posthog-js'
import { IconGear } from '@posthog/icons'
+import { LemonMenuItem } from '@posthog/lemon-ui'
import { errorTrackingQuery } from '@posthog/products-error-tracking/frontend/queries'
import api from 'lib/api'
import { AuthorizedUrlListType, authorizedUrlListLogic } from 'lib/components/AuthorizedUrlList/authorizedUrlListLogic'
import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'
import { FEATURE_FLAGS, RETENTION_FIRST_OCCURRENCE_MATCHING_FILTERS } from 'lib/constants'
+import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { Link } from 'lib/lemon-ui/Link/Link'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
@@ -26,6 +28,7 @@ import {
import { isDefinitionStale } from 'lib/utils/definitions'
import { eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { getCurrentTeamId } from 'lib/utils/getAppContext'
+import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { Scene } from 'scenes/sceneTypes'
import { teamLogic } from 'scenes/teamLogic'
@@ -45,6 +48,8 @@ import {
EventsNode,
InsightVizNode,
NodeKind,
+ ProductIntentContext,
+ ProductKey,
TrendsFilter,
TrendsQuery,
WebAnalyticsConversionGoal,
@@ -1255,6 +1260,22 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
]
}
+ const useTileHeaderV2 = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_HEADER_V2] === 'test'
+
+ const includeHostMenuItem: LemonMenuItem | null =
+ useTileHeaderV2 && featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_INCLUDE_HOST]
+ ? {
+ label: 'Include host',
+ tooltip: 'Show the full host + path (e.g. example.com/about) instead of just the path',
+ active: includeHostPath,
+ onClick: () => actions.setIncludeHostPath(!includeHostPath),
+ }
+ : null
+
+ const pathTabExtras = useTileHeaderV2
+ ? { extraMenuItems: includeHostMenuItem ? [includeHostMenuItem] : undefined }
+ : { control: <IncludeHostToggle /> }
+
const allTiles: (WebAnalyticsTile | null)[] = [
{
kind: 'query',
@@ -1391,7 +1412,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
!!featureFlags[FEATURE_FLAGS.AVERAGE_PAGE_VIEW_COLUMN],
},
{
- control: <IncludeHostToggle />,
+ ...pathTabExtras,
docs: {
url: 'https://posthog.com/docs/web-analytics/dashboard#paths',
title: 'Paths',
@@ -1438,7 +1459,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
!!featureFlags[FEATURE_FLAGS.AVERAGE_PAGE_VIEW_COLUMN],
},
{
- control: <IncludeHostToggle />,
+ ...pathTabExtras,
docs: {
url: 'https://posthog.com/docs/web-analytics/dashboard#paths',
title: 'Entry Path',
@@ -1473,7 +1494,7 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
includeHost: includeHostPath,
},
{
- control: <IncludeHostToggle />,
+ ...pathTabExtras,
docs: {
url: 'https://posthog.com/docs/web-analytics/dashboard#paths',
title: 'End Path',
@@ -1546,20 +1567,35 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
WebStatsBreakdown.InitialChannelType,
{},
{
- control: (
- <div className="flex flex-row deprecated-space-x-2 font-medium">
- <span>Customize channel types</span>
- <LemonButton
- icon={<IconGear />}
- type="tertiary"
- status="alt"
- size="small"
- noPadding={true}
- tooltip="Customize channel types"
- to={urls.settings('environment-web-analytics', 'channel-type')}
- />
- </div>
- ),
+ ...(useTileHeaderV2
+ ? {
+ extraMenuItems: [
+ {
+ label: 'Customize channel types',
+ icon: <IconGear />,
+ to: urls.settings('environment-web-analytics', 'channel-type'),
+ },
+ ],
+ }
+ : {
+ control: (
+ <div className="flex flex-row deprecated-space-x-2 font-medium">
+ <span>Customize channel types</span>
+ <LemonButton
+ icon={<IconGear />}
+ type="tertiary"
+ status="alt"
+ size="small"
+ noPadding={true}
+ tooltip="Customize channel types"
+ to={urls.settings(
+ 'environment-web-analytics',
+ 'channel-type'
+ )}
+ />
+ </div>
+ ),
+ }),
docs: {
url: 'https://posthog.com/docs/data/channel-type',
title: 'Channels',
@@ -2140,6 +2176,22 @@ export const webAnalyticsLogic = kea<webAnalyticsLogicType>([
},
insightProps: createInsightProps(TileId.GOALS),
canOpenInsight: false,
+ extraMenuItems: useTileHeaderV2
+ ? [
+ {
+ label: 'Manage actions',
+ icon: <IconOpenInNew />,
+ to: urls.actions(),
+ onClick: () => {
+ void addProductIntentForCrossSell({
+ from: ProductKey.WEB_ANALYTICS,
+ to: ProductKey.ACTIONS,
+ intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
+ })
+ },
+ },
+ ]
+ : undefined,
docs: {
url: 'https://posthog.com/docs/web-analytics/dashboard#goals',
title: 'Goals',
diff --git a/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsx b/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsx
new file mode 100644
index 000000000000..74a1db41e320
--- /dev/null
+++ b/frontend/src/scenes/web-analytics/webTileHeaderHooks.tsx
@@ -0,0 +1,156 @@
+import { useActions, useValues } from 'kea'
+import { useMemo } from 'react'
+
+import { IconExpand45 } from '@posthog/icons'
+import { LemonButtonProps, LemonMenuItem } from '@posthog/lemon-ui'
+
+import { copyToClipboard } from 'lib/utils/copyToClipboard'
+import { addProductIntentForCrossSell } from 'lib/utils/product-intents'
+import { insightDataLogic } from 'scenes/insights/insightDataLogic'
+
+import {
+ ProductIntentContext,
+ ProductKey,
+ QuerySchema,
+ TrendsQueryResponse,
+ WebStatsTableQueryResponse,
+} from '~/queries/schema/schema-general'
+import { ExporterFormat, InsightLogicProps } from '~/types'
+
+import { TileId, WEB_ANALYTICS_DATA_COLLECTION_NODE_ID } from './common'
+import {
+ CalendarHeatmapAdapter,
+ ExportAdapter,
+ TrendsAdapter,
+ WebAnalyticsTableAdapter,
+ WorldMapAdapter,
+ exportTableData,
+} from './webAnalyticsExportUtils'
+import { webAnalyticsModalLogic } from './webAnalyticsModalLogic'
+
+const NO_ACTIVE_TAB_INSIGHT_PROPS: InsightLogicProps = {
+ dashboardItemId: 'new-AdHoc.web-analytics-no-active-tab-fallback',
+ dataNodeCollectionId: WEB_ANALYTICS_DATA_COLLECTION_NODE_ID,
+}
+
+export function useWebTileExportAdapter(
+ query: QuerySchema | undefined,
+ insightProps: InsightLogicProps
+): ExportAdapter | null {
+ const builtInsightDataLogic = insightDataLogic(insightProps)
+ const { insightDataRaw } = useValues(builtInsightDataLogic)
+
+ return useMemo(() => {
+ if (!insightDataRaw || !query) {
+ return null
+ }
+ const adapters: ExportAdapter[] = [
+ new CalendarHeatmapAdapter(insightDataRaw as TrendsQueryResponse, query),
+ new WorldMapAdapter(insightDataRaw as TrendsQueryResponse, query),
+ new WebAnalyticsTableAdapter(insightDataRaw as WebStatsTableQueryResponse, query),
+ new TrendsAdapter(insightDataRaw as TrendsQueryResponse, query),
+ ]
+ return adapters.find((a) => a.canHandle()) ?? null
+ }, [insightDataRaw, query])
+}
+
+interface UseWebTileOverflowMenuItemsArgs {
+ tileId: TileId
+ tabId?: string
+ query?: QuerySchema
+ insightProps?: InsightLogicProps
+ canOpenModal?: boolean
+ extraMenuItems?: LemonMenuItem[]
+}
+
+export function useWebTileOverflowMenuItems({
+ tileId,
+ tabId,
+ query,
+ insightProps,
+ canOpenModal,
+ extraMenuItems,
+}: UseWebTileOverflowMenuItemsArgs): LemonMenuItem[] {
+ const effectiveInsightProps = insightProps ?? NO_ACTIVE_TAB_INSIGHT_PROPS
+ const { openModal } = useActions(webAnalyticsModalLogic)
+ const adapter = useWebTileExportAdapter(query, effectiveInsightProps)
+
+ return useMemo(() => {
+ const copyItems: LemonMenuItem[] = [
+ {
+ label: 'Link',
+ onClick: () => {
+ void copyToClipboard(window.location.href, 'link to this view')
+ },
+ },
+ {
+ label: 'CSV',
+ disabledReason: adapter ? undefined : 'No exportable data yet',
+ onClick: () => {
+ if (!adapter) {
+ return
+ }
+ exportTableData(adapter.toTableData(), ExporterFormat.CSV)
+ },
+ },
+ {
+ label: 'Query JSON',
+ disabledReason: query ? undefined : 'No query loaded yet',
+ onClick: () => {
+ if (!query) {
+ return
+ }
+ void copyToClipboard(JSON.stringify(query, null, 2), 'query JSON')
+ },
+ },
+ ]
+
+ const items: LemonMenuItem[] = [
+ ...(extraMenuItems ?? []),
+ {
+ label: 'Copy',
+ items: copyItems,
+ 'data-attr': 'web-analytics-copy-dropdown',
+ },
+ ]
+
+ if (canOpenModal !== false) {
+ items.push({
+ label: 'Show more',
+ icon: <IconExpand45 />,
+ onClick: () => openModal(tileId, tabId),
+ })
+ }
+
+ return items
+ }, [tileId, tabId, query, canOpenModal, openModal, adapter, extraMenuItems])
+}
+
+export type WebTileOpenInsightProps = Required<Pick<LemonButtonProps, 'to' | 'onClick'>>
+
+interface UseWebTileOpenInsightArgs {
+ tileId: TileId
+ tabId?: string
+ canOpenInsight: boolean
+}
+
+const trackOpenAsNewInsightClick = (): void => {
+ void addProductIntentForCrossSell({
+ from: ProductKey.WEB_ANALYTICS,
+ to: ProductKey.PRODUCT_ANALYTICS,
+ intent_context: ProductIntentContext.WEB_ANALYTICS_INSIGHT,
+ })
+}
+
+export function useWebTileOpenInsight({
+ tileId,
+ tabId,
+ canOpenInsight,
+}: UseWebTileOpenInsightArgs): WebTileOpenInsightProps | undefined {
+ const { getNewInsightUrl } = useValues(webAnalyticsModalLogic)
+ const insightUrl = useMemo(
+ () => (canOpenInsight ? getNewInsightUrl(tileId, tabId) : undefined),
+ [canOpenInsight, getNewInsightUrl, tileId, tabId]
+ )
+ return insightUrl ? { to: insightUrl, onClick: trackOpenAsNewInsightClick } : undefined
+}