Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine/extract shortcuts snowplow events #42445

Merged
merged 7 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from "underscore";

import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
describeWithSnowplow,
Expand All @@ -11,6 +12,9 @@ import {
restore,
visualize,
createQuestion,
expectGoodSnowplowEvent,
resetSnowplow,
expectNoBadSnowplowEvents,
} from "e2e/support/helpers";

const { PEOPLE, PEOPLE_ID } = SAMPLE_DATABASE;
Expand All @@ -20,31 +24,37 @@ const DATE_CASES = [
option: "Hour of day",
value: "21",
example: "0, 1",
expressions: ["get-hour"],
},
{
option: "Day of month",
value: "11",
example: "1, 2",
expressions: ["get-day"],
},
{
option: "Day of week",
value: "Tuesday",
example: "Monday, Tuesday",
expressions: ["day-name", "get-day-of-week"],
},
{
option: "Month of year",
value: "Feb",
example: "Jan, Feb",
expressions: ["month-name", "get-month"],
},
{
option: "Quarter of year",
value: "Q1",
example: "Q1, Q2",
expressions: ["quarter-name", "get-quarter"],
},
{
option: "Year",
value: "2,025",
example: "2023, 2024",
expressions: ["get-year"],
},
];

Expand All @@ -53,11 +63,13 @@ const EMAIL_CASES = [
option: "Domain",
value: "yahoo",
example: "example, online",
expressions: ["domain"],
},
{
option: "Host",
value: "yahoo.com",
example: "example.com, online.com",
expressions: ["host"],
},
];

Expand All @@ -66,28 +78,37 @@ const URL_CASES = [
option: "Domain",
value: "yahoo",
example: "example, online",
expressions: ["domain"],
},
{
option: "Subdomain",
value: "",
example: "www, maps",
expressions: ["subdomain"],
},
{
option: "Host",
value: "yahoo.com",
example: "example.com, online.com",
expressions: ["host"],
},
];

