Skip to content

Commit

Permalink
feat: track setup completed (#272)
Browse files Browse the repository at this point in the history
Send command completed event when user gets to toggle flag setup page
  • Loading branch information
dbolson authored May 13, 2024
1 parent 68e6b5c commit 6554b7d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
38 changes: 26 additions & 12 deletions internal/quickstart/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (m ContainerModel) Init() tea.Cmd {

func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
var sendEvent bool
var shouldSendTrackingEvent bool
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width = msg.Width
Expand Down Expand Up @@ -128,7 +128,7 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.environment,
)
cmd = m.currentModel.Init()
sendEvent = true
shouldSendTrackingEvent = true
}
default:
// delegate all other input to the current model
Expand All @@ -139,7 +139,7 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.flagKey = msg.flag.key
m.currentStep += 1
m.err = nil
sendEvent = true
shouldSendTrackingEvent = true
case choseSDKMsg:
m.currentModel = NewShowSDKInstructionsModel(
m.environmentsClient,
Expand All @@ -156,7 +156,7 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmd = m.currentModel.Init()
m.sdk = msg.sdk
m.currentStep += 1
sendEvent = true
shouldSendTrackingEvent = true
case errMsg:
m.currentModel, cmd = m.currentModel.Update(msg)
case fetchedEnvMsg:
Expand All @@ -182,7 +182,7 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.toggleTime = msg.time
m.flagToggled = true
m.err = nil
sendEvent = true
shouldSendTrackingEvent = true
case showToggleFlagMsg:
m.currentModel = NewToggleFlagModel(
m.flagsClient,
Expand All @@ -193,23 +193,37 @@ func (m ContainerModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
cmd = m.currentModel.Init()
m.currentStep += 1
sendEvent = true
shouldSendTrackingEvent = true
default:
// ignore other messages
}

if sendEvent {
cmd = tea.Batch(cmd, trackSetupStepStartedEvent(m.analyticsTracker, m.currentStep.String()))

if m.currentStep == stepShowSDKInstructions {
cmd = tea.Batch(cmd, trackSetupSDKSelectedEvent(m.analyticsTracker, m.sdk.canonicalName))
} else if (m.currentStep == stepToggleFlag) && m.flagToggled {
if shouldSendTrackingEvent {
switch {
case m.currentStep == stepShowSDKInstructions:
cmd = tea.Batch(
cmd,
trackSetupStepStartedEvent(m.analyticsTracker, m.currentStep.String()),
trackSetupSDKSelectedEvent(m.analyticsTracker, m.sdk.canonicalName),
)
case m.currentStep == stepToggleFlag && !m.flagToggled:
// the first time we get to the flag toggled view
cmd = tea.Batch(
cmd,
trackSendCommandCompletedEvent(m.analyticsTracker),
trackSetupStepStartedEvent(m.analyticsTracker, m.currentStep.String()),
)
case m.currentStep == stepToggleFlag && m.flagToggled:
// subsequent times we've toggled the flag in the toggle flag view
cmd = tea.Batch(cmd, trackSetupFlagToggledEvent(
m.analyticsTracker,
m.flagStatus,
m.toggleCount,
m.toggleTime.Sub(m.startTime).Milliseconds(),
))
default:
// all other views
cmd = tea.Batch(cmd, trackSetupStepStartedEvent(m.analyticsTracker, m.currentStep.String()))
}
}

Expand Down
8 changes: 8 additions & 0 deletions internal/quickstart/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ func trackSetupFlagToggledEvent(tracker analytics.Tracker, on bool, count int, d
}
}

func trackSendCommandCompletedEvent(tracker analytics.Tracker) tea.Cmd {
return func() tea.Msg {
tracker.SendCommandCompletedEvent(analytics.SUCCESS)

return eventTrackedMsg{}
}
}

type flagToggleThrottleMsg int

func throttleFlagToggle(count int) tea.Cmd {
Expand Down

0 comments on commit 6554b7d

Please sign in to comment.