Skip to content

Commit

Permalink
feat(analytics): more login related events
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Aug 27, 2021
1 parent 3a717b6 commit c31fb4f
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,5 @@ export const NEED_HELP_CLICKED = 'NEED_HELP_CLICKED'
export const LOGIN_ID_ENTERED = 'LOGIN_ID_ENTERED'
export const LOGIN_METHOD_SELECTED = 'LOGIN_METHOD_SELECTED'
export const LOGIN_PASSWORD_DENIED = 'LOGIN_PASSWORD_DENIED'
export const LOGIN_TWO_STEP_VERIFICATION_DENIED = 'LOGIN_TWO_STEP_VERIFICATION_DENIED'
export const LOGIN_TWO_STEP_VERIFICATION_ENTERED = 'LOGIN_TWO_STEP_VERIFICATION_ENTERED'
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,10 @@ export const loginMethodSelected = (loginMethod) => ({
export const loginPasswordDenied = () => ({
type: AT.LOGIN_PASSWORD_DENIED
})

export const loginTwoStepVerificationDenied = () => ({
type: AT.LOGIN_TWO_STEP_VERIFICATION_DENIED
})
export const loginTwoStepVerificationEntered = () => ({
type: AT.LOGIN_TWO_STEP_VERIFICATION_ENTERED
})
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ export default ({ api, coreSagas, networks }) => {
const formValues = yield select(selectors.form.getFormValues('login'))
const { email, emailToken } = formValues
let session = yield select(selectors.session.getSession, guid, email)
if (code) {
yield put(A.loginTwoStepVerificationEntered())
}
yield put(startSubmit('login'))
try {
if (!session) {
Expand Down Expand Up @@ -440,11 +443,13 @@ export default ({ api, coreSagas, networks }) => {
// Wrong 2fa code error
error &&
is(String, error) &&
error.includes('Authentication code is incorrect')
(error.includes('Authentication code is incorrect') ||
error.includes('Invalid authentication code'))
) {
yield put(actions.form.clearFields('login', false, true, 'code'))
yield put(actions.form.focus('login', 'code'))
yield put(actions.auth.loginFailure(error))
yield put(A.loginTwoStepVerificationDenied())
} else if (error && is(String, error)) {
yield put(actions.auth.loginFailure(error))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from 'middleware/analyticsMiddleware/utils'

import { actions, actionTypes as AT } from 'data'
import { login } from 'data/auth/actions'
import { convertBaseToStandard } from 'data/components/exchange/services'
import { BankDWStepType, InterestStep, ModalName, SwapBaseCounterTypes } from 'data/types'

Expand Down Expand Up @@ -123,6 +122,27 @@ const analyticsMiddleware = () => (store) => (next) => (action) => {

break
}
case '/login': {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
const email = state.profile.userData.getOrElse({})?.emailVerified
? state.profile.userData.getOrElse({})?.email
: null
const tier = state.profile.userData.getOrElse({})?.tiers?.current ?? null
const guid = state.walletPath.wallet.guid ?? null
analytics.push(AnalyticsKey.SETTINGS_CURRENCY_CLICKED, {
properties: {
guid,
originalTimestamp: getOriginalTimestamp()
},
traits: {
email,
nabuId,
tier
}
})
break
}
case '/settings/addresses/btc': {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
Expand Down Expand Up @@ -2825,6 +2845,118 @@ const analyticsMiddleware = () => (store) => (next) => (action) => {
})
break
}
case AT.auth.LOGIN: {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
const email = state.profile.userData.getOrElse({})?.emailVerified
? state.profile.userData.getOrElse({})?.email
: null
const tier = state.profile.userData.getOrElse({})?.tiers?.current ?? null
const guid = state.walletPath.wallet.guid ?? null

analytics.push(AnalyticsKey.LOGIN_PASSWORD_ENTERED, {
properties: {
guid,
originalTimestamp: getOriginalTimestamp()
},
traits: {
email,
nabuId,
tier
}
})
break
}
case AT.auth.SECURE_CHANNEL_LOGIN_SUCCESS: {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
const email = state.profile.userData.getOrElse({})?.emailVerified
? state.profile.userData.getOrElse({})?.email
: null
const tier = state.profile.userData.getOrElse({})?.tiers?.current ?? null
const guid = state.walletPath.wallet.guid ?? null

analytics.push(AnalyticsKey.LOGIN_REQUEST_APPROVED, {
properties: {
guid,
originalTimestamp: getOriginalTimestamp(),
request_platform: 'WALLET'
},
traits: {
email,
nabuId,
tier
}
})
break
}
case AT.auth.SECURE_CHANNEL_LOGIN_FAILURE: {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
const email = state.profile.userData.getOrElse({})?.emailVerified
? state.profile.userData.getOrElse({})?.email
: null
const tier = state.profile.userData.getOrElse({})?.tiers?.current ?? null
const guid = state.walletPath.wallet.guid ?? null

analytics.push(AnalyticsKey.LOGIN_REQUEST_DENIED, {
properties: {
guid,
originalTimestamp: getOriginalTimestamp(),
request_platform: 'WALLET'
},
traits: {
email,
nabuId,
tier
}
})
break
}
case AT.auth.LOGIN_TWO_STEP_VERIFICATION_DENIED: {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
const email = state.profile.userData.getOrElse({})?.emailVerified
? state.profile.userData.getOrElse({})?.email
: null
const tier = state.profile.userData.getOrElse({})?.tiers?.current ?? null
const guid = state.walletPath.wallet.guid ?? null

analytics.push(AnalyticsKey.LOGIN_TWO_STEP_VERIFICATION_DENIED, {
properties: {
guid,
originalTimestamp: getOriginalTimestamp()
},
traits: {
email,
nabuId,
tier
}
})
break
}
case AT.auth.LOGIN_TWO_STEP_VERIFICATION_ENTERED: {
const state = store.getState()
const nabuId = state.profile.userData.getOrElse({})?.id ?? null
const email = state.profile.userData.getOrElse({})?.emailVerified
? state.profile.userData.getOrElse({})?.email
: null
const tier = state.profile.userData.getOrElse({})?.tiers?.current ?? null
const guid = state.walletPath.wallet.guid ?? null

analytics.push(AnalyticsKey.LOGIN_TWO_STEP_VERIFICATION_ENTERED, {
properties: {
guid,
originalTimestamp: getOriginalTimestamp()
},
traits: {
email,
nabuId,
tier
}
})
break
}
default: {
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ enum AnalyticsKey {
LOGIN_IDENTIFIER_ENTERED = 'Login Identifier Entered',
LOGIN_METHOD_SELECTED = 'Login Method Selected',
LOGIN_PASSWORD_DENIED = 'Login Password Denied',
LOGIN_PASSWORD_ENTERED = 'Login Password Entered',
LOGIN_REQUEST_APPROVED = 'Login Request Approved',
LOGIN_REQUEST_DENIED = 'Login Request Denied',
LOGIN_TWO_STEP_VERIFICATION_DENIED = 'Login Two Step Verification Denied',
LOGIN_TWO_STEP_VERIFICATION_ENTERED = 'Login Two Step Verification Entered',
LOGIN_VIEWED = 'Login Viewed',
MANAGE_TAB_SELECTION_CLICKED = 'Manage Tab Selection Clicked',
NOTIFICATION_PREFERENCES_UPDATED = 'Notification Preferences Updated',
PRIVATE_KEYS_SHOWN = 'Private Keys Shown',
Expand Down Expand Up @@ -147,6 +153,7 @@ type PageViewPayload = {
type PageName =
| '/home'
| '/interest'
| '/login'
| '/settings/addresses/btc'
| '/settings/addresses/bch'
| '/settings/addresses/eth'
Expand Down Expand Up @@ -336,6 +343,10 @@ type ManageTabSelectionClickedSelection =
| 'SHOW_CHANGE_ADDRESSES'
| 'SHOW_XPUB'

type LoginRequestPayload = BasePayload & {
request_platform: 'EXCHANGE' | 'WALLET'
}

type ManageTabSelectionClickedPayload = BasePayload & {
currency: string
selection: ManageTabSelectionClickedSelection
Expand Down Expand Up @@ -608,6 +619,7 @@ type AnalyticsProperties =
| LinkBankClickedPayload
| LoginIdentifierEnteredPayload
| LoginMethodSelectedPayload
| LoginRequestPayload
| ManageTabSelectionClickedPayload
| NotificationPreferencesUpdatedPayload
| PrivateKeysShownPayload
Expand Down

0 comments on commit c31fb4f

Please sign in to comment.