Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(compass-schema): "Schema Exported" event COMPASS-8332 #6389

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
22 changes: 21 additions & 1 deletion docs/tracking-plan.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
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,
Anemy marked this conversation as resolved.
Show resolved Hide resolved
});
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
Loading