Welcome to the final chapter of our specific feature walkthrough!
In the previous chapter, Keyboard Input Abstraction, we made our Fast Mode tool interactive. Users can now open the menu, toggle options, and confirm their choices using the keyboard.
But here is a scary thought: Once we release this to users, we are flying blind.
fast on (shortcut) or opening the menu?To answer these questions without standing behind every user's shoulder, we use Event Telemetry.
Imagine you run a bakery.
In software, Event Telemetry is that clicker. It allows our code to send small, anonymous postcards to our servers saying, "Hey, this thing just happened!"
For our fast command, we want to track two specific moments:
tengu_fast_mode_picker_shown).tengu_fast_mode_toggled).This is a unique ID for the action. It should be descriptive.
tengu_fast_mode_toggledbutton_clicked (Too vague! Which button?)Just knowing "it happened" isn't always enough. We need context. If the user toggled the mode, did they turn it ON or OFF? Did they use the Menu or the Shortcut? We pass this extra info as a simple object.
Telemetry should never slow down the application. When we log an event, we don't wait for a receipt. We "fire" the event and immediately let the code continue running.
Let's look at how we added this to fast.tsx. We use a helper function called logEvent.
When the command is called (but before the user selects anything), we want to record that the menu was opened. We also want to know if the menu showed an error (like "System Overloaded").
// inside the call() function in fast.tsx
// 1. Get the status (is the system down?)
const unavailableReason = getFastModeUnavailableReason();
// 2. Log the event
logEvent('tengu_fast_mode_picker_shown', {
unavailable_reason: (unavailableReason ?? '')
});
// 3. Show the UI (The log happens in the background)
return <FastModePicker ... />;
Explanation:
tengu_fast_mode_picker_shown: The name of our event.unavailable_reason: If the user sees an error, we want to know about it. If 1,000 users see this error, we know we have a server problem!Now, let's look at what happens when the user actually changes the setting. This happens in our logic handler.
// inside handleFastModeShortcut
// ... logic to save settings ...
logEvent('tengu_fast_mode_toggled', {
enabled: enable, // Did they turn it ON (true) or OFF (false)?
source: 'shortcut' // Did they use the CLI arg?
});
// ... return success message ...
Explanation:
enabled: This boolean is crucial. It helps us calculate the "Adoption Rate" (how many people keep it on).source: This helps our Product Designers. If 99% of users use source: 'shortcut', maybe we don't need to maintain the visual menu anymore!You might be wondering: "Does sending this data over the internet make my CLI slow?"
The answer is No. The logEvent service uses a "buffer" system.
In our code, you might notice a strange type cast: as AnalyticsMetadata_I_VERIFIED....
logEvent('tengu_fast_mode_toggled', {
enabled: enable,
source: 'picker' as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS
});
Why is this here? This is a safety mechanism.
In this final chapter, we learned about Event Telemetry:
logEvent to record specific actions (Views and Toggles).
Congratulations! You have walked through the entire lifecycle of a command in the fast project.
You now possess the knowledge to build your own powerful, interactive, and data-driven CLI tools. Happy coding!
Generated by Code IQ