-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: dev server commands emit events (#410)
This adds events for the dev server commands so that we can track adoption. Along the way, I also did the following * Added a LogClient implementation for testing event tracking * Simplified the TrackerFn so that it was easier to swap clients * Split up the event tracker implementations into multiple files * Added a note on what steps are needed to add a command because we missed 2/3 for the dev server.
- Loading branch information
Showing
8 changed files
with
183 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package analytics | ||
|
||
import "log" | ||
|
||
type LogClientFn struct{} | ||
|
||
func (fn LogClientFn) Tracker(_ string, _ string, _ bool) Tracker { | ||
return &LogClient{} | ||
} | ||
|
||
type LogClient struct{} | ||
|
||
func (c *LogClient) SendCommandRunEvent(properties map[string]interface{}) { | ||
log.Printf("SendCommandRunEvent, properties: %v", properties) | ||
} | ||
func (c *LogClient) SendCommandCompletedEvent(outcome string) { | ||
log.Printf("SendCommandCompletedEvent, outcome: %v", outcome) | ||
} | ||
func (c *LogClient) SendSetupStepStartedEvent(step string) { | ||
log.Printf("SendSetupStepStartedEvent, step: %v", step) | ||
} | ||
func (c *LogClient) SendSetupSDKSelectedEvent(sdk string) { | ||
log.Printf("SendSetupSDKSelectedEvent, sdk: %v", sdk) | ||
} | ||
func (c *LogClient) SendSetupFlagToggledEvent(on bool, count int, duration_ms int64) { | ||
log.Printf("SendSetupFlagToggledEvent, count: %v", count) | ||
} | ||
func (a *LogClient) Wait() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package analytics | ||
|
||
import "github.com/stretchr/testify/mock" | ||
|
||
type MockTracker struct { | ||
mock.Mock | ||
ID string | ||
} | ||
|
||
func (m *MockTracker) sendEvent(eventName string, properties map[string]interface{}) { | ||
properties["id"] = m.ID | ||
m.Called(eventName, properties) | ||
} | ||
|
||
func (m *MockTracker) SendCommandRunEvent(properties map[string]interface{}) { | ||
m.sendEvent( | ||
"CLI Command Run", | ||
properties, | ||
) | ||
} | ||
|
||
func (m *MockTracker) SendCommandCompletedEvent(outcome string) { | ||
m.sendEvent( | ||
"CLI Command Completed", | ||
map[string]interface{}{ | ||
"outcome": outcome, | ||
}, | ||
) | ||
} | ||
|
||
func (m *MockTracker) SendSetupStepStartedEvent(step string) { | ||
m.sendEvent( | ||
"CLI Setup Step Started", | ||
map[string]interface{}{ | ||
"step": step, | ||
}, | ||
) | ||
} | ||
|
||
func (m *MockTracker) SendSetupSDKSelectedEvent(sdk string) { | ||
m.sendEvent( | ||
"CLI Setup SDK Selected", | ||
map[string]interface{}{ | ||
"sdk": sdk, | ||
}, | ||
) | ||
} | ||
|
||
func (m *MockTracker) SendSetupFlagToggledEvent(on bool, count int, duration_ms int64) { | ||
m.sendEvent( | ||
"CLI Setup Flag Toggled", | ||
map[string]interface{}{ | ||
"on": on, | ||
"count": count, | ||
"duration_ms": duration_ms, | ||
}, | ||
) | ||
} | ||
|
||
func (a *MockTracker) Wait() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package analytics | ||
|
||
type NoopClientFn struct{} | ||
|
||
func (fn NoopClientFn) Tracker() TrackerFn { | ||
return func(_ string, _ string, _ bool) Tracker { | ||
return &NoopClient{} | ||
} | ||
} | ||
|
||
type NoopClient struct{} | ||
|
||
func (c *NoopClient) SendCommandRunEvent(properties map[string]interface{}) {} | ||
func (c *NoopClient) SendCommandCompletedEvent(outcome string) {} | ||
func (c *NoopClient) SendSetupStepStartedEvent(step string) {} | ||
func (c *NoopClient) SendSetupSDKSelectedEvent(sdk string) {} | ||
func (c *NoopClient) SendSetupFlagToggledEvent(on bool, count int, duration_ms int64) {} | ||
func (a *NoopClient) Wait() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package analytics | ||
|
||
type TrackerFn func(accessToken string, baseURI string, optOut bool) Tracker | ||
|
||
type Tracker interface { | ||
SendCommandRunEvent(properties map[string]interface{}) | ||
SendCommandCompletedEvent(outcome string) | ||
SendSetupStepStartedEvent(step string) | ||
SendSetupSDKSelectedEvent(sdk string) | ||
SendSetupFlagToggledEvent(on bool, count int, duration_ms int64) | ||
Wait() | ||
} |