From 2e3445c7487babb65b8b50a27cd05f866510de76 Mon Sep 17 00:00:00 2001 From: Sunny Guduru Date: Tue, 30 Apr 2024 15:56:45 -0700 Subject: [PATCH] feat: track sdk selected on setup (#221) --- internal/analytics/client.go | 48 ++++++++++++++++++++++++++++++++ internal/quickstart/container.go | 10 ++++++- internal/quickstart/messages.go | 8 ++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/internal/analytics/client.go b/internal/analytics/client.go index 9b0265c9..17e64347 100644 --- a/internal/analytics/client.go +++ b/internal/analytics/client.go @@ -30,6 +30,12 @@ type Tracker interface { optOut bool, step string, ) + SendSetupSDKSelectedEvent( + accessToken, + baseURI string, + optOut bool, + sdk string, + ) SendSetupFlagToggledEvent( accessToken, baseURI string, @@ -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, @@ -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, @@ -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, diff --git a/internal/quickstart/container.go b/internal/quickstart/container.go index 9b95c4c2..21e8804c 100644 --- a/internal/quickstart/container.go +++ b/internal/quickstart/container.go @@ -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, diff --git a/internal/quickstart/messages.go b/internal/quickstart/messages.go index 8d6a06dd..26ab070b 100644 --- a/internal/quickstart/messages.go +++ b/internal/quickstart/messages.go @@ -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)