Skip to content

Conversation

@kylelai1
Copy link
Collaborator

Description

CLOUDP-333861

  • Adds analytics track events as per the TD

Checklist

  • [ x ] New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • [ x ] Misc

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • [ x ] Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@kylelai1 kylelai1 marked this pull request as ready for review October 21, 2025 19:41
@kylelai1 kylelai1 requested a review from a team as a code owner October 21, 2025 19:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive telemetry tracking for the Mock Data Generator modal feature to measure user engagement and feature usage patterns. The changes implement analytics events as specified in the technical design document for tracking user interactions throughout the mock data generation workflow.

Key changes:

  • Defined 9 new telemetry event types for tracking button views, modal interactions, and user actions
  • Instrumented modal screens and user interactions with tracking calls
  • Added test coverage for all new tracking events

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/compass-telemetry/src/telemetry-events.ts Defines 9 new event types for Mock Data Generator analytics
packages/compass-collection/src/components/mock-data-generator-modal/utils.ts Exports max collection nesting depth constant for reuse
packages/compass-collection/src/components/mock-data-generator-modal/types.ts Adds enum for data generation steps used in telemetry
packages/compass-collection/src/components/mock-data-generator-modal/script-screen.tsx Tracks script generation and copy events
packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.tsx Tracks screen views, progression, and modal dismissal
packages/compass-collection/src/components/mock-data-generator-modal/faker-mapping-selector.tsx Tracks faker method changes
packages/compass-collection/src/components/mock-data-generator-modal/document-count-screen.tsx Tracks document count changes
packages/compass-collection/src/components/mock-data-generator-modal/constants.ts Adds step progression map for telemetry
packages/compass-collection/src/components/collection-header-actions/collection-header-actions.tsx Tracks CTA button views and clicks
packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.spec.tsx Tests for new tracking events in modal
packages/compass-collection/src/components/mock-data-generator-modal/faker-mapping-selector.spec.tsx Tests for faker method change tracking
packages/compass-collection/src/components/collection-header-actions/collection-header-actions.spec.tsx Tests for CTA button tracking events

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

output_docs_count: documentCount,
});
}
});
Copy link

Copilot AI Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This useEffect is missing its dependency array, which will cause the tracking event to fire on every render. Add [scriptResult.success, fakerSchema, documentCount, track] as dependencies to ensure it only fires when the script is successfully generated.

Suggested change
});
}, [scriptResult.success, fakerSchema, documentCount, track]);

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

co-pilot is correct here, we want to add deps here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the missing deps

@kylelai1 kylelai1 requested a review from kpamaran October 21, 2025 19:56
const onFakerMethodChange = useCallback(
(newMethod: string) => {
track('Mock Data Faker Method Changed', {
field_name: activeJsonType,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be the field name, not the type. We can pass that into this component from mock-data-generator-modal. Also not a bad idea to include the jsonType, let's add json_type: activeJsonType here too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed!

track('Mock Data Generator Dismissed', {
screen: currentStep,
gen_ai_features_enabled: false,
send_sample_values_enabled: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these hardcoded values snuck in here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this, thanks for flagging!

@jcobis
Copy link
Collaborator

jcobis commented Oct 21, 2025

Also, missed this but let's add a Mock Data JSON Type Changed event as well, perhaps with properties:

field_name: string,
previous_json_type: MongoDBFieldType,
new_json_type: MongoDBFieldType
previous_faker_method: string,
new_faker_method: string,

Comment on lines 145 to 159
useEffect(() => {
if (shouldShowMockDataButton) {
track('Mock Data Generator CTA Button Viewed', {
button_enabled: !shouldDisableMockDataButton,
gen_ai_features_enabled: isAIFeatureEnabled,
send_sample_values_enabled: isSampleDocumentPassingEnabled,
});
}
}, [
track,
isAIFeatureEnabled,
isSampleDocumentPassingEnabled,
shouldDisableMockDataButton,
shouldShowMockDataButton,
]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can use useTrackOnChange hook that '@mongodb-js/compass-telemetry/provider' exports

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is awesome, will use useTrackOnChange!

});
onFakerFunctionSelect(newMethod);
},
[activeJsonType, onFakerFunctionSelect, track]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing fieldName from deps list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this here! it was a late addition

@kylelai1
Copy link
Collaborator Author

Also, missed this but let's add a Mock Data JSON Type Changed event as well, perhaps with properties:

field_name: string,
previous_json_type: MongoDBFieldType,
new_json_type: MongoDBFieldType
previous_faker_method: string,
new_faker_method: string,

Added the new event!

Comment on lines 3258 to 3273
| 'String'
| 'Number'
| 'Boolean'
| 'Date'
| 'Int32'
| 'Decimal128'
| 'Long'
| 'ObjectId'
| 'RegExp'
| 'Symbol'
| 'MaxKey'
| 'MinKey'
| 'Binary'
| 'Code'
| 'Timestamp'
| 'DBRef';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can extract this bit to a type and then use for previous_json_type, new_json_type and within MockDataFakerMethodChangedEvent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly for screens?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can add this. Any reason that other events in the file don't use any types and just write out the union of strings?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this until now :) I don't think there's any specific reason for this - its just that this caught my eye especially as the list a big, so made sense to type it out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi - we use these types to generate Compass tracking-plan.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol I see what you did there

[track]
);

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also use useTrackOnChange here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Copy link
Collaborator

@jcobis jcobis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kylelai1 kylelai1 requested a review from mabaasit October 23, 2025 15:05
@kylelai1 kylelai1 merged commit bf64826 into main Oct 24, 2025
170 of 180 checks passed
@kylelai1 kylelai1 deleted the CLOUDP-333861 branch October 24, 2025 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants