diff --git a/docs/tracking-plan.md b/docs/tracking-plan.md
index 3efef1ae2ad..9bf59b7de5f 100644
--- a/docs/tracking-plan.md
+++ b/docs/tracking-plan.md
@@ -148,6 +148,7 @@ Generated on Tue, Oct 29, 2024 at 05:29 PM
### Schema
- [Schema Analyzed](#event--SchemaAnalyzedEvent)
+- [Schema Exported](#event--SchemaExportedEvent)
### Schema Validation
- [Schema Validation Added](#event--SchemaValidationAddedEvent)
@@ -1801,6 +1802,25 @@ This event is fired when user analyzes the schema.
- **connection_id** (optional): `string | undefined`
- The id of the connection associated to this event.
+
+
+### Schema Exported
+
+This event is fired when user shares the schema.
+
+**Properties**:
+
+- **has_schema** (required): `boolean`
+ - Indicates whether the schema was analyzed before sharing.
+- **schema_width** (required): `number`
+ - The number of fields at the top level.
+- **schema_depth** (required): `number`
+ - The number of nested levels.
+- **geo_data** (required): `boolean`
+ - Indicates whether the schema contains geospatial data.
+- **connection_id** (optional): `string | undefined`
+ - The id of the connection associated to this event.
+
## Schema Validation
diff --git a/packages/compass-schema/src/stores/store.ts b/packages/compass-schema/src/stores/store.ts
index 6bad28897a7..9377d80a032 100644
--- a/packages/compass-schema/src/stores/store.ts
+++ b/packages/compass-schema/src/stores/store.ts
@@ -87,6 +87,8 @@ export type SchemaStore = StoreWithStateMixin & {
dataService: DataService;
handleSchemaShare(): void;
+ _trackSchemaShared(hasSchema: boolean): void;
+
onSchemaSampled(): void;
geoLayerAdded(
field: string,
@@ -162,6 +164,7 @@ export function activateSchemaPlugin(
JSON.stringify(this.state.schema, null, ' ')
);
const hasSchema = this.state.schema !== null;
+ this._trackSchemaShared(hasSchema);
openToast(
'share-schema',
hasSchema
@@ -181,6 +184,21 @@ export function activateSchemaPlugin(
);
},
+ _trackSchemaShared(this: SchemaStore, hasSchema: boolean) {
+ const { schema } = this.state;
+ // Use a function here to a) ensure that the calculations here
+ // are only made when telemetry is enabled and b) that errors from
+ // those calculations are caught and logged rather than displayed to
+ // users as errors from the core schema sharing logic.
+ const trackEvent = () => ({
+ has_schema: hasSchema,
+ schema_width: schema?.fields?.length ?? 0,
+ schema_depth: schema ? calculateSchemaDepth(schema) : 0,
+ geo_data: schema ? schemaContainsGeoData(schema) : false,
+ });
+ track('Schema Exported', trackEvent, connectionInfoRef.current);
+ },
+
/**
* Initialize the schema store.
*
diff --git a/packages/compass-telemetry/src/telemetry-events.ts b/packages/compass-telemetry/src/telemetry-events.ts
index 26dbd1394d6..1e354add801 100644
--- a/packages/compass-telemetry/src/telemetry-events.ts
+++ b/packages/compass-telemetry/src/telemetry-events.ts
@@ -1928,6 +1928,36 @@ type SchemaAnalyzedEvent = ConnectionScoped<{
};
}>;
+/**
+ * This event is fired when user shares the schema.
+ *
+ * @category Schema
+ */
+type SchemaExportedEvent = ConnectionScoped<{
+ name: 'Schema Exported';
+ payload: {
+ /**
+ * Indicates whether the schema was analyzed before sharing.
+ */
+ has_schema: boolean;
+
+ /**
+ * The number of fields at the top level.
+ */
+ schema_width: number;
+
+ /**
+ * The number of nested levels.
+ */
+ schema_depth: number;
+
+ /**
+ * Indicates whether the schema contains geospatial data.
+ */
+ geo_data: boolean;
+ };
+}>;
+
/**
* This event is fired when a user clicks to show the details of an operation.
*
@@ -2641,6 +2671,7 @@ export type TelemetryEvent =
| QueryHistoryRecentUsedEvent
| QueryResultsRefreshedEvent
| SchemaAnalyzedEvent
+ | SchemaExportedEvent
| SchemaValidationAddedEvent
| SchemaValidationEditedEvent
| SchemaValidationUpdatedEvent