Skip to content

Commit 1b1f08d

Browse files
authored
chore(compass-schema): "Schema Exported" event COMPASS-8332 (#6389)
* Add "Schema Exported" event * Update tracking plan * Send "Schema Exported" event
1 parent 2b44d26 commit 1b1f08d

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

docs/tracking-plan.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ Generated on Tue, Oct 29, 2024 at 05:29 PM
148148

149149
### Schema
150150
- [Schema Analyzed](#event--SchemaAnalyzedEvent)
151+
- [Schema Exported](#event--SchemaExportedEvent)
151152

152153
### Schema Validation
153154
- [Schema Validation Added](#event--SchemaValidationAddedEvent)
@@ -1801,6 +1802,25 @@ This event is fired when user analyzes the schema.
18011802
- **connection_id** (optional): `string | undefined`
18021803
- The id of the connection associated to this event.
18031804

1805+
<a name="event--SchemaExportedEvent"></a>
1806+
1807+
### Schema Exported
1808+
1809+
This event is fired when user shares the schema.
1810+
1811+
**Properties**:
1812+
1813+
- **has_schema** (required): `boolean`
1814+
- Indicates whether the schema was analyzed before sharing.
1815+
- **schema_width** (required): `number`
1816+
- The number of fields at the top level.
1817+
- **schema_depth** (required): `number`
1818+
- The number of nested levels.
1819+
- **geo_data** (required): `boolean`
1820+
- Indicates whether the schema contains geospatial data.
1821+
- **connection_id** (optional): `string | undefined`
1822+
- The id of the connection associated to this event.
1823+
18041824

18051825
## Schema Validation
18061826

packages/compass-schema/src/stores/store.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export type SchemaStore = StoreWithStateMixin<SchemaState> & {
8787
dataService: DataService;
8888

8989
handleSchemaShare(): void;
90+
_trackSchemaShared(hasSchema: boolean): void;
91+
9092
onSchemaSampled(): void;
9193
geoLayerAdded(
9294
field: string,
@@ -162,6 +164,7 @@ export function activateSchemaPlugin(
162164
JSON.stringify(this.state.schema, null, ' ')
163165
);
164166
const hasSchema = this.state.schema !== null;
167+
this._trackSchemaShared(hasSchema);
165168
openToast(
166169
'share-schema',
167170
hasSchema
@@ -181,6 +184,21 @@ export function activateSchemaPlugin(
181184
);
182185
},
183186

187+
_trackSchemaShared(this: SchemaStore, hasSchema: boolean) {
188+
const { schema } = this.state;
189+
// Use a function here to a) ensure that the calculations here
190+
// are only made when telemetry is enabled and b) that errors from
191+
// those calculations are caught and logged rather than displayed to
192+
// users as errors from the core schema sharing logic.
193+
const trackEvent = () => ({
194+
has_schema: hasSchema,
195+
schema_width: schema?.fields?.length ?? 0,
196+
schema_depth: schema ? calculateSchemaDepth(schema) : 0,
197+
geo_data: schema ? schemaContainsGeoData(schema) : false,
198+
});
199+
track('Schema Exported', trackEvent, connectionInfoRef.current);
200+
},
201+
184202
/**
185203
* Initialize the schema store.
186204
*

packages/compass-telemetry/src/telemetry-events.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,36 @@ type SchemaAnalyzedEvent = ConnectionScoped<{
19281928
};
19291929
}>;
19301930

1931+
/**
1932+
* This event is fired when user shares the schema.
1933+
*
1934+
* @category Schema
1935+
*/
1936+
type SchemaExportedEvent = ConnectionScoped<{
1937+
name: 'Schema Exported';
1938+
payload: {
1939+
/**
1940+
* Indicates whether the schema was analyzed before sharing.
1941+
*/
1942+
has_schema: boolean;
1943+
1944+
/**
1945+
* The number of fields at the top level.
1946+
*/
1947+
schema_width: number;
1948+
1949+
/**
1950+
* The number of nested levels.
1951+
*/
1952+
schema_depth: number;
1953+
1954+
/**
1955+
* Indicates whether the schema contains geospatial data.
1956+
*/
1957+
geo_data: boolean;
1958+
};
1959+
}>;
1960+
19311961
/**
19321962
* This event is fired when a user clicks to show the details of an operation.
19331963
*
@@ -2641,6 +2671,7 @@ export type TelemetryEvent =
26412671
| QueryHistoryRecentUsedEvent
26422672
| QueryResultsRefreshedEvent
26432673
| SchemaAnalyzedEvent
2674+
| SchemaExportedEvent
26442675
| SchemaValidationAddedEvent
26452676
| SchemaValidationEditedEvent
26462677
| SchemaValidationUpdatedEvent

0 commit comments

Comments
 (0)