describeWithSnowplow("extract shortcut", () => {
beforeEach(() => {
restore();
resetSnowplow();

cy.signInAsAdmin();
});

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

describe("date columns", () => {
describe("should add a date expression for each option", () => {
DATE_CASES.forEach(({ option, value, example }) => {
DATE_CASES.forEach(({ option, value, example, expressions }) => {
it(option, () => {
openOrdersTable({ limit: 1 });
extractColumnAndCheck({
Expand All @@ -96,6 +117,11 @@ describeWithSnowplow("extract shortcut", () => {
value,
example,
});
expectGoodSnowplowEvent({
event: "column_extract_via_plus_modal",
custom_expressions_used: expressions,
database_id: SAMPLE_DB_ID,
});
});
});
});
Expand Down Expand Up @@ -136,7 +162,7 @@ describeWithSnowplow("extract shortcut", () => {
cy.signInAsAdmin();
});

EMAIL_CASES.forEach(({ option, value, example }) => {
EMAIL_CASES.forEach(({ option, value, example, expressions }) => {
it(option, () => {
createQuestion(
{
Expand All @@ -157,6 +183,11 @@ describeWithSnowplow("extract shortcut", () => {
value,
example,
});
expectGoodSnowplowEvent({
event: "column_extract_via_plus_modal",
custom_expressions_used: expressions,
database_id: SAMPLE_DB_ID,
});
});
});
});
Expand All @@ -172,7 +203,7 @@ describeWithSnowplow("extract shortcut", () => {
});
});

URL_CASES.forEach(({ option, value, example }) => {
URL_CASES.forEach(({ option, value, example, expressions }) => {
it(option, () => {
createQuestion(
{
Expand All @@ -193,6 +224,11 @@ describeWithSnowplow("extract shortcut", () => {
value,
example,
});
expectGoodSnowplowEvent({
event: "column_extract_via_plus_modal",
custom_expressions_used: expressions,
database_id: SAMPLE_DB_ID,
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import _ from "underscore";

import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { restore, popover, createQuestion } from "e2e/support/helpers";
import {
restore,
popover,
createQuestion,
describeWithSnowplow,
expectNoBadSnowplowEvents,
resetSnowplow,
expectGoodSnowplowEvent,
} from "e2e/support/helpers";

const { PEOPLE, PEOPLE_ID } = SAMPLE_DATABASE;

describe("scenarios > visualizations > combine shortcut", () => {
describeWithSnowplow("scenarios > visualizations > combine shortcut", () => {
beforeEach(() => {
restore();
cy.signInAsNormalUser();
resetSnowplow();
});

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

it("should be possible add a new column through the combine columns shortcut", () => {
Expand All @@ -34,6 +48,12 @@ describe("scenarios > visualizations > combine shortcut", () => {
example: "email@example.com12345",
newValue: "borer-hudson@yahoo.com1",
});

expectGoodSnowplowEvent({
event: "column_combine_via_plus_modal",
custom_expressions_used: ["concat"],
database_id: SAMPLE_DB_ID,
});
});
});

Expand Down
27 changes: 27 additions & 0 deletions frontend/src/metabase/query_builder/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export const trackColumnCombineViaShortcut = (query, question) => {
});
};

export const trackColumnCombineViaPlusModal = (query, question) => {
trackSchemaEvent("question", "1-0-5", {
event: "column_combine_via_plus_modal",
custom_expressions_used: ["concat"],
database_id: Lib.databaseID(query),
question_id: question?.id() ?? 0,
});
};

export const trackColumnExtractViaShortcut = (
query,
stageIndex,
Expand All @@ -59,3 +68,21 @@ export const trackColumnExtractViaShortcut = (
question_id: question?.id() ?? 0,
});
};

export const trackColumnExtractViaPlusModal = (
query,
stageIndex,
extraction,
question,
) => {
trackSchemaEvent("question", "1-0-5", {
event: "column_extract_via_plus_modal",
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
@@ -1,5 +1,6 @@
import { t } from "ttag";

import { trackColumnCombineViaPlusModal } from "metabase/query_builder/analytics";
import { CombineColumns } from "metabase/query_builder/components/expressions/CombineColumns";
import type { LegacyDrill } from "metabase/visualizations/types";
import type { ClickActionPopoverProps } from "metabase/visualizations/types/click-actions";
Expand Down Expand Up @@ -30,6 +31,8 @@ export const CombineColumnsAction: LegacyDrill = ({ question, clicked }) => {
const nextQuestion = question.setQuery(newQuery);
const nextCard = nextQuestion.card();

trackColumnCombineViaPlusModal(newQuery, nextQuestion);

onChangeCardAndRun({ nextCard });
onClose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { t } from "ttag";

import { trackColumnExtractViaPlusModal } from "metabase/query_builder/analytics";
import { ExtractColumn } from "metabase/query_builder/components/expressions/ExtractColumn";
import type { LegacyDrill } from "metabase/visualizations/types";
import type { ClickActionPopoverProps } from "metabase/visualizations/types/click-actions";
Expand Down Expand Up @@ -35,6 +36,13 @@ export const ExtractColumnAction: LegacyDrill = ({ question, clicked }) => {
const nextQuestion = question.setQuery(newQuery);
const nextCard = nextQuestion.card();

trackColumnExtractViaPlusModal(
newQuery,
stageIndex,
extraction,
nextQuestion,
);

onChangeCardAndRun({ nextCard });
onClose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
"description": "Events related to questions",
"self": {
"vendor": "com.metabase",
"name": "question",
"format": "jsonschema",
"version": "1-0-5"
},
"type": "object",
"properties": {
"event": {
"description": "Event name",
"type": "string",
"enum": [
"new_question_saved",
"turn_into_model_clicked",
"notebook_native_preview_shown",
"notebook_native_preview_hidden",
"column_combine_via_shortcut",
"column_combine_via_column_header",
"column_combine_via_plus_modal",
"column_extract_via_shortcut",
"column_extract_via_column_header",
"column_extract_via_plus_modal"
],
"maxLength": 1024
},
"type": {
"description": "String identifying the type of the question when it is saved",
"type": [
"string",
"null"
],
"enum": [
"simple_question",
"custom_question",
"native_question"
],
"maxLength": 1024
},
"method": {
"description": "String indicating whether or not the question was created based off of an existing question",
"type": [
"string",
"null"
],
"enum": [
"from_scratch",
"existing_question"
],
"maxLength": 1024
},
"visualization_type": {
"description": "String describing the type of visualization used for the question",
"type": [
"string",
"null"
],
"maxLength": 1024
},
"question_id": {
"description": "Unique identifier for the question within the Metabase instance",
"type": "integer",
"minimum": 0,
"maximum": 2147483647
},
"database_id": {
"description": "Unique identifier(s) for the database connection(s) used to create the question",
"type": [
"integer",
"null"
],
"minimum": 0,
"maximum": 2147483647
},
"custom_expressions_used": {
"description": "A list of names of expression functions and aggregations used",
"type": [
"array",
"null"
],
"items": {
"description": "The name of a function used in the custom expression",
"type": "string",
"maxLength": 1024
}
}
},
"required": [
"event",
"question_id"
],
"additionalProperties": true
}