Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions docs/analytics-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ at the end maps the previous UA-shaped events to their replacements.
Set once on app boot. Auto-attach to every subsequent event for the same user,
available as user-scoped breakdowns in GA4.

| Name | Values | Set when | Notes |
| ------------------ | ------------ | -------- | -------------------------------------------------------------- |
| `webusb_available` | `yes` / `no` | App boot | From `"usb" in navigator`. Same name and values as ml-trainer. |
| Name | Values | Set when | Notes |
| ------------------ | -------------------------------------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `webusb_available` | `yes` / `no` | App boot | From `"usb" in navigator`. Same name and values as ml-trainer. |
| `project_storage` | `database` / `session_no_indexeddb` / `session_open_failed` / `host` | App boot, once the projects database has opened or failed to | Where the tab keeps its project. `database` is IndexedDB. The two `session_` values are the session-storage fallback: the browser has no IndexedDB, or it has but the database would not open. `host` is iframe controller mode, where the embedding page keeps the project. |

Unlike ml-trainer there is no `webbluetooth_available`: the editor doesn't use
Bluetooth.

`project_storage` is there to show how many sessions really run without the
projects database, and why, which decides whether the session-storage fallback
is worth keeping.

## Device events

Same event family and params as ml-trainer so a cross-product device dashboard
Expand Down
9 changes: 8 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import SearchProvider from "./documentation/search/search-hooks";
import { ActiveEditorProvider } from "./editor/active-editor-hooks";
import { FileSystem } from "./fs/fs";
import { FileSystemProvider } from "./fs/fs-hooks";
import { openProjectsDatabase } from "./fs/current-project";
import {
openProjectsDatabase,
reportProjectStorageMode,
} from "./fs/current-project";
import { createHost, IframeHost } from "./fs/host";
import { parseProjectLink, PendingProjectLink } from "./fs/project-link";
import { FSStorage } from "./fs/storage";
Expand Down Expand Up @@ -93,6 +96,10 @@ const App = () => {
"webusb_available",
"usb" in navigator ? "yes" : "no"
);
if (iframeMode) {
// Otherwise reported when the projects database opens, or fails to.
reportProjectStorageMode(logging, "host");
}
const statusListener = (event: ConnectionStatusChange) =>
logDeviceStatusChange(logging, event);
device.addEventListener("status", statusListener);
Expand Down
10 changes: 10 additions & 0 deletions src/fs/current-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("openProjectsDatabase", () => {
const db = await openProjectsDatabase(logging);
expect(db).toBeInstanceOf(ProjectsDatabase);
expect(isActive()).toEqual(true);
expect(logging.userProperties.project_storage).toEqual("database");
db!.close();
});

Expand All @@ -58,6 +59,9 @@ describe("openProjectsDatabase", () => {
expect(await openProjectsDatabase(logging)).toBeUndefined();
expect(logging.errors[0].message).toMatch(/using session storage/);
expect(isActive()).toEqual(false);
expect(logging.userProperties.project_storage).toEqual(
"session_open_failed"
);
});

it("gives up quietly on an incompatible database on public stages", async () => {
Expand All @@ -76,6 +80,9 @@ describe("openProjectsDatabase", () => {
expect(await openProjectsDatabase(logging, false)).toBeUndefined();
expect(logging.errors).toEqual([]);
expect(hasStorageVersionError()).toEqual(true);
expect(logging.userProperties.project_storage).toEqual(
"session_open_failed"
);
});

it("gives up without IndexedDB", async () => {
Expand All @@ -86,6 +93,9 @@ describe("openProjectsDatabase", () => {
});
try {
expect(await openProjectsDatabase(logging)).toBeUndefined();
expect(logging.userProperties.project_storage).toEqual(
"session_no_indexeddb"
);
} finally {
Object.defineProperty(globalThis, "indexedDB", {
value: original,
Expand Down
22 changes: 22 additions & 0 deletions src/fs/current-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ export const sessionStorageIfPossible = (): Storage | undefined => {
}
};

/**
* Where a tab keeps its project, as the project_storage user property.
*
* It is there to answer one question: how many sessions really run without
* the projects database, and why. That decides whether the session-storage
* fallback earns its keep.
*/
export type ProjectStorageMode =
| "database"
| "session_no_indexeddb"
| "session_open_failed"
// Iframe controller mode: the embedding page keeps the project.
| "host";

export const reportProjectStorageMode = (
logging: Logging,
mode: ProjectStorageMode
): void => logging.setUserProperty("project_storage", mode);

/**
* Opens the projects database, or explains why not.
*
Expand All @@ -63,13 +82,16 @@ export const openProjectsDatabase = async (
publicFacing: boolean = isPublicFacingStage()
): Promise<ProjectsDatabase | undefined> => {
if (typeof indexedDB === "undefined") {
reportProjectStorageMode(logging, "session_no_indexeddb");
return undefined;
}
try {
const db = await ProjectsDatabase.open();
reportProjectsDatabaseActive();
reportProjectStorageMode(logging, "database");
return db;
} catch (e) {
reportProjectStorageMode(logging, "session_open_failed");
if (isVersionError(e) && !publicFacing) {
reportStorageVersionError(e);
} else {
Expand Down
Loading