Skip to content

Commit

Permalink
chore(compass-schema): "Schema Exported" event COMPASS-8332 (#6389)
Browse files Browse the repository at this point in the history
* Add "Schema Exported" event

* Update tracking plan

* Send "Schema Exported" event
  • Loading branch information
kraenhansen authored Oct 30, 2024
1 parent 2b44d26 commit 1b1f08d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/tracking-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.

<a name="event--SchemaExportedEvent"></a>

### 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

Expand Down
18 changes: 18 additions & 0 deletions packages/compass-schema/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export type SchemaStore = StoreWithStateMixin<SchemaState> & {
dataService: DataService;

handleSchemaShare(): void;
_trackSchemaShared(hasSchema: boolean): void;

onSchemaSampled(): void;
geoLayerAdded(
field: string,
Expand Down Expand Up @@ -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
Expand All @@ -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.
*
Expand Down
31 changes: 31 additions & 0 deletions packages/compass-telemetry/src/telemetry-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -2641,6 +2671,7 @@ export type TelemetryEvent =
| QueryHistoryRecentUsedEvent
| QueryResultsRefreshedEvent
| SchemaAnalyzedEvent
| SchemaExportedEvent
| SchemaValidationAddedEvent
| SchemaValidationEditedEvent
| SchemaValidationUpdatedEvent
Expand Down

0 comments on commit 1b1f08d

Please sign in to comment.