Skip to content

Commit

Permalink
feat: track sdk selected on setup (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny Guduru authored Apr 30, 2024
1 parent 3b408cc commit 2e3445c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
48 changes: 48 additions & 0 deletions internal/analytics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ type Tracker interface {
optOut bool,
step string,
)
SendSetupSDKSelectedEvent(
accessToken,
baseURI string,
optOut bool,
sdk string,
)
SendSetupFlagToggledEvent(
accessToken,
baseURI string,
Expand Down Expand Up @@ -159,6 +165,23 @@ func (c *Client) SendSetupStepStartedEvent(
)
}

func (c *Client) SendSetupSDKSelectedEvent(
accessToken,
baseURI string,
optOut bool,
sdk string,
) {
c.sendEvent(
accessToken,
baseURI,
optOut,
"CLI Setup SDK Selected",
map[string]interface{}{
"sdk": sdk,
},
)
}

func (c *Client) SendSetupFlagToggledEvent(
accessToken,
baseURI string,
Expand Down Expand Up @@ -210,6 +233,14 @@ func (c *NoopClient) SendSetupStepStartedEvent(
) {
}

func (c *NoopClient) SendSetupSDKSelectedEvent(
accessToken,
baseURI string,
optOut bool,
sdk string,
) {
}

func (c *NoopClient) SendSetupFlagToggledEvent(
accessToken,
baseURI string,
Expand Down Expand Up @@ -285,6 +316,23 @@ func (m *MockTracker) SendSetupStepStartedEvent(
)
}

func (m *MockTracker) SendSetupSDKSelectedEvent(
accessToken,
baseURI string,
optOut bool,
sdk string,
) {
m.sendEvent(
accessToken,
baseURI,
optOut,
"CLI Setup SDK Selected",
map[string]interface{}{
"sdk": sdk,
},
)
}

func (m *MockTracker) SendSetupFlagToggledEvent(
accessToken,
baseURI string,
Expand Down
10 changes: 9 additions & 1 deletion internal/quickstart/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.currentStep.String(),
))

if (m.currentStep == stepToggleFlag) && m.flagToggled {
if m.currentStep == stepShowSDKInstructions {
cmd = tea.Batch(cmd, trackSetupSDKSelectedEvent(
m.analyticsTracker,
m.accessToken,
m.baseUri,
m.analyticsOptOut,
m.sdk.canonicalName,
))
} else if (m.currentStep == stepToggleFlag) && m.flagToggled {
cmd = tea.Batch(cmd, trackSetupFlagToggledEvent(
m.analyticsTracker,
m.accessToken,
Expand Down
8 changes: 8 additions & 0 deletions internal/quickstart/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ func trackSetupStepStartedEvent(tracker analytics.Tracker, accessToken, baseURI
}
}

func trackSetupSDKSelectedEvent(tracker analytics.Tracker, accessToken, baseURI string, optOut bool, sdk string) tea.Cmd {
return func() tea.Msg {
tracker.SendSetupSDKSelectedEvent(accessToken, baseURI, optOut, sdk)

return eventTrackedMsg{}
}
}

func trackSetupFlagToggledEvent(tracker analytics.Tracker, accessToken, baseURI string, optOut, on bool, count int, duration_ms int64) tea.Cmd {
return func() tea.Msg {
tracker.SendSetupFlagToggledEvent(accessToken, baseURI, optOut, on, count, duration_ms)
Expand Down

0 comments on commit 2e3445c

Please sign in to comment.