: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(insights): track chart alternative previews (#103532)
Sam Penningtonb69e87a1ab23
diff --git a/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts b/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.tsindex 5651dd8a5344..0c2743932c17 100644--- a/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts+++ b/products/product_analytics/frontend/insights/chartAlternatives/chartPreviewsLogic.ts@@ -1,4 +1,5 @@import { MakeLogicType, actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'+import posthog from 'posthog-js'import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'@@ -50,6 +51,7 @@ function hasResults(response: AnyResponseType | null | undefined): boolean {export interface chartPreviewsLogicValues {alternatives: ChartDisplayOption[] // chartAlternativesLogiccurrentDisplay: ChartDisplayType // chartAlternativesLogic+ galleryOpen: boolean // chartAlternativesLogicoptions: ChartDisplayOptionGroup[] // chartAlternativesLogictrendsSource: TrendsQuery | null // chartAlternativesLogicinsightData: Record<string, any> // insightVizDataLogic@@ -64,6 +66,9 @@ export interface chartPreviewsLogicValues {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface chartPreviewsLogicActions {+ toggleGallery: () => {+ value: true+ } // chartAlternativesLogicloadDataSuccess: (response:| Record<string, any>@@ -194,11 +199,16 @@ export const chartPreviewsLogic = kea<chartPreviewsLogicType>([connect((props: ChartAlternativesLogicProps) => ({values: [chartAlternativesLogic(props),- ['alternatives', 'currentDisplay', 'options', 'trendsSource'],+ ['alternatives', 'currentDisplay', 'galleryOpen', 'options', 'trendsSource'],insightVizDataLogic(props),['insightData', 'insightDataLoading'],],- actions: [insightVizDataLogic(props), ['loadDataSuccess', 'setInsightData']],+ actions: [+ chartAlternativesLogic(props),+ ['toggleGallery'],+ insightVizDataLogic(props),+ ['loadDataSuccess', 'setInsightData'],+ ],})),actions({rememberTimeSeries: (entry: TimeSeriesEntry) => ({ entry }),@@ -299,6 +309,28 @@ export const chartPreviewsLogic = kea<chartPreviewsLogicType>([}}return {+ toggleGallery: () => {+ if (!values.galleryOpen || values.insightDataLoading) {+ return+ }+ const eligiblePreviews = values.previews.filter((preview) => !preview.option.disabledReason)+ const loadedPreviews = eligiblePreviews.filter((preview) => preview.response !== null)+ const samplePreviews = loadedPreviews.filter((preview) => preview.sample)+ posthog.capture('insight chart alternatives viewed', {+ current_display: values.currentDisplay,+ eligible_chart_count: eligiblePreviews.length,+ eligible_displays: eligiblePreviews.map((preview) => preview.option.display),+ preview_count: loadedPreviews.length,+ preview_displays: loadedPreviews.map((preview) => preview.option.display),+ sample_preview_count: samplePreviews.length,+ sample_preview_displays: samplePreviews.map((preview) => preview.option.display),+ suggested_displays: eligiblePreviews+ .filter((preview) => preview.suggested)+ .map((preview) => preview.option.display),+ all_previews_loaded:+ eligiblePreviews.length > 0 && loadedPreviews.length === eligiblePreviews.length,+ })+ },loadDataSuccess: rememberLoadedTimeSeries,setInsightData: rememberLoadedTimeSeries,}