Skip to content

Commit fd7e275

Browse files
committed
feat(analytics): unify command tracking events under a single method
1 parent 68e4718 commit fd7e275

4 files changed

Lines changed: 18 additions & 34 deletions

File tree

internal/analytics/analytics.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,8 @@ func (t *Tracker) TrackFirstLogin(id string, loginType string) {
5151
t.track(eventName, id, nil)
5252
}
5353

54-
func (t *Tracker) TrackCommandSucceeded(commandPath string, id string) {
55-
eventName := generateSucceededEventName(commandPath)
56-
t.track(eventName, id, map[string]string{"success": "true", "error_class": "none"})
57-
}
58-
59-
func (t *Tracker) TrackCommandFailed(commandPath string, id string, properties map[string]string) {
60-
eventName := generateFailedEventName(commandPath)
54+
func (t *Tracker) TrackCommandRun(commandPath string, id string, properties map[string]string) {
55+
eventName := generateRunEventName(commandPath)
6156
t.track(eventName, id, properties)
6257
}
6358

@@ -135,12 +130,8 @@ func newEvent(eventName string, id string, properties map[string]string) *event
135130
}
136131
}
137132

138-
func generateSucceededEventName(command string) string {
139-
return generateEventName(command, "Succeeded")
140-
}
141-
142-
func generateFailedEventName(command string) string {
143-
return generateEventName(command, "Failed")
133+
func generateRunEventName(command string) string {
134+
return generateEventName(command, "Run")
144135
}
145136

146137
func generateEventName(command string, action string) string {

internal/analytics/analytics_test.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,22 @@ func TestGenerateEventName(t *testing.T) {
3434
})
3535
}
3636

37-
func TestGenerateSucceededEventName(t *testing.T) {
37+
func TestGenerateRunEventName(t *testing.T) {
3838
t.Run("generates from root command", func(t *testing.T) {
39-
want := "CLI - Auth0 - Succeeded"
40-
got := generateSucceededEventName("auth0")
39+
want := "CLI - Auth0 - Run"
40+
got := generateRunEventName("auth0")
4141
assert.Equal(t, want, got)
4242
})
4343

4444
t.Run("generates from top-level command", func(t *testing.T) {
45-
want := "CLI - Auth0 - Apps - Succeeded"
46-
got := generateSucceededEventName("auth0 apps")
47-
assert.Equal(t, want, got)
48-
})
49-
}
50-
51-
func TestGenerateFailedEventName(t *testing.T) {
52-
t.Run("generates from root command", func(t *testing.T) {
53-
want := "CLI - Auth0 - Failed"
54-
got := generateFailedEventName("auth0")
45+
want := "CLI - Auth0 - Apps - Run"
46+
got := generateRunEventName("auth0 apps")
5547
assert.Equal(t, want, got)
5648
})
5749

5850
t.Run("generates from subcommand", func(t *testing.T) {
59-
want := "CLI - Apps - List - Failed"
60-
got := generateFailedEventName("auth0 apps list")
51+
want := "CLI - Apps - List - Run"
52+
got := generateRunEventName("auth0 apps list")
6153
assert.Equal(t, want, got)
6254
})
6355
}

internal/cli/api.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ func (i *apiCmdInputs) parseRaw(args []string) {
284284
i.RawURI = args[lenArgs-1]
285285
}
286286

287-
// newAPIResponseError builds a go-auth0 v2 management error from a non-2xx raw
288-
// `auth0 api` response. Using the real management error type (rather than a
289-
// bespoke one) means classifyCommandFailure maps the status to an error_class
290-
// through the same path as the typed SDK commands.
287+
// newAPIResponseError turns non-2xx `auth0 api` responses into SDK management errors.
288+
// This keeps `error_class` handling consistent with typed SDK commands.
291289
func newAPIResponseError(statusCode int, header http.Header, body []byte) error {
292290
message := strings.TrimSpace(string(body))
293291
if message == "" {

internal/cli/root.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,14 @@ func trackCommandOutcome(cli *cli, executionErr error) {
239239
}
240240

241241
if executionErr != nil {
242-
cli.tracker.TrackCommandFailed(cli.executedCommandPath, installID, classifyCommandFailure(executionErr))
242+
cli.tracker.TrackCommandRun(cli.executedCommandPath, installID, classifyCommandFailure(executionErr))
243243
return
244244
}
245245

246-
cli.tracker.TrackCommandSucceeded(cli.executedCommandPath, installID)
246+
cli.tracker.TrackCommandRun(cli.executedCommandPath, installID, map[string]string{
247+
"success": "true",
248+
"error_class": "none",
249+
})
247250
}
248251

249252
func resolveInstallIDForTracking(cli *cli) string {

0 commit comments

Comments
 (0)