Skip to content

Commit

Permalink
Send "Schema Shared" event
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Oct 22, 2024
1 parent cafa077 commit b26708a
Showing 1 changed file with 18 additions and 0 deletions.
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 Shared', trackEvent, connectionInfoRef.current);
},

/**
* Initialize the schema store.
*
Expand Down

0 comments on commit b26708a

Please sign in to comment.