From 3269de1f4a1b24ae03095f267132d389d62d98b8 Mon Sep 17 00:00:00 2001 From: ArtemHoruzhenko Date: Tue, 27 Aug 2024 10:17:01 +0300 Subject: [PATCH] add telemetry events --- .../OAuthAutodiscovery.spec.tsx | 21 ++++++++++----- .../oauth-create-db/OAuthCreateDb.spec.tsx | 17 ++++++++---- .../oauth-sign-in/OAuthSignIn.spec.tsx | 12 ++++++--- .../shared/oauth-form/OAuthForm.spec.tsx | 18 +++++++++++-- .../oauth/shared/oauth-form/OAuthForm.tsx | 27 ++++++++++++++++--- .../WelcomeAiAssistant.spec.tsx | 21 ++++++++++----- redisinsight/ui/src/telemetry/events.ts | 2 ++ 7 files changed, 91 insertions(+), 27 deletions(-) diff --git a/redisinsight/ui/src/components/oauth/oauth-sso/oauth-autodiscovery/OAuthAutodiscovery.spec.tsx b/redisinsight/ui/src/components/oauth/oauth-sso/oauth-autodiscovery/OAuthAutodiscovery.spec.tsx index 66b936600d..01bf82b64d 100644 --- a/redisinsight/ui/src/components/oauth/oauth-sso/oauth-autodiscovery/OAuthAutodiscovery.spec.tsx +++ b/redisinsight/ui/src/components/oauth/oauth-sso/oauth-autodiscovery/OAuthAutodiscovery.spec.tsx @@ -71,9 +71,9 @@ describe('OAuthAutodiscovery', () => { invokeMock.mockRestore() const expectedActions = [ - signIn(), setSSOFlow(OAuthSocialAction.Import), - setOAuthCloudSource(OAuthSocialSource.Autodiscovery) + setOAuthCloudSource(OAuthSocialSource.Autodiscovery), + signIn(), ] expect(store.getActions()).toEqual(expectedActions) @@ -88,6 +88,15 @@ describe('OAuthAutodiscovery', () => { expect(screen.getByTestId('sso-email')).toBeInTheDocument() + expect(sendEventTelemetry).toBeCalledWith({ + event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + eventData: { + accountOption: OAuthStrategy.SSO, + action: OAuthSocialAction.Import, + source: OAuthSocialSource.Autodiscovery + } + }) + await act(async () => { fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } }) }) @@ -99,11 +108,9 @@ describe('OAuthAutodiscovery', () => { }) expect(sendEventTelemetry).toBeCalledWith({ - event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED, eventData: { - accountOption: OAuthStrategy.SSO, action: OAuthSocialAction.Import, - source: OAuthSocialSource.Autodiscovery } }) @@ -121,9 +128,9 @@ describe('OAuthAutodiscovery', () => { invokeMock.mockRestore() const expectedActions = [ - signIn(), setSSOFlow(OAuthSocialAction.Import), - setOAuthCloudSource(OAuthSocialSource.Autodiscovery) + setOAuthCloudSource(OAuthSocialSource.Autodiscovery), + signIn(), ] expect(store.getActions()).toEqual(expectedActions) diff --git a/redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx b/redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx index 61e720da54..2c99da79c2 100644 --- a/redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx +++ b/redisinsight/ui/src/components/oauth/oauth-sso/oauth-create-db/OAuthCreateDb.spec.tsx @@ -72,6 +72,15 @@ describe('OAuthCreateDb', () => { expect(screen.getByTestId('sso-email')).toBeInTheDocument() + expect(sendEventTelemetry).toBeCalledWith({ + event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + eventData: { + accountOption: OAuthStrategy.SSO, + action: OAuthSocialAction.Create, + cloudRecommendedSettings: 'enabled' + } + }) + await act(async () => { fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } }) }) @@ -83,15 +92,13 @@ describe('OAuthCreateDb', () => { }) expect(sendEventTelemetry).toBeCalledWith({ - event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED, eventData: { - accountOption: OAuthStrategy.SSO, action: OAuthSocialAction.Create, - cloudRecommendedSettings: 'enabled' } }) - const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)] + const expectedActions = [setIsRecommendedSettingsSSO(true), signIn()] expect(store.getActions()).toEqual(expectedActions); (sendEventTelemetry as jest.Mock).mockRestore() }) @@ -110,7 +117,7 @@ describe('OAuthCreateDb', () => { } }) - const expectedActions = [signIn(), setIsRecommendedSettingsSSO(true)] + const expectedActions = [setIsRecommendedSettingsSSO(true), signIn()] expect(store.getActions()).toEqual(expectedActions); (sendEventTelemetry as jest.Mock).mockRestore() }) diff --git a/redisinsight/ui/src/components/oauth/oauth-sso/oauth-sign-in/OAuthSignIn.spec.tsx b/redisinsight/ui/src/components/oauth/oauth-sso/oauth-sign-in/OAuthSignIn.spec.tsx index 74060914d2..3a18f9b9c5 100644 --- a/redisinsight/ui/src/components/oauth/oauth-sso/oauth-sign-in/OAuthSignIn.spec.tsx +++ b/redisinsight/ui/src/components/oauth/oauth-sso/oauth-sign-in/OAuthSignIn.spec.tsx @@ -53,6 +53,13 @@ describe('OAuthSignIn', () => { fireEvent.click(screen.queryByTestId('sso-oauth') as HTMLButtonElement) expect(screen.getByTestId('sso-email')).toBeInTheDocument() + expect(sendEventTelemetry).toBeCalledWith({ + event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + eventData: { + accountOption: OAuthStrategy.SSO, + action: OAuthSocialAction.SignIn, + } + }) await act(async () => { fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } }) @@ -65,9 +72,8 @@ describe('OAuthSignIn', () => { }) expect(sendEventTelemetry).toBeCalledWith({ - event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED, eventData: { - accountOption: OAuthStrategy.SSO, action: OAuthSocialAction.SignIn, } }) @@ -86,8 +92,8 @@ describe('OAuthSignIn', () => { invokeMock.mockRestore() const expectedActions = [ - signIn(), setSSOFlow(OAuthSocialAction.SignIn), + signIn(), ] expect(store.getActions()).toEqual(expectedActions) diff --git a/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.spec.tsx b/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.spec.tsx index 87e6359794..cea20ec161 100644 --- a/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.spec.tsx +++ b/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.spec.tsx @@ -1,10 +1,16 @@ import React from 'react' import { cloneDeep } from 'lodash' +import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry' import { render, cleanup, mockedStore, fireEvent, screen, act, waitFor } from 'uiSrc/utils/test-utils' import { OAuthStrategy } from 'uiSrc/slices/interfaces' import { MOCK_OAUTH_SSO_EMAIL } from 'uiSrc/mocks/data/oauth' import OAuthForm from './OAuthForm' +jest.mock('uiSrc/telemetry', () => ({ + ...jest.requireActual('uiSrc/telemetry'), + sendEventTelemetry: jest.fn(), +})) + jest.mock('uiSrc/slices/oauth/cloud', () => ({ ...jest.requireActual('uiSrc/slices/oauth/cloud'), oauthCloudSelector: jest.fn().mockReturnValue({ @@ -60,6 +66,11 @@ describe('OAuthForm', () => { fireEvent.click(screen.getByTestId('btn-submit')) }) + expect(sendEventTelemetry).toBeCalledWith({ + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED, + eventData: {} + }) + expect(onClick).toBeCalledWith(OAuthStrategy.SSO) }) @@ -73,6 +84,11 @@ describe('OAuthForm', () => { fireEvent.click(screen.getByTestId('btn-back')) + expect(sendEventTelemetry).toBeCalledWith({ + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_CANCELED, + eventData: {} + }) + expect(screen.getByTestId('sso-oauth')).toBeInTheDocument() }) @@ -100,7 +116,5 @@ describe('OAuthForm', () => { await act(async () => { fireEvent.click(screen.getByTestId('btn-submit')) }) - - expect(onClick).not.toHaveBeenCalled() }) }) diff --git a/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.tsx b/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.tsx index e223664348..71853ac8d4 100644 --- a/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.tsx +++ b/redisinsight/ui/src/components/oauth/shared/oauth-form/OAuthForm.tsx @@ -3,6 +3,7 @@ import { useDispatch } from 'react-redux' import { signIn } from 'uiSrc/slices/oauth/cloud' import { OAuthSocialAction, OAuthStrategy } from 'uiSrc/slices/interfaces' import { ipcAuth } from 'uiSrc/electron/utils' +import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry' import OAuthSsoForm from './components/oauth-sso-form' import OAuthSocialButtons from '../oauth-social-buttons' import { Props as OAuthSocialButtonsProps } from '../oauth-social-buttons/OAuthSocialButtons' @@ -30,12 +31,12 @@ const OAuthForm = ({ const initOAuthProcess = (strategy: OAuthStrategy, action: string, data?: {}) => { dispatch(signIn()) - onClick?.(strategy) ipcAuth(strategy, action, data) } const onSocialButtonClick = (authStrategy: OAuthStrategy) => { setAuthStrategy(authStrategy) + onClick?.(authStrategy) switch (authStrategy) { case OAuthStrategy.Google: @@ -50,11 +51,31 @@ const OAuthForm = ({ } } + const onSsoBackButtonClick = () => { + setAuthStrategy('') + sendEventTelemetry({ + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_CANCELED, + eventData: { + action, + } + }) + } + + const onSsoLoginButtonClick = (data: {}) => { + sendEventTelemetry({ + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED, + eventData: { + action, + } + }) + initOAuthProcess(OAuthStrategy.SSO, action, data) + } + if (authStrategy === OAuthStrategy.SSO) { return ( setAuthStrategy('')} - onSubmit={(data: {}) => initOAuthProcess(OAuthStrategy.SSO, action, data)} + onBack={onSsoBackButtonClick} + onSubmit={onSsoLoginButtonClick} /> ) } diff --git a/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/welcome-ai-assistant/WelcomeAiAssistant.spec.tsx b/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/welcome-ai-assistant/WelcomeAiAssistant.spec.tsx index 56f7742c34..92a17d8fe2 100644 --- a/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/welcome-ai-assistant/WelcomeAiAssistant.spec.tsx +++ b/redisinsight/ui/src/components/side-panels/panels/ai-assistant/components/welcome-ai-assistant/WelcomeAiAssistant.spec.tsx @@ -46,9 +46,9 @@ describe('WelcomeAiAssistant', () => { fireEvent.click(screen.getByTestId('google-oauth')) expect(store.getActions()).toEqual([ - signIn(), setSSOFlow(OAuthSocialAction.SignIn), - setOAuthCloudSource(OAuthSocialSource.AiChat) + setOAuthCloudSource(OAuthSocialSource.AiChat), + signIn(), ]) expect(sendEventTelemetry).toBeCalledWith({ @@ -69,6 +69,15 @@ describe('WelcomeAiAssistant', () => { expect(screen.getByTestId('sso-email')).toBeInTheDocument() + expect(sendEventTelemetry).toBeCalledWith({ + event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + eventData: { + accountOption: OAuthStrategy.SSO, + action: OAuthSocialAction.SignIn, + source: OAuthSocialSource.AiChat + } + }) + await act(async () => { fireEvent.change(screen.getByTestId('sso-email'), { target: { value: MOCK_OAUTH_SSO_EMAIL } }) }) @@ -80,17 +89,15 @@ describe('WelcomeAiAssistant', () => { }) expect(store.getActions()).toEqual([ - signIn(), setSSOFlow(OAuthSocialAction.SignIn), - setOAuthCloudSource(OAuthSocialSource.AiChat) + setOAuthCloudSource(OAuthSocialSource.AiChat), + signIn(), ]) expect(sendEventTelemetry).toBeCalledWith({ - event: TelemetryEvent.CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED, + event: TelemetryEvent.CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED, eventData: { - accountOption: OAuthStrategy.SSO, action: OAuthSocialAction.SignIn, - source: OAuthSocialSource.AiChat } }); (sendEventTelemetry as jest.Mock).mockRestore() diff --git a/redisinsight/ui/src/telemetry/events.ts b/redisinsight/ui/src/telemetry/events.ts index b28760033c..fd0db7d0cb 100644 --- a/redisinsight/ui/src/telemetry/events.ts +++ b/redisinsight/ui/src/telemetry/events.ts @@ -270,6 +270,8 @@ export enum TelemetryEvent { CLOUD_FREE_DATABASE_CLICKED = 'CLOUD_FREE_DATABASE_CLICKED', CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED = 'CLOUD_SIGN_IN_SOCIAL_ACCOUNT_SELECTED', + CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED = 'CLOUD_SIGN_IN_SSO_OPTION_PROCEEDED', + CLOUD_SIGN_IN_SSO_OPTION_CANCELED = 'CLOUD_SIGN_IN_SSO_OPTION_CANCELED', CLOUD_SIGN_IN_FORM_CLOSED = 'CLOUD_SIGN_IN_FORM_CLOSED', CLOUD_SIGN_IN_CLICKED = 'CLOUD_SIGN_IN_CLICKED', CLOUD_SIGN_IN_SUCCEEDED = 'CLOUD_SIGN_IN_SUCCEEDED',