Skip to content

Commit

Permalink
Embed downloads ms3 - analytics (metabase#46335)
Browse files Browse the repository at this point in the history
* update static_embed_code_copied to use downloads (metabase#45944)

* copy schema file for better diff

* adds downloads field to appearance in embed_flow schema

* update event to send `downloads` parameter, update e2e tests

* fix test for dwonloads: false

* fix: use correct schema version for embed flow analytics (metabase#46053)

* update `dashboard_pdf_exported` and use it in embedding context (metabase#46076)

* copy schema for better diff

* adds `dashboard_accessed_via` to the `dashboard_pdf_exported` event

* download_results_clicked event (metabase#46132)

* adds download_results_clicked event + e2e tests

* make strings nullable

* adds maxLength

* switch back to if/then as it seems more readable

* refactor: use the resourceType to determine the download params instead of re-doing the logic

* fix ''question' is possibly 'undefined'.'

* split resource_type into resource_type and accessed_via to also consider interactive-embedding and sdk

* edit comment

* adds test for ad-hoc-question

* Update frontend/src/metabase/query_builder/actions/downloading.ts

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

* makes describe message more consistent

* "else if" => if

* fix describe block name

* convert downloads event to use enum for download_type and export_type

* resource_type should be an enum too

* fix line added in the wrong place during merges

---------

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

* Update frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>

* adds enum schema to dashboard_accessed_via

* fix accessed_via for sdk embeds

* update comments to explain why we send 0 when dashboardId is null

* only send dashboard_id as a number when it is a number, as expected by snowplow

* remove un-needed async/await from saveAsPDF function

* rename frontend/src/metabase/redux/downloading-analytics.ts -> frontend/src/metabase/redux/downloads-analytics.ts

* fix cy.log message

---------

Co-authored-by: Mahatthana (Kelvin) Nomsawadi <me@bboykelvin.dev>
  • Loading branch information
npretto and WiNloSt authored Aug 2, 2024
1 parent 2c7d0cf commit c08b85c
Show file tree
Hide file tree
Showing 13 changed files with 763 additions and 136 deletions.
39 changes: 37 additions & 2 deletions e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {
ORDERS_DASHBOARD_ID,
} from "e2e/support/cypress_sample_instance_data";
import {
describeEE,
describeWithSnowplowEE,
expectGoodSnowplowEvent,
expectNoBadSnowplowEvents,
getDashboardCardMenu,
main,
popover,
resetSnowplow,
restore,
setTokenFeatures,
showDashboardCardActions,
Expand All @@ -17,10 +20,11 @@ import {
* Unless the product changes, these should test the same things as `public-resource-downloads.cy.spec.ts`
*/

describeEE(
describeWithSnowplowEE(
"Static embed dashboards/questions downloads (results and export as pdf)",
() => {
beforeEach(() => {
resetSnowplow();
cy.deleteDownloadsFolder();
});

Expand All @@ -38,6 +42,10 @@ describeEE(
cy.signOut();
});

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

it("#downloads=false should disable both PDF downloads and dashcard results downloads", () => {
visitEmbeddedPage(
{
Expand Down Expand Up @@ -76,6 +84,12 @@ describeEE(
cy.get("header").findByText("Export as PDF").click();

cy.verifyDownload("Orders in a dashboard.pdf");

expectGoodSnowplowEvent({
event: "dashboard_pdf_exported",
dashboard_id: 0,
dashboard_accessed_via: "static-embed",
});
});

it("should be able to download a static embedded dashcard as CSV", () => {
Expand All @@ -99,6 +113,13 @@ describeEE(
popover().findByText(".csv").click();

cy.verifyDownload(".csv", { contains: true });

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "dashcard",
accessed_via: "static-embed",
export_type: "csv",
});
});
});

Expand Down Expand Up @@ -153,6 +174,13 @@ describeEE(
popover().findByText(".png").click();

cy.verifyDownload(".png", { contains: true });

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "question",
accessed_via: "static-embed",
export_type: "png",
});
});

it("should be able to download a static embedded card as CSV", () => {
Expand All @@ -175,6 +203,13 @@ describeEE(
popover().findByText(".csv").click();

cy.verifyDownload(".csv", { contains: true });

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "question",
accessed_via: "static-embed",
export_type: "csv",
});
});
});
},
Expand Down
103 changes: 69 additions & 34 deletions e2e/test/scenarios/sharing/downloads/downloads.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ import {
ORDERS_QUESTION_ID,
} from "e2e/support/cypress_sample_instance_data";
import {
restore,
downloadAndAssert,
startNewQuestion,
visualize,
visitDashboard,
popover,
assertSheetRowsCount,
filterWidget,
saveDashboard,
getDashboardCardMenu,
describeWithSnowplow,
expectGoodSnowplowEvent,
expectNoBadSnowplowEvents,
resetSnowplow,
enableTracking,
addOrUpdateDashboardCard,
assertSheetRowsCount,
createQuestion,
queryBuilderMain,
describeWithSnowplow,
downloadAndAssert,
editDashboard,
setFilter,
enableTracking,
entityPickerModal,
entityPickerModalTab,
showDashboardCardActions,
expectGoodSnowplowEvent,
expectNoBadSnowplowEvents,
filterWidget,
getDashboardCard,
getDashboardCardMenu,
multiAutocompleteInput,
popover,
queryBuilderMain,
resetSnowplow,
restore,
saveDashboard,
setFilter,
showDashboardCardActions,
startNewQuestion,
visitDashboard,
visualize,
dismissDownloadStatus,
} from "e2e/support/helpers";

Expand Down Expand Up @@ -66,24 +66,33 @@ describe("scenarios > question > download", () => {
cy.signInAsAdmin();
});

testCases.forEach(fileType => {
it(`downloads ${fileType} file`, () => {
startNewQuestion();
entityPickerModal().within(() => {
entityPickerModalTab("Saved questions").click();
cy.findByText("Orders, Count").click();
});
describeWithSnowplow("[snowplow]", () => {
testCases.forEach(fileType => {
it(`downloads ${fileType} file`, () => {
startNewQuestion();
entityPickerModal().within(() => {
entityPickerModalTab("Saved questions").click();
cy.findByText("Orders, Count").click();
});

visualize();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.contains("18,760");
visualize();
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.contains("18,760");

downloadAndAssert({ fileType }, sheet => {
expect(sheet["A1"].v).to.eq("Count");
expect(sheet["A2"].v).to.eq(18760);
});
downloadAndAssert({ fileType }, sheet => {
expect(sheet["A1"].v).to.eq("Count");
expect(sheet["A2"].v).to.eq(18760);
});

dismissDownloadStatus();
expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "ad-hoc-question",
accessed_via: "internal",
export_type: fileType,
});

dismissDownloadStatus();
});
});
});

Expand Down Expand Up @@ -337,7 +346,7 @@ describe("scenarios > dashboard > download pdf", () => {
});
});

describeWithSnowplow("scenarios > dashboard > download pdf", () => {
describeWithSnowplow("[snowplow] scenarios > dashboard", () => {
beforeEach(() => {
restore();
resetSnowplow();
Expand All @@ -362,9 +371,35 @@ describeWithSnowplow("scenarios > dashboard > download pdf", () => {
expectGoodSnowplowEvent({
event: "dashboard_pdf_exported",
dashboard_id: dashboard.id,
dashboard_accessed_via: "internal",
});
});
});

it("should send the `download_results_clicked` event when downloading dashcards results", () => {
cy.createDashboardWithQuestions({
dashboardName: "saving pngs dashboard",
questions: [canSavePngQuestion, cannotSavePngQuestion],
}).then(({ dashboard }) => {
visitDashboard(dashboard.id);
});

showDashboardCardActions(0);
getDashboardCard(0).findByText("Created At").should("be.visible");
getDashboardCardMenu(0).click();

popover().within(() => {
cy.findByText("Download results").click();
cy.findByText(".png").click();
});

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "dashcard",
accessed_via: "internal",
export_type: "png",
});
});
});

function assertOrdersExport(length) {
Expand Down
39 changes: 37 additions & 2 deletions e2e/test/scenarios/sharing/public-resource-downloads.cy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import {
} from "e2e/support/cypress_sample_instance_data";
import {
assertNotEmptyObject,
describeEE,
describeWithSnowplowEE,
downloadAndAssert,
expectGoodSnowplowEvent,
expectNoBadSnowplowEvents,
getDashboardCardMenu,
main,
popover,
resetSnowplow,
restore,
setTokenFeatures,
showDashboardCardActions,
Expand All @@ -19,10 +22,11 @@ import {
* Unless the product changes, these should test the same things as `embed-resource-downloads.cy.spec.ts`
*/

describeEE(
describeWithSnowplowEE(
"Public dashboards/questions downloads (results and export as pdf)",
() => {
beforeEach(() => {
resetSnowplow();
cy.deleteDownloadsFolder();
});

Expand Down Expand Up @@ -50,6 +54,10 @@ describeEE(
cy.signOut();
});

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

it("#downloads=false should disable both PDF downloads and dashcard results downloads", () => {
cy.visit(`${publicLink}#downloads=false`);
waitLoading();
Expand All @@ -68,6 +76,12 @@ describeEE(
cy.get("header").findByText("Export as PDF").click();

cy.verifyDownload("Orders in a dashboard.pdf");

expectGoodSnowplowEvent({
event: "dashboard_pdf_exported",
dashboard_id: 0,
dashboard_accessed_via: "public-link",
});
});

it("should be able to download a public dashcard as CSV", () => {
Expand All @@ -88,6 +102,13 @@ describeEE(
},
assertNotEmptyObject,
);

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "dashcard",
accessed_via: "public-link",
export_type: "csv",
});
});
});

Expand Down Expand Up @@ -129,6 +150,13 @@ describeEE(
popover().findByText(".png").click();

cy.verifyDownload(".png", { contains: true });

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "question",
accessed_via: "public-link",
export_type: "png",
});
});

it("should be able to download a public card as CSV", () => {
Expand All @@ -148,6 +176,13 @@ describeEE(
},
assertNotEmptyObject,
);

expectGoodSnowplowEvent({
event: "download_results_clicked",
resource_type: "question",
accessed_via: "public-link",
export_type: "csv",
});
});
});
},
Expand Down
Loading

0 comments on commit c08b85c

Please sign in to comment.