-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: track help cmd #245
feat: track help cmd #245
Conversation
func CmdRunEventProperties( | ||
cmd *cobra.Command, | ||
name string, | ||
overrides map[string]interface{}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add overrides so we can pass in an optional "action: help". We could make this functional options if we want to use it for more than the one-off case this introduces.
cmdAnalytics.CmdRunEventProperties(cmd, "config"), | ||
) | ||
// only track event if there are flags | ||
if len(os.Args[1:]) > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there's a better way to do this. Since we define config --list/--set/--unset
with no action, we only want to send this if we're not showing help.
@@ -53,6 +56,19 @@ func NewConfigCmd(analyticsTracker analytics.Tracker) *cobra.Command { | |||
sb.WriteString(fmt.Sprintf("- `%s`: %s\n", s, cliflags.AllFlagsHelp()[s])) | |||
} | |||
cmd.Long += sb.String() | |||
|
|||
analyticsTracker.SendCommandRunEvent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is similar to what we do in the root command.
// getResourceCommand returns the command for a resource or an action's parent resource. | ||
// ldcli projects // returns projects command | ||
// ldcli projects list // returns projects command | ||
func getResourceCommand(c *cobra.Command) *cobra.Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need this since a user could call help in various ways.
ID string | ||
HTTPClient *http.Client | ||
Version string | ||
sentHelpEvent bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to keep state here to know if we already tracked a help event.
Send analytics when showing help, either when the user asks (--help) or if it's an error and we show the help.
Here are example inputs with their respective analytics output:
These also send "CLI Command Completed" with an outcome of "help."
Requirements
Related issues
Provide links to any issues in this repository or elsewhere relating to this pull request.
Describe the solution you've provided
Provide a clear and concise description of what you expect to happen.
Describe alternatives you've considered
Provide a clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context about the pull request here.