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
remote sync analytics (#65129)
Aleksandr Lesnenko9d1d534e51c5
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.tsindex 589db9179b8..08b3e8b1926 100644--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts@@ -10,15 +10,20 @@ const LOCAL_GIT_URL = "file://" + H.LOCAL_GIT_PATH + "/.git";const REMOTE_QUESTION_NAME = "Remote Sync Test Question";-describe("Remote Sync", () => {+H.describeWithSnowplowEE("Remote Sync", () => {beforeEach(() => {H.restore();+ H.resetSnowplow();cy.signInAsAdmin();H.activateToken("bleeding-edge");H.setupGitSync();H.interceptTask();});+ afterEach(() => {+ H.expectNoBadSnowplowEvents();+ });+describe("Development Mode", () => {it("can push and pull changes", () => {H.configureGit("development");@@ -55,6 +60,10 @@ describe("Remote Sync", () => {.click();H.waitForTask({ taskName: "export" });+ H.expectUnstructuredSnowplowEvent({+ event: "remote_sync_push_changes",+ triggered_from: "sidebar",+ });H.navigationSidebar().findByRole("link", { name: /Library/ })@@ -76,6 +85,10 @@ describe("Remote Sync", () => {.click();H.waitForTask({ taskName: "import" });+ H.expectUnstructuredSnowplowEvent({+ event: "remote_sync_pull_changes",+ triggered_from: "sidebar",+ });H.collectionTable().findByText(UPDATED_REMOTE_QUESTION_NAME)@@ -183,7 +196,14 @@ describe("Remote Sync", () => {});describe("Branching", () => {+ let branchCount = 0;++ beforeEach(() => {+ branchCount = 0;+ });+const createNewBranch = (newBranchName: string) => {+ branchCount++;H.navigationSidebar().findByTestId("branch-picker-button").click();H.popover().findByPlaceholderText("Find or create a branch...")@@ -192,6 +212,14 @@ describe("Remote Sync", () => {.findByRole("option", { name: /Create branch/ }).click();+ H.expectUnstructuredSnowplowEvent(+ {+ event: "remote_sync_branch_created",+ triggered_from: "branch-picker",+ },+ branchCount,+ );+H.navigationSidebar().findByTestId("branch-picker-button").should("contain.text", newBranchName);@@ -257,6 +285,11 @@ describe("Remote Sync", () => {// Go back to the first branchswitchToExistingBranch(NEW_BRANCH_1);+ H.expectUnstructuredSnowplowEvent({+ event: "remote_sync_branch_switched",+ triggered_from: "sidebar",+ });+H.collectionTable().findByText("Orders, Count").should("exist");// The second item should not exist in the first branchH.collectionTable().findByText("Orders Model").should("not.exist");@@ -422,6 +455,12 @@ describe("Remote Sync", () => {.type(LOCAL_GIT_URL);cy.findByTestId("admin-layout-content").findByText("Development").click();cy.button("Set up Remote Sync").click();++ H.expectUnstructuredSnowplowEvent({+ event: "remote_sync_settings_changed",+ triggered_from: "admin-settings",+ });+cy.findByTestId("admin-layout-content").findByText("Success").should("exist");@@ -510,6 +549,11 @@ describe("Remote Sync", () => {cy.button("Disable").click();});+ H.expectUnstructuredSnowplowEvent({+ event: "remote_sync_deactivated",+ triggered_from: "admin-settings",+ });+cy.findByTestId("admin-layout-content").findByText("Enabled").should("not.exist");diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/analytics.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/analytics.tsnew file mode 100644index 00000000000..0b2fb4b4f77--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/analytics.ts@@ -0,0 +1,65 @@+import { trackSimpleEvent } from "metabase/lib/analytics";++export const trackBranchSwitched = ({+ triggeredFrom,+}: {+ triggeredFrom: "sidebar" | "admin-settings";+}) => {+ trackSimpleEvent({+ event: "remote_sync_branch_switched",+ triggered_from: triggeredFrom,+ });+};++export const trackBranchCreated = ({+ triggeredFrom,+}: {+ triggeredFrom: "branch-picker" | "conflict-modal";+}) => {+ trackSimpleEvent({+ event: "remote_sync_branch_created",+ triggered_from: triggeredFrom,+ });+};++export const trackPullChanges = ({+ triggeredFrom,+ force,+}: {+ triggeredFrom: "sidebar" | "admin-settings";+ force: boolean;+}) => {+ trackSimpleEvent({+ event: "remote_sync_pull_changes",+ triggered_from: triggeredFrom,+ ...(force && { event_detail: "force" }),+ });+};++export const trackPushChanges = ({+ triggeredFrom,+ force,+}: {+ triggeredFrom: "sidebar" | "conflict-modal";+ force: boolean;+}) => {+ trackSimpleEvent({+ event: "remote_sync_push_changes",+ triggered_from: triggeredFrom,+ ...(force && { event_detail: "force" }),+ });+};++export const trackRemoteSyncSettingsChanged = () => {+ trackSimpleEvent({+ event: "remote_sync_settings_changed",+ triggered_from: "admin-settings",+ });+};++export const trackRemoteSyncDeactivated = () => {+ trackSimpleEvent({+ event: "remote_sync_deactivated",+ triggered_from: "admin-settings",+ });+};diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/PushChangesModal/PushChangesModal.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/PushChangesModal/PushChangesModal.tsxindex e8e86faca59..bcf1972e43f 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/PushChangesModal/PushChangesModal.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/PushChangesModal/PushChangesModal.tsx@@ -14,6 +14,7 @@ import {import { useExportChangesMutation } from "metabase-enterprise/api";import type { Collection } from "metabase-types/api";+import { trackPushChanges } from "../../analytics";import { type SyncError, parseSyncError } from "../../utils";import { ChangesLists } from "../ChangesLists";import { SyncConflictModal } from "../SyncConflictModal";@@ -58,6 +59,11 @@ export const PushChangesModal = ({message: commitMessage.trim() || undefined,branch: currentBranch,});++ trackPushChanges({+ triggeredFrom: "sidebar",+ force: false,+ });}, [commitMessage, exportChanges, currentBranch]);if (hasConflict) {diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/PullChangesButton.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/PullChangesButton.tsxindex 60656f51978..e2e46ee98bc 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/PullChangesButton.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/PullChangesButton.tsx@@ -5,6 +5,8 @@ import { useToast } from "metabase/common/hooks";import { Button, Tooltip } from "metabase/ui";import { useImportChangesMutation } from "metabase-enterprise/api";+import { trackPullChanges } from "../../analytics";+interface PullChangesButtonProps {dirty: boolean; // disambiguation: local form state, not the git-synced collection statebranch: string;@@ -20,6 +22,12 @@ export const PullChangesButton = (props: PullChangesButtonProps) => {const handlePullChanges = useCallback(async () => {try {await importChanges({ branch, force: forcePull }).unwrap();++ trackPullChanges({+ triggeredFrom: "admin-settings",+ force: forcePull,+ });+sendToast({message: t`Latest changes have been pulled successfully`,icon: "check",diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsxindex 22e7bea45c2..7365d7345a2 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/RemoteSyncAdminSettings/RemoteSyncAdminSettings.tsx@@ -41,6 +41,11 @@ import type {SettingDefinition,} from "metabase-types/api";+import {+ trackBranchSwitched,+ trackRemoteSyncDeactivated,+ trackRemoteSyncSettingsChanged,+} from "../../analytics";import {AUTO_IMPORT_KEY,BRANCH_KEY,@@ -82,6 +87,19 @@ export const RemoteSyncAdminSettings = () => {const saveSettings = async (values: RemoteSyncConfigurationSettings) => {try {await updateRemoteSyncSettings(values).unwrap();++ trackRemoteSyncSettingsChanged();++ if (+ didBranchChange &&+ settingValues?.[BRANCH_KEY] &&+ values[BRANCH_KEY]+ ) {+ trackBranchSwitched({+ triggeredFrom: "admin-settings",+ });+ }+sendToast({ message: t`Settings saved successfully`, icon: "check" });} catch (error) {sendToast({@@ -136,6 +154,7 @@ export const RemoteSyncAdminSettings = () => {onConfirm: async () => {try {await updateRemoteSyncSettings({ [URL_KEY]: "" }).unwrap();+ trackRemoteSyncDeactivated();sendToast({ message: t`Remote Sync disabled`, icon: "check" });} catch (error) {console.error(error);diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.tsindex 6573bf4dde0..e3ab6d60d8c 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/mutation-wrappers.ts@@ -12,6 +12,8 @@ import {parseSyncError,} from "metabase-enterprise/remote_sync/utils";+import { trackBranchCreated, trackPushChanges } from "../../analytics";+export const usePushChangesAction = () => {const [exportChanges, { isLoading: isPushingChanges }] =useExportChangesMutation();@@ -25,6 +27,12 @@ export const usePushChangesAction = () => {branch,force,}).unwrap();++ trackPushChanges({+ triggeredFrom: "conflict-modal",+ force,+ });+sendToast({message: c("{0} is the GitHub branch name").t`Changes pushed to branch ${branch} successfully.`,@@ -74,6 +82,11 @@ export const useStashToNewBranchAction = (existingBranches: string[]) => {try {setIsStashing(true);await createBranch({ name: newBranchName }).unwrap();++ trackBranchCreated({+ triggeredFrom: "conflict-modal",+ });+await exportChanges({branch: newBranchName,}).unwrap();diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/BranchPicker.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/BranchPicker.tsxindex 87dced6ac2a..04432941987 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/BranchPicker.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/BranchPicker.tsx@@ -21,6 +21,8 @@ import {useGetBranchesQuery,} from "metabase-enterprise/api";+import { trackBranchCreated } from "../../analytics";+export interface BranchPickerProps {value: string;onChange: (branch: string, isNewBranch?: boolean) => void;@@ -82,6 +84,10 @@ export const BranchPicker = ({name: branchName,}).unwrap();+ trackBranchCreated({+ triggeredFrom: "branch-picker",+ });+onChange(branchName, true);} catch (error) {sendToast({diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/PullFromRemoteButton.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/PullFromRemoteButton.tsxindex 8325977c02d..0a4649c9b78 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/PullFromRemoteButton.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/PullFromRemoteButton.tsx@@ -9,6 +9,7 @@ import {parseSyncError,} from "metabase-enterprise/remote_sync/utils";+import { trackPullChanges } from "../../analytics";import type { SyncConflictVariant } from "../SyncConflictModal";interface PushChangesButtonProps {@@ -26,6 +27,12 @@ export const PullFromRemoteButton = (props: PushChangesButtonProps) => {const handleClick = async () => {try {await importChanges({ branch }).unwrap();++ trackPullChanges({+ triggeredFrom: "sidebar",+ force: false,+ });+sendToast({message: t`Your branch is now up to date with remote`,icon: "check",diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsxindex 598a42a72f4..289302f67f2 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncedCollectionsSidebarSection/SyncedCollectionsSidebarSection.tsx@@ -19,6 +19,7 @@ import {useImportChangesMutation,} from "metabase-enterprise/api";+import { trackBranchSwitched } from "../../analytics";import { BRANCH_KEY, REMOTE_SYNC_KEY } from "../../constants";import { useSyncStatus } from "../../hooks/use-sync-status";import {@@ -71,6 +72,11 @@ export const SyncedCollectionsSidebarSection = ({if (!isNewBranch) {await importChanges({ branch });++ // Tracking only when not creating a new branch since it has its own event+ trackBranchSwitched({+ triggeredFrom: "sidebar",+ });}setNextBranch(null);diff --git a/frontend/src/metabase-types/analytics/event.ts b/frontend/src/metabase-types/analytics/event.tsindex de9118cf976..b27f8e18ccf 100644--- a/frontend/src/metabase-types/analytics/event.ts+++ b/frontend/src/metabase-types/analytics/event.ts@@ -452,6 +452,46 @@ export type ClickActionPerformedEvent = ValidateEvent<{triggered_from: ClickActionSection;}>;+export type RemoteSyncBranchSwitchedEvent = ValidateEvent<{+ event: "remote_sync_branch_switched";+ triggered_from: "sidebar" | "admin-settings";+}>;++export type RemoteSyncBranchCreatedEvent = ValidateEvent<{+ event: "remote_sync_branch_created";+ triggered_from: "branch-picker" | "conflict-modal";+}>;++export type RemoteSyncPullChangesEvent = ValidateEvent<{+ event: "remote_sync_pull_changes";+ triggered_from: "sidebar" | "admin-settings";+ event_detail?: "force";+}>;++export type RemoteSyncPushChangesEvent = ValidateEvent<{+ event: "remote_sync_push_changes";+ triggered_from: "sidebar" | "conflict-modal";+ event_detail?: "force";+}>;++export type RemoteSyncSettingsChangedEvent = ValidateEvent<{+ event: "remote_sync_settings_changed";+ triggered_from: "admin-settings";+}>;++export type RemoteSyncDeactivatedEvent = ValidateEvent<{+ event: "remote_sync_deactivated";+ triggered_from: "admin-settings";+}>;++export type RemoteSyncEvent =+ | RemoteSyncBranchSwitchedEvent+ | RemoteSyncBranchCreatedEvent+ | RemoteSyncPullChangesEvent+ | RemoteSyncPushChangesEvent+ | RemoteSyncSettingsChangedEvent+ | RemoteSyncDeactivatedEvent;+export type BookmarkEvent =| BookmarkQuestionEvent| BookmarkModelEvent@@ -509,4 +549,5 @@ export type SimpleEvent =| LearnAboutDataClickedEvent| MetadataEditEvent| BookmarkEvent+ | RemoteSyncEvent| ClickActionPerformedEvent;