: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(dashboards): test Metric cards in templates (#99102)
Sam Penningtonf4ad3b91b95d
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex e65c72d47c75..d3fa78a1601d 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -290,6 +290,7 @@ export const FEATURE_FLAGS = {DASHBOARD_LAYOUT_DISCARD_PROMPT: 'dashboard-layout-discard-prompt', // owner: @cory.s #team-analytics-platformDASHBOARD_SAVED_VIEWS: 'dashboard-saved-views', // owner: #team-analytics-platform, target organizations for saved dashboard-list viewsDASHBOARD_TEMPLATE_CHOOSER_EXPERIMENT: 'dashboard-template-chooser-experiment', // owner: @mattp #team-analytics-platform multivariate=control,simple,new+ DASHBOARD_TEMPLATE_METRIC_CARD: 'dashboard-template-metric-card', // owner: #team-product-analytics multivariate=control,testDASHBOARD_WIDGETS: 'dashboard-widgets', // owner: @mattp #team-analytics-platformDATA_MODELING_INCREMENTAL_VIEWS: 'data-modeling-incremental-views', // owner: #team-data-modelingDATA_MODELING_SUSPEND_FAILING_NODES: 'data-modeling-suspend-failing-nodes', // owner: #team-data-modelingdiff --git a/frontend/src/scenes/dashboard/newDashboardLogic.ts b/frontend/src/scenes/dashboard/newDashboardLogic.tsindex f644bd69ae92..daf21ab9af68 100644--- a/frontend/src/scenes/dashboard/newDashboardLogic.ts+++ b/frontend/src/scenes/dashboard/newDashboardLogic.ts@@ -17,6 +17,7 @@ import { actionToUrl, router, urlToAction } from 'kea-router'import api from 'lib/api'import { tryShowMCPHint } from 'lib/components/MCPHint/mcpHintLogic'+import { FEATURE_FLAGS } from 'lib/constants'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { featureFlagLogic } from 'lib/logic/featureFlagLogic'import { eventUsageLogic } from 'lib/utils/eventUsageLogic'@@ -38,6 +39,8 @@ import {JsonType,} from '~/types'+import { WEBSITE_METRICS_METRIC_CARD_TILES } from 'products/dashboards/frontend/websiteMetricsMetricCardTemplate'+import type { FeatureFlagsSet } from '../../lib/logic/featureFlagLogic'import type { InsightModel } from '../../types'import { UNFILED_DASHBOARDS_FOLDER } from './dashboardConstants'@@ -110,6 +113,23 @@ export function applyTemplate(return obj}+const METRIC_CARD_TEMPLATE_NAME = 'Website Metrics'++// A global scope alone does not identify the built-in: staff can promote a project template, which keeps its team_id.+function isMetricTemplate(template: DashboardTemplateType): boolean {+ return (+ template.scope === 'global' && template.team_id == null && template.template_name === METRIC_CARD_TEMPLATE_NAME+ )+}++export function applyMetricTemplateVariant(+ tiles: DashboardTemplateStoredTile[],+ template: DashboardTemplateType,+ isTestVariant: boolean+): DashboardTemplateStoredTile[] {+ return isTestVariant && isMetricTemplate(template) ? WEBSITE_METRICS_METRIC_CARD_TILES : tiles+}+function makeTilesUsingVariables(tiles: DashboardTemplateStoredTile[],variables: DashboardTemplateVariableType[]@@ -365,7 +385,7 @@ export const newDashboardLogic = kea<newDashboardLogicType>([selectors(({ props }) => ({isFeatureFlagDashboard: [() => [], () => props.featureFlagId],})),- listeners(({ actions }) => ({+ listeners(({ actions, values }) => ({addDashboard: ({ form }) => {actions.resetNewDashboard()actions.setNewDashboardValues({ ...defaultFormValues, ...form })@@ -385,7 +405,13 @@ export const newDashboardLogic = kea<newDashboardLogicType>([creationContext = null,}) => {actions.setIsLoading(true)- const tiles = makeTilesUsingVariables(template.tiles, variables)+ const isMetricTemplateTestVariant =+ isMetricTemplate(template) &&+ values.featureFlags[FEATURE_FLAGS.DASHBOARD_TEMPLATE_METRIC_CARD] === 'test'+ const tiles = makeTilesUsingVariables(+ applyMetricTemplateVariant(template.tiles, template, isMetricTemplateTestVariant),+ variables+ )const dashboardJSON = {...template,tiles,diff --git a/products/dashboards/frontend/websiteMetricsMetricCardTemplate.ts b/products/dashboards/frontend/websiteMetricsMetricCardTemplate.tsnew file mode 100644index 000000000000..c10e669804dd--- /dev/null+++ b/products/dashboards/frontend/websiteMetricsMetricCardTemplate.ts@@ -0,0 +1,665 @@+import { DashboardTemplateStoredInsightTile } from '~/types'++// Mirrors the Website Metrics dashboard used to design the metric card experiment.+export const WEBSITE_METRICS_METRIC_CARD_TILES: DashboardTemplateStoredInsightTile[] = [+ {+ type: 'INSIGHT',+ name: 'Daily visitors',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'dau',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: true,+ },+ properties: [],+ trendsFilter: {+ display: 'Metric',+ showLegend: false,+ hideWeekends: false,+ metricSummary: 'average',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: true,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'short',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: true,+ metricLineDecreaseColor: '#8c8c8c',+ metricLineIncreaseColor: '#1d4aff',+ showAlertThresholdLines: false,+ },+ compareFilter: {+ compare: true,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 0,+ y: 0,+ w: 3,+ h: 3,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 0,+ w: 1,+ h: 3,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Sessions',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: true,+ },+ properties: [],+ trendsFilter: {+ display: 'Metric',+ showLegend: false,+ hideWeekends: false,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: true,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'short',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: true,+ metricLineDecreaseColor: '#8c8c8c',+ metricLineIncreaseColor: '#621da6',+ showAlertThresholdLines: false,+ },+ compareFilter: {+ compare: true,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 3,+ y: 0,+ w: 3,+ h: 3,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 3,+ w: 1,+ h: 3,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Pageviews',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'total',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: true,+ },+ properties: [],+ trendsFilter: {+ display: 'Metric',+ showLegend: false,+ hideWeekends: false,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: true,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'short',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: true,+ metricLineDecreaseColor: '#8c8c8c',+ metricLineIncreaseColor: '#42827e',+ showAlertThresholdLines: false,+ },+ compareFilter: {+ compare: true,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 6,+ y: 0,+ w: 3,+ h: 3,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 6,+ w: 1,+ h: 3,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Pageviews per session',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'total',+ name: '$pageview',+ event: '$pageview',+ custom_name: 'Pageviews',+ },+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ custom_name: 'Sessions',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: true,+ },+ properties: [],+ trendsFilter: {+ display: 'Metric',+ formula: 'A / B',+ showLegend: false,+ hideWeekends: false,+ decimalPlaces: 1,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: true,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'short',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: true,+ metricLineDecreaseColor: '#e4a604',+ metricLineIncreaseColor: '#ce0e74',+ showAlertThresholdLines: false,+ },+ compareFilter: {+ compare: true,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 9,+ y: 0,+ w: 3,+ h: 3,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 9,+ w: 1,+ h: 3,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Sessions by channel',+ description: 'Where sessions come from: organic search, direct, referral, paid, social and so on.',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: false,+ },+ properties: [],+ trendsFilter: {+ display: 'ActionsAreaGraph',+ showLegend: true,+ hideWeekends: false,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: false,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'numeric',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: false,+ showAlertThresholdLines: false,+ },+ breakdownFilter: {+ breakdown: '$channel_type',+ breakdown_type: 'session',+ breakdown_limit: 8,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 0,+ y: 3,+ w: 6,+ h: 5,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 12,+ w: 1,+ h: 5,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Top Website Pages',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: false,+ },+ properties: [],+ trendsFilter: {+ display: 'ActionsBarValue',+ showLegend: false,+ hideWeekends: false,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: true,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'short',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: false,+ showAlertThresholdLines: false,+ },+ breakdownFilter: {+ breakdown: '$pathname',+ breakdown_type: 'event',+ breakdown_limit: 10,+ breakdown_hide_other_aggregation: true,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 6,+ y: 3,+ w: 6,+ h: 5,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 17,+ w: 1,+ h: 5,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Top referrers',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: false,+ },+ properties: [],+ trendsFilter: {+ display: 'ActionsBarValue',+ showLegend: false,+ hideWeekends: false,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: false,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: false,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'short',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: false,+ showAlertThresholdLines: false,+ },+ breakdownFilter: {+ breakdown: '$entry_referring_domain',+ breakdown_type: 'session',+ breakdown_limit: 10,+ breakdown_hide_other_aggregation: true,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 0,+ y: 8,+ w: 6,+ h: 5,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 22,+ w: 1,+ h: 5,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Search engines vs AI',+ description:+ 'Sessions that came from a search engine compared with sessions that came from an AI assistant, using the session channel type.',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ properties: [+ {+ key: '$channel_type',+ type: 'session',+ value: ['Organic Search', 'Paid Search'],+ operator: 'exact',+ },+ ],+ custom_name: 'Search engines',+ },+ {+ kind: 'EventsNode',+ math: 'unique_session',+ name: '$pageview',+ event: '$pageview',+ properties: [{ key: '$channel_type', type: 'session', value: ['AI'], operator: 'exact' }],+ custom_name: 'AI assistants',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ excludeIncompletePeriods: false,+ },+ properties: [],+ trendsFilter: {+ display: 'ActionsLineGraph',+ showLegend: true,+ hideWeekends: false,+ metricSummary: 'total',+ legendPosition: 'bottom',+ yAxisScaleType: 'linear',+ showAnnotations: false,+ metricShowChange: true,+ yAxisStartAtZero: true,+ showMultipleYAxes: true,+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ stackBreakdownValues: false,+ aggregationAxisFormat: 'numeric',+ resultCustomizationBy: 'value',+ excludeBoxPlotOutliers: true,+ metricColorByDirection: false,+ showAlertThresholdLines: false,+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 6,+ y: 8,+ w: 6,+ h: 5,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 27,+ w: 1,+ h: 5,+ minW: 1,+ minH: 2,+ },+ },+ },+ {+ type: 'INSIGHT',+ name: 'Website Users by Location',+ description: '',+ query: {+ kind: 'InsightVizNode',+ source: {+ kind: 'TrendsQuery',+ series: [+ {+ kind: 'EventsNode',+ math: 'dau',+ name: '$pageview',+ event: '$pageview',+ },+ ],+ version: 4,+ interval: 'day',+ dateRange: {+ date_from: '-30d',+ explicitDate: false,+ },+ properties: [],+ trendsFilter: {+ display: 'WorldMap',+ showLegend: false,+ yAxisScaleType: 'linear',+ showValuesOnSeries: false,+ smoothingIntervals: 1,+ showPercentStackView: false,+ aggregationAxisFormat: 'numeric',+ showAlertThresholdLines: false,+ },+ breakdownFilter: {+ breakdown: '$geoip_country_code',+ breakdown_type: 'person',+ },+ filterTestAccounts: false,+ },+ },+ layouts: {+ sm: {+ x: 0,+ y: 13,+ w: 12,+ h: 7,+ minW: 2,+ minH: 2,+ },+ xs: {+ x: 0,+ y: 32,+ w: 1,+ h: 7,+ minW: 1,+ minH: 2,+ },+ },+ },+]