The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Add simple event tracking for drill-thrus and other "click actions" (#63792)
Nemanja Glumac5bda80e53f7d
diff --git a/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.jsindex 22886aef879..18e573e7605 100644--- a/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js+++ b/e2e/test/scenarios/visualizations-tabular/drillthroughs/chart_drill.cy.spec.js@@ -1,6 +1,7 @@const { H } = cy;import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";+import { ORDERS_BY_YEAR_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID, PEOPLE, PEOPLE_ID } =SAMPLE_DATABASE;@@ -853,4 +854,94 @@ describe("scenarios > visualizations > drillthroughs > chart drill", () => {cy.findByText("≠").should("be.visible");});});++ H.describeWithSnowplow("chart click actions analytics", () => {+ beforeEach(() => {+ H.resetSnowplow();+ H.restore();+ cy.signInAsAdmin();+ H.enableTracking();+ });++ afterEach(() => {+ H.expectNoBadSnowplowEvents();+ });++ // This list is not exhaustive. It only covers the events that were defined in a ticket defined by Product.+ // The full list can be found in frontend/src/metabase/visualizations/types/click-actions.ts+ // See: `type ClickActionSection`+ it("should track clicks on action sections", () => {+ H.visitQuestion(ORDERS_BY_YEAR_QUESTION_ID);++ H.cartesianChartCircle().eq(1).should("be.visible").click();++ H.popover()+ .findByText(/^See these/)+ .click();++ H.expectUnstructuredSnowplowEvent({+ event: "click_action",+ triggered_from: "records",+ });++ cy.go("back");+ H.cartesianChartCircle().eq(1).should("be.visible").click();+ H.popover()+ .findByText(/^See this year/)+ .click();++ H.expectUnstructuredSnowplowEvent({+ event: "click_action",+ triggered_from: "zoom",+ });++ H.cartesianChartCircle().eq(1).should("be.visible").click();+ H.popover()+ .findByText(/^Break out by/)+ .click();++ H.expectUnstructuredSnowplowEvent({+ event: "click_action",+ triggered_from: "breakout",+ });++ H.cartesianChartCircle().eq(1).should("be.visible").click();+ H.popover().findByText(">").click();++ H.expectUnstructuredSnowplowEvent({+ event: "click_action",+ triggered_from: "filter",+ });++ cy.go("back");++ H.cartesianChartCircle().eq(1).should("be.visible").click();+ H.popover()+ .findByText(/^Automatic insights/)+ .click();++ H.expectUnstructuredSnowplowEvent({+ event: "click_action",+ triggered_from: "auto",+ });++ H.popover().findByText("X-ray").click();+ H.expectUnstructuredSnowplowEvent({+ event: "x-ray_automatic_insights_clicked",+ event_detail: "x-ray",+ });++ cy.go("back");++ H.cartesianChartCircle().eq(1).should("be.visible").click();+ H.popover()+ .findByText(/^Automatic insights/)+ .click();+ H.popover().findByText("Compare to the rest").click();+ H.expectUnstructuredSnowplowEvent({+ event: "x-ray_automatic_insights_clicked",+ event_detail: "compare_to_rest",+ });+ });+ });});diff --git a/frontend/src/metabase-types/analytics/event.ts b/frontend/src/metabase-types/analytics/event.tsindex b70b4254e43..406e71fc769 100644--- a/frontend/src/metabase-types/analytics/event.ts+++ b/frontend/src/metabase-types/analytics/event.ts@@ -5,6 +5,7 @@ import type {} from "metabase/home/components/Onboarding/types";import type { MetadataEditAnalyticsDetail } from "metabase/metadata/pages/DataModel/types";import type { KeyboardShortcutId } from "metabase/palette/shortcuts";+import type { ClickActionSection } from "metabase/visualizations/types";import type {Engine,RelatedDashboardXRays,@@ -362,10 +363,16 @@ export type XRaySuggestionClickedEvent = ValidateEvent<{triggered_from: "suggestion_sidebar";}>;+export type XRayAutoInsightsClicked = ValidateEvent<{+ event: "x-ray_automatic_insights_clicked";+ event_detail: "x-ray" | "compare_to_rest";+}>;+export type XRayClickedEvent =| XRayTableClickedEvent| XRayDataReferenceClickedEvent- | XRaySuggestionClickedEvent;+ | XRaySuggestionClickedEvent+ | XRayAutoInsightsClicked;export type XRaySavedEvent = ValidateEvent<{event: "x-ray_saved";@@ -463,6 +470,11 @@ export type BookmarkDocumentEvent = ValidateEvent<{triggered_from: "collection_list" | "document_header";}>;+export type ClickActionPerformedEvent = ValidateEvent<{+ event: "click_action";+ triggered_from: ClickActionSection;+}>;+export type BookmarkEvent =| BookmarkQuestionEvent| BookmarkModelEvent@@ -521,4 +533,5 @@ export type SimpleEvent =| RevertVersionEvent| LearnAboutDataClickedEvent| MetadataEditEvent- | BookmarkEvent;+ | BookmarkEvent+ | ClickActionPerformedEvent;diff --git a/frontend/src/metabase/visualizations/analytics.ts b/frontend/src/metabase/visualizations/analytics.tsnew file mode 100644index 00000000000..ad1606b8912--- /dev/null+++ b/frontend/src/metabase/visualizations/analytics.ts@@ -0,0 +1,24 @@+import { match } from "ts-pattern";++import { trackSimpleEvent } from "metabase/lib/analytics";++import type { RegularClickAction } from "./types";++export const trackClickActionPerformed = (action: RegularClickAction) => {+ trackSimpleEvent({+ event: "click_action",+ triggered_from: action.section,+ });++ if (action.section === "auto-popover") {+ const event = match(action.name)+ .with("automatic-insights.compare", () => "compare_to_rest" as const)+ .with("automatic-insights.xray", () => "x-ray" as const)+ .otherwise(() => "x-ray" as const);++ trackSimpleEvent({+ event: "x-ray_automatic_insights_clicked",+ event_detail: event,+ });+ }+};diff --git a/frontend/src/metabase/visualizations/components/ClickActions/ClickActionsView.tsx b/frontend/src/metabase/visualizations/components/ClickActions/ClickActionsView.tsxindex 7f0d2125d36..6aad6eeb6cb 100644--- a/frontend/src/metabase/visualizations/components/ClickActions/ClickActionsView.tsx+++ b/frontend/src/metabase/visualizations/components/ClickActions/ClickActionsView.tsx@@ -1,5 +1,6 @@import type { HTMLAttributes } from "react";+import { trackClickActionPerformed } from "metabase/visualizations/analytics";import type { RegularClickAction } from "metabase/visualizations/types";import { ClickActionControl } from "./ClickActionControl";@@ -52,7 +53,10 @@ export const ClickActionsView = ({key={action.name}action={action}close={close}- onClick={() => onClick(action)}+ onClick={() => {+ trackClickActionPerformed(action);+ onClick(action);+ }}/>))}{withBottomDivider && <Divider />}