From 4e22b522941e45a96b8052d653cb23fc1abc824c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 22 Oct 2024 19:22:48 +0200 Subject: [PATCH 1/3] Add "Schema Exported" event --- .../compass-telemetry/src/telemetry-events.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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 From 4673142f63a0d7ba02e19e2e9971ec945c37399b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 22 Oct 2024 19:22:56 +0200 Subject: [PATCH 2/3] Update tracking plan --- docs/tracking-plan.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/tracking-plan.md b/docs/tracking-plan.md index 99ebbfa5ee9..64ca980cc24 100644 --- a/docs/tracking-plan.md +++ b/docs/tracking-plan.md @@ -1,7 +1,7 @@ # Compass Tracking Plan -Generated on Wed, Oct 23, 2024 at 04:31 PM +Generated on Thu, Oct 24, 2024 at 09:05 AM ## Table of Contents @@ -148,6 +148,7 @@ Generated on Wed, Oct 23, 2024 at 04:31 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 From 55bdb8245cefd27b838639308e4dd2a4a9ff5cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 22 Oct 2024 19:23:27 +0200 Subject: [PATCH 3/3] Send "Schema Exported" event --- packages/compass-schema/src/stores/store.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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. *