Skip to content

Commit

Permalink
Snowplow event for extract action via notebook shortcut (#42095)
Browse files Browse the repository at this point in the history
* Add helper to track column extractions

* Track column extractions

* Add text for column extraction

* Pass correct extraction to trackColumnExtractViaShortcut
  • Loading branch information
romeovs committed May 3, 2024
1 parent 0691779 commit 021c35a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
37 changes: 37 additions & 0 deletions e2e/test/scenarios/custom-column/cc-shortcuts-extract.cy.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
addCustomColumn,
Expand All @@ -6,6 +7,10 @@ import {
openOrdersTable,
expressionEditorWidget,
openTable,
describeWithSnowplow,
expectNoBadSnowplowEvents,
expectGoodSnowplowEvent,
resetSnowplow,
} from "e2e/support/helpers";

const { ORDERS_ID, ORDERS } = SAMPLE_DATABASE;
Expand Down Expand Up @@ -155,3 +160,35 @@ function selectExtractColumn() {
cy.findByText("Extract columns").click();
});
}

describeWithSnowplow(
"scenarios > question > custom column > expression shortcuts > extract",
() => {
beforeEach(() => {
restore();
resetSnowplow();
cy.signInAsNormalUser();
});

afterEach(() => {
expectNoBadSnowplowEvents();
});

it("should track column extraction via shortcut", () => {
openTable({ mode: "notebook", limit: 1, table: ORDERS_ID });
addCustomColumn();
selectExtractColumn();

cy.findAllByTestId("dimension-list-item").contains("Created At").click();

popover().findAllByRole("button").contains("Hour of day").click();

expectGoodSnowplowEvent({
event: "column_extract_via_shortcut",
custom_expressions_used: ["get-hour"],
database_id: SAMPLE_DB_ID,
question_id: 0,
});
});
},
);
18 changes: 18 additions & 0 deletions frontend/src/metabase/query_builder/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,21 @@ export const trackColumnCombineViaShortcut = (query, question) => {
question_id: question?.id() ?? 0,
});
};

export const trackColumnExtractViaShortcut = (
query,
stageIndex,
extraction,
question,
) => {
trackSchemaEvent("question", "1-0-4", {
event: "column_extract_via_shortcut",
custom_expressions_used: Lib.functionsUsedByExtraction(
query,
stageIndex,
extraction,
),
database_id: Lib.databaseID(query),
question_id: question?.id() ?? 0,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import * as Lib from "metabase-lib";
import { isExpression } from "metabase-lib/v1/expressions";
import type { Expression } from "metabase-types/api";

import { trackColumnCombineViaShortcut } from "../../analytics";
import {
trackColumnCombineViaShortcut,
trackColumnExtractViaShortcut,
} from "../../analytics";

import { CombineColumns } from "./CombineColumns/CombineColumns";
import { ExpressionEditorTextfield } from "./ExpressionEditorTextfield";
Expand Down Expand Up @@ -158,7 +161,12 @@ export const ExpressionWidget = <Clause extends object = Lib.ExpressionClause>(
}

if (isExtractingColumn) {
const handleSubmit = (clause: Lib.ExpressionClause, name: string) => {
const handleSubmit = (
clause: Lib.ExpressionClause,
name: string,
extraction: Lib.ColumnExtraction,
) => {
trackColumnExtractViaShortcut(query, stageIndex, extraction);
const expression = Lib.legacyExpressionForExpressionClause(
query,
stageIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { getExample, getName } from "./util";
type Props = {
query: Lib.Query;
stageIndex: number;
onSubmit: (clause: Lib.ExpressionClause, name: string) => void;
onSubmit: (
clause: Lib.ExpressionClause,
name: string,
extraction: Lib.ColumnExtraction,
) => void;
onCancel: () => void;
};

Expand Down Expand Up @@ -51,7 +55,7 @@ export function ExtractColumn({
const name = getName(query, stageIndex, info);
const lastExpression = expressions.at(-1);
if (lastExpression) {
onSubmit(lastExpression, name);
onSubmit(lastExpression, name, extraction);
}
}

Expand Down

0 comments on commit 021c35a

Please sign in to comment.