: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): read an empty error tracking tile as good news (#101901)
Mike Warrend26baa3d22fb
diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.test.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.test.tsxnew file mode 100644index 000000000000..629f072ab0ec--- /dev/null+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.test.tsx@@ -0,0 +1,93 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'++import '@testing-library/jest-dom'++import { cleanup, render, screen, waitFor } from '@testing-library/react'++import { errorTrackingQuery } from '@posthog/products-error-tracking/frontend/queries'++import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'+import { ProductSetupStatus } from 'lib/components/ProductEmptyState/types'+import { teamLogic } from 'scenes/teamLogic'+import { ErrorTrackingTile, TileId } from 'scenes/web-analytics/common'++import { useMocks } from '~/mocks/jest'+import { ProductKey } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'+import { FilterLogicalOperator } from '~/types'++import { WebAnalyticsErrorTrackingTile } from './WebAnalyticsErrorTracking'++describe('WebAnalyticsErrorTrackingTile', () => {+ const tile: ErrorTrackingTile = {+ kind: 'error_tracking',+ tileId: TileId.ERROR_TRACKING,+ layout: {},+ query: errorTrackingQuery({+ orderBy: 'users',+ dateRange: { date_from: '-7d', date_to: null },+ filterTestAccounts: false,+ filterGroup: { type: FilterLogicalOperator.And, values: [] },+ columns: ['error', 'users', 'occurrences', 'last_seen'],+ limit: 4,+ }),+ }++ beforeEach(() => {+ initKeaTests()+ useMocks({+ post: {+ '/api/environments/:team_id/query/': { results: [] },+ },+ })+ })++ afterEach(() => {+ cleanup()+ })++ const mountWithSetupStatus = (autocaptureOptIn: boolean, setupStatus: ProductSetupStatus | null): void => {+ teamLogic.mount()+ teamLogic.actions.loadCurrentTeamSuccess({+ ...MOCK_DEFAULT_TEAM,+ autocapture_exceptions_opt_in: autocaptureOptIn,+ })+ const setup = productSetupStatusLogic({ productKey: ProductKey.ERROR_TRACKING })+ setup.mount()+ if (setupStatus) {+ setup.actions.setDetectedStatus(setupStatus)+ }+ }++ it.each([+ {+ name: 'good news when exceptions already reach the project',+ autocaptureOptIn: false,+ setupStatus: 'has-data' as const,+ expected: 'No errors found!',+ },+ {+ name: 'good news when autocapture is on but nothing has errored yet',+ autocaptureOptIn: true,+ setupStatus: 'needs-setup' as const,+ expected: 'No errors found!',+ },+ {+ name: 'a nudge when nothing reports errors, so a missing SDK does not read as no errors',+ autocaptureOptIn: false,+ setupStatus: 'needs-setup' as const,+ expected: 'Error tracking is not set up',+ },+ {+ name: 'the generic copy while setup detection has not answered',+ autocaptureOptIn: false,+ setupStatus: null,+ expected: 'There are no matching events for this query',+ },+ ])('reads an empty table as $name', async ({ autocaptureOptIn, setupStatus, expected }) => {+ mountWithSetupStatus(autocaptureOptIn, setupStatus)+ render(<WebAnalyticsErrorTrackingTile tile={tile} />)++ await waitFor(() => expect(screen.getByText(expected)).toBeInTheDocument())+ })+})diff --git a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsxindex 9d055d506cda..361963cfc027 100644--- a/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx+++ b/frontend/src/scenes/web-analytics/tiles/WebAnalyticsErrorTracking.tsx@@ -1,6 +1,12 @@import clsx from 'clsx'import { useActions, useValues } from 'kea'+import { useCallback, useMemo } from 'react'+import * as panicPng from '@posthog/brand/hoggies/png/panic'+import * as starPng from '@posthog/brand/hoggies/png/star'++import { pngHoggie } from 'lib/brand/hoggies'+import { productSetupStatusLogic } from 'lib/components/ProductEmptyState/productSetupStatusLogic'import { TZLabel } from 'lib/components/TZLabel'import { FEATURE_FLAGS } from 'lib/constants'import { IconOpenInNew } from 'lib/lemon-ui/icons'@@ -18,6 +24,9 @@ import { Query } from '~/queries/Query/Query'import { ErrorTrackingIssue, ProductIntentContext, ProductKey } from '~/queries/schema/schema-general'import { QueryContext, QueryContextColumnComponent } from '~/queries/types'+const HedgehogStar = pngHoggie(starPng)+const HedgehogPanic = pngHoggie(panicPng)+export const CustomGroupTitleColumn: QueryContextColumnComponent = (props) => {const record = props.record as ErrorTrackingIssue@@ -45,7 +54,7 @@ const CountColumn = ({ record, columnName }: { record: unknown; columnName: strireturn <>{humanFriendlyLargeNumber(count)}</>}-const context: QueryContext = {+const baseContext: QueryContext = {extraDataTableQueryFeatures: [QueryFeature.hideLoadNextButton],showOpenEditorButton: false,showQueryEditor: false,@@ -74,23 +83,65 @@ export const WebAnalyticsErrorTrackingTile = ({ tile }: { tile: ErrorTrackingTilconst { layout, query } = tileconst to = urls.errorTracking()const { addProductIntentForCrossSell } = useActions(teamLogic)+ const { currentTeam } = useValues(teamLogic)const { featureFlags } = useValues(featureFlagLogic)+ const { status: errorTrackingStatus } = useValues(+ productSetupStatusLogic({ productKey: ProductKey.ERROR_TRACKING })+ )const useTileHeaderV2 = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_HEADER_V2] === 'test'+ // An empty table only means good news when exceptions do reach this project: either+ // some have already been grouped into issues, or autocapture is on and will send them.+ const errorsAreReported = errorTrackingStatus === 'has-data' || !!currentTeam?.autocapture_exceptions_opt_in++ const crossSellToErrorTracking = useCallback((): void => {+ addProductIntentForCrossSell({+ from: ProductKey.WEB_ANALYTICS,+ to: ProductKey.ERROR_TRACKING,+ intent_context: ProductIntentContext.WEB_ANALYTICS_ERRORS,+ })+ }, [addProductIntentForCrossSell])++ const context = useMemo((): QueryContext => {+ if (errorsAreReported) {+ return {+ ...baseContext,+ emptyStateIcon: <HedgehogStar className="w-32 mb-2" />,+ emptyStateHeading: 'No errors found!',+ emptyStateDetail: 'Keep up the great work!',+ }+ }+ if (errorTrackingStatus === 'needs-setup') {+ return {+ ...baseContext,+ emptyStateIcon: <HedgehogPanic className="w-32 mb-2" />,+ emptyStateHeading: 'Error tracking is not set up',+ emptyStateDetail: (+ <>+ See the exceptions your visitors hit, grouped by issue and linked to the session they happened+ in.+ <span className="mt-2 flex justify-center">+ <LemonButton+ to={to}+ onClick={crossSellToErrorTracking}+ size="small"+ type="primary"+ data-attr="web-analytics-error-tracking-setup"+ >+ Set up error tracking+ </LemonButton>+ </span>+ </>+ ),+ }+ }+ // Detection is still loading, or it failed. Neither answer is safe to act on, so the+ // generic copy stands: it promises nothing about whether errors are being reported.+ return baseContext+ }, [errorsAreReported, errorTrackingStatus, to, crossSellToErrorTracking])+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"- >+ <LemonButton to={to} icon={<IconOpenInNew />} onClick={crossSellToErrorTracking} size="small" type="secondary">View all</LemonButton>)