Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Add Snowplow Events for Data Studio (#66383)

Anderson438230281b04
diff --git a/e2e/test/scenarios/data-reference/glossary.cy.spec.ts b/e2e/test/scenarios/data-reference/glossary.cy.spec.ts
index d583d41e4cb..da4883953ba 100644
--- a/e2e/test/scenarios/data-reference/glossary.cy.spec.ts
+++ b/e2e/test/scenarios/data-reference/glossary.cy.spec.ts
@@ -1,5 +1,91 @@
const { H } = cy;
+function executeCreateGlossaryTermFlow() {
+ cy.intercept("POST", "/api/glossary", (req) => {
+ expect(req.body).to.deep.equal({
+ term: "Bird",
+ definition: "A thing with wings.",
+ });
+ }).as("createGlossary");
+
+ cy.findByRole("button", { name: /new term/i }).click();
+
+ cy.findByPlaceholderText(/bird/i).type(" Bird ");
+ cy.findByPlaceholderText(/a warm-blooded.*/i).type(" A thing with wings. ");
+
+ cy.findByLabelText("Save").click();
+
+ cy.wait("@createGlossary");
+
+ cy.get("table").within(() => {
+ cy.findByText("Bird").should("be.visible");
+ cy.findByText("A thing with wings.").should("be.visible");
+ });
+}
+
+function executeUpdateGlossaryTermFlow(visitPageFn: VoidFunction) {
+ cy.request("POST", "/api/glossary", {
+ term: "Cat",
+ definition: "Meows",
+ }).then(({ body }) => {
+ const { id } = body;
+
+ cy.intercept("PUT", `/api/glossary/${id}`, (req) => {
+ expect(req.body).to.deep.equal({
+ term: "Kitten",
+ definition: "Young cat",
+ });
+ }).as("updateGlossary");
+
+ visitPageFn();
+
+ cy.get("table").within(() => {
+ cy.findByText("Cat").click();
+ });
+
+ cy.findByPlaceholderText(/bird/i).clear().type("Kitten");
+ cy.findByPlaceholderText(/a warm-blooded.*/i)
+ .clear()
+ .type("Young cat");
+
+ cy.findByRole("button", { name: /save/i }).click();
+
+ cy.wait("@updateGlossary");
+
+ cy.get("table").within(() => {
+ cy.findByText("Kitten").should("be.visible");
+ cy.findByText("Young cat").should("be.visible");
+ });
+ });
+}
+
+function executeDeleteGlossaryTermFlow(visitPageFn: VoidFunction) {
+ cy.request("POST", "/api/glossary", {
+ term: "DeleteMe",
+ definition: "To be removed",
+ }).then(({ body }) => {
+ const { id } = body;
+ cy.intercept("DELETE", `/api/glossary/${id}`).as("deleteGlossary");
+
+ visitPageFn();
+
+ cy.get("table").within(() => {
+ cy.findByText("DeleteMe").should("be.visible").realHover();
+ cy.findByRole("button", { name: /delete/i }).click();
+ });
+
+ cy.findByRole("dialog").within(() => {
+ cy.findByRole("button", { name: /delete/i }).click();
+ });
+
+ cy.wait("@deleteGlossary");
+
+ cy.get("table").within(() => {
+ cy.findByText("DeleteMe").should("not.exist");
+ });
+ });
+}
+
describe("data reference > glossary", () => {
beforeEach(() => {
H.restore();
@@ -31,92 +117,53 @@ describe("data reference > glossary", () => {
});
it("creates a new definition and makes POST /api/glossary with trimmed values", () => {
- cy.intercept("POST", "/api/glossary", (req) => {
- expect(req.body).to.deep.equal({
- term: "Bird",
- definition: "A thing with wings.",
- });
- }).as("createGlossary");
-
visitGlossary();
-
- cy.findByRole("button", { name: /new term/i }).click();
-
- cy.findByPlaceholderText(/bird/i).type(" Bird ");
- cy.findByPlaceholderText(/a warm-blooded.*/i).type(
- " A thing with wings. ",
- );
-
- cy.findByLabelText("Save").click();
-
- cy.wait("@createGlossary");
-
- cy.get("table").within(() => {
- cy.findByText("Bird").should("be.visible");
- cy.findByText("A thing with wings.").should("be.visible");
- });
+ executeCreateGlossaryTermFlow();
});
it("updates an existing definition and makes PUT /api/glossary/:id", () => {
- cy.request("POST", "/api/glossary", {
- term: "Cat",
- definition: "Meows",
- }).then(({ body }) => {
- const { id } = body;
-
- cy.intercept("PUT", `/api/glossary/${id}`, (req) => {
- expect(req.body).to.deep.equal({
- term: "Kitten",
- definition: "Young cat",
- });
- }).as("updateGlossary");
-
- visitGlossary();
-
- cy.get("table").within(() => {
- cy.findByText("Cat").click();
- });
+ executeUpdateGlossaryTermFlow(visitGlossary);
+ });
- cy.findByPlaceholderText(/bird/i).clear().type("Kitten");
- cy.findByPlaceholderText(/a warm-blooded.*/i)
- .clear()
- .type("Young cat");
+ it("deletes an existing definition and makes DELETE /api/glossary/:id", () => {
+ executeDeleteGlossaryTermFlow(visitGlossary);
+ });
+});
- cy.findByRole("button", { name: /save/i }).click();
+describe("data studio > glossary", () => {
+ beforeEach(() => {
+ H.restore();
+ H.resetSnowplow();
+ cy.signInAsAdmin();
+ H.activateToken("bleeding-edge");
+ });
- cy.wait("@updateGlossary");
+ function visitDataStudioGlossary() {
+ H.DataModel.visitDataStudio();
+ cy.findByRole("img", { name: "model icon" }).click();
+ cy.findByRole("link", { name: /Glossary/ }).click();
+ cy.findByRole("heading", { name: "Glossary" }).should("be.visible");
+ }
- cy.get("table").within(() => {
- cy.findByText("Kitten").should("be.visible");
- cy.findByText("Young cat").should("be.visible");
- });
+ it("should allow creating a new definition and trigger tracking event", () => {
+ visitDataStudioGlossary();
+ executeCreateGlossaryTermFlow();
+ H.expectUnstructuredSnowplowEvent({
+ event: "data_studio_glossary_term_created",
});
});
- it("deletes an existing definition and makes DELETE /api/glossary/:id", () => {
- cy.request("POST", "/api/glossary", {
- term: "DeleteMe",
- definition: "To be removed",
- }).then(({ body }) => {
- const { id } = body;
- cy.intercept("DELETE", `/api/glossary/${id}`).as("deleteGlossary");
-
- visitGlossary();
-
- cy.get("table").within(() => {
- cy.findByText("DeleteMe").should("be.visible").realHover();
- cy.findByRole("button", { name: /delete/i }).click();
- });
-
- cy.findByRole("dialog").within(() => {
- cy.findByRole("button", { name: /delete/i }).click();
- });
-
- cy.wait("@deleteGlossary");
+ it("should allow updating an existing definition and trigger tracking event", () => {
+ executeUpdateGlossaryTermFlow(visitDataStudioGlossary);
+ H.expectUnstructuredSnowplowEvent({
+ event: "data_studio_glossary_term_updated",
+ });
+ });
- cy.get("table").within(() => {
- cy.findByText("DeleteMe").should("not.exist");
- });
+ it("should allow deleting an existing definition and trigger tracking event", () => {
+ executeDeleteGlossaryTermFlow(visitDataStudioGlossary);
+ H.expectUnstructuredSnowplowEvent({
+ event: "data_studio_glossary_term_deleted",
});
});
});
diff --git a/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts
index a3410cda339..f84153969d6 100644
--- a/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts
@@ -17,6 +17,7 @@ interface PublishModelResponse {
describe("Table editing", () => {
beforeEach(() => {
+ H.resetSnowplow();
H.restore();
cy.signInAsAdmin();
H.activateToken("bleeding-edge");
@@ -108,6 +109,10 @@ describe("Table editing", () => {
});
});
+ H.expectUnstructuredSnowplowEvent({
+ event: "data_studio_table_published",
+ });
+
// Should not show info modal again
cy.go("back");
diff --git a/e2e/test/scenarios/data-studio/modeling-library.cy.spec.ts b/e2e/test/scenarios/data-studio/modeling-library.cy.spec.ts
index f3fa5ec6868..2d0401868bd 100644
--- a/e2e/test/scenarios/data-studio/modeling-library.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/modeling-library.cy.spec.ts
@@ -47,6 +47,11 @@ describe("scenarios > data studio > modeling > library", () => {
cy.findByText("Metrics").should("be.visible");
});
+ cy.log("Verify tracking event is triggered");
+ H.expectUnstructuredSnowplowEvent({
+ event: "data_studio_library_created",
+ });
+
cy.log("Verify empty state shows on library root");
H.DataStudio.Modeling.collectionPage().within(() => {
cy.findByText("No models or metrics yet").should("be.visible");
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/analytics.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/analytics.ts
new file mode 100644
index 00000000000..36f2373ef10
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/analytics.ts
@@ -0,0 +1,37 @@
+import { trackSimpleEvent } from "metabase/lib/analytics";
+import type { CollectionId } from "metabase-types/api";
+
+export const trackDataStudioLibraryCreated = (id: CollectionId) => {
+ trackSimpleEvent({
+ event: "data_studio_library_created",
+ target_id: Number(id),
+ });
+};
+
+export const trackDataStudioTablePublished = (id: number | null) => {
+ trackSimpleEvent({
+ event: "data_studio_table_published",
+ target_id: id,
+ });
+};
+
+export const trackDataStudioGlossaryTermCreated = (id: number | null) => {
+ trackSimpleEvent({
+ event: "data_studio_glossary_term_created",
+ target_id: id,
+ });
+};
+
+export const trackDataStudioGlossaryTermUpdated = (id: number | null) => {
+ trackSimpleEvent({
+ event: "data_studio_glossary_term_updated",
+ target_id: id,
+ });
+};
+
+export const trackDataStudioGlossaryTermDeleted = (id: number | null) => {
+ trackSimpleEvent({
+ event: "data_studio_glossary_term_deleted",
+ target_id: id,
+ });
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/ModelingSectionLayout/ModelingSidebar/LibrarySection/LibrarySection.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/ModelingSectionLayout/ModelingSidebar/LibrarySection/LibrarySection.tsx
index 21c42902c95..0376c07dae6 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/ModelingSectionLayout/ModelingSidebar/LibrarySection/LibrarySection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/ModelingSectionLayout/ModelingSidebar/LibrarySection/LibrarySection.tsx
@@ -7,9 +7,11 @@ import { isLibraryCollection } from "metabase/collections/utils";
import { useDispatch, useSelector } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
import { getUserIsAdmin } from "metabase/selectors/user";
-import { ModelingSidebarSection } from "metabase-enterprise/data-studio/app/pages/ModelingSectionLayout/ModelingSidebar/ModelingSidebarSection";
+import { trackDataStudioLibraryCreated } from "metabase-enterprise/data-studio/analytics";
import type { Collection, CollectionId } from "metabase-types/api";
+import { ModelingSidebarSection } from "../ModelingSidebarSection";
+
import { CreateLibraryModal } from "./CreateLibraryModal";
import { LibraryCollectionTree } from "./LibraryCollectionTree";
@@ -38,6 +40,7 @@ export function LibrarySection({
const handleCreate = (collection: Collection) => {
closeModal();
+ trackDataStudioLibraryCreated(collection.id);
dispatch(push(Urls.dataStudioCollection(collection.id)));
};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/data-model/components/TablePicker/components/PublishModelsModal.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/data-model/components/TablePicker/components/PublishModelsModal.tsx
index c032f29aa8c..05d9b4999bf 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/data-model/components/TablePicker/components/PublishModelsModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/data-model/components/TablePicker/components/PublishModelsModal.tsx
@@ -12,6 +12,7 @@ import { useMetadataToasts } from "metabase/metadata/hooks";
import { PLUGIN_DATA_STUDIO } from "metabase/plugins";
import { Box, Button, Checkbox, Group, Modal, Text, rem } from "metabase/ui";
import { usePublishModelsMutation } from "metabase-enterprise/api";
+import { trackDataStudioTablePublished } from "metabase-enterprise/data-studio/analytics";
import type { DatabaseId, SchemaId, TableId } from "metabase-types/api";
import { getPublishSeeItLink } from "../utils";
@@ -66,6 +67,7 @@ export function PublishModelsModal({
if (error) {
sendErrorToast(t`Failed to publish models`);
} else if (data) {
+ trackDataStudioTablePublished(collectionId);
sendSuccessToast(
t`Published`,
() => {
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/glossary/pages/GlossaryPage/GlossaryPage.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/glossary/pages/GlossaryPage/GlossaryPage.tsx
index 870145f6f56..e5cc7567fa2 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/glossary/pages/GlossaryPage/GlossaryPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/glossary/pages/GlossaryPage/GlossaryPage.tsx
@@ -8,6 +8,11 @@ import {
} from "metabase/api";
import { GlossaryTable } from "metabase/reference/glossary/GlossaryTable";
import { Box, Card, Group, Stack, Text } from "metabase/ui";
+import {
+ trackDataStudioGlossaryTermCreated,
+ trackDataStudioGlossaryTermDeleted,
+ trackDataStudioGlossaryTermUpdated,
+} from "metabase-enterprise/data-studio/analytics";
import S from "./GlossaryPage.module.css";
@@ -20,20 +25,23 @@ export function GlossaryPage() {
return (
<Stack w="100%" h="100%" p="xl" bg="background-light">
<Group align="center" wrap="nowrap" justify="space-between">
- <Text fw="bold" fz="1.5rem">{t`Glossary`}</Text>
+ <Text fw="bold" fz="1.5rem" component="h1">{t`Glossary`}</Text>
</Group>
<Box w="100%" className={S.contentWrapper}>
<Card px="lg" pb="sm" withBorder shadow="none">
<GlossaryTable
glossary={glossary}
onCreate={async (term, definition) => {
- await createGlossary({ term, definition });
+ const { data } = await createGlossary({ term, definition });
+ data?.id && trackDataStudioGlossaryTermCreated(data.id);
}}
onEdit={async (id, term, definition) => {
await updateGlossary({ id, term, definition });
+ trackDataStudioGlossaryTermUpdated(id);
}}
onDelete={async (id) => {
await deleteGlossary({ id });
+ trackDataStudioGlossaryTermDeleted(id);
}}
/>
</Card>
diff --git a/frontend/src/metabase-types/analytics/event.ts b/frontend/src/metabase-types/analytics/event.ts
index 8c48c90a415..c70ebed8bef 100644
--- a/frontend/src/metabase-types/analytics/event.ts
+++ b/frontend/src/metabase-types/analytics/event.ts
@@ -505,6 +505,38 @@ export type BookmarkEvent =
| BookmarkCollectionEvent
| BookmarkDocumentEvent;
+export type DataStudioLibraryCreatedEvent = ValidateEvent<{
+ event: "data_studio_library_created";
+ target_id: number | null;
+}>;
+
+export type DataStudioTablePublishedEvent = ValidateEvent<{
+ event: "data_studio_table_published";
+ target_id: number | null;
+}>;
+
+export type DataStudioGlossaryCreatedEvent = ValidateEvent<{
+ event: "data_studio_glossary_term_created";
+ target_id: number | null;
+}>;
+
+export type DataStudioGlossaryEditedEvent = ValidateEvent<{
+ event: "data_studio_glossary_term_updated";
+ target_id: number | null;
+}>;
+
+export type DataStudioGlossaryDeletedEvent = ValidateEvent<{
+ event: "data_studio_glossary_term_deleted";
+ target_id: number | null;
+}>;
+
+export type DataStudioEvent =
+ | DataStudioLibraryCreatedEvent
+ | DataStudioTablePublishedEvent
+ | DataStudioGlossaryCreatedEvent
+ | DataStudioGlossaryEditedEvent
+ | DataStudioGlossaryDeletedEvent;
+
export type SimpleEvent =
| CustomSMTPSetupClickedEvent
| CustomSMTPSetupSuccessEvent
@@ -556,4 +588,5 @@ export type SimpleEvent =
| MetadataEditEvent
| BookmarkEvent
| RemoteSyncEvent
- | ClickActionPerformedEvent;
+ | ClickActionPerformedEvent
+ | DataStudioEvent;