Skip to content

Commit

Permalink
[Wallet] Add balance and contact tracking (#4209)
Browse files Browse the repository at this point in the history
### Description

The new wallet KPIs require a few analytics we weren't already tracking. This PR adds balance and contact imports tracking, which is the final addition to be able to calculate the KPIs listed [here](https://docs.google.com/document/d/1G_XGpggW6cTBENcvs4v6XpaZzkTpST2D0kh31V9OVtU/edit). 

Note that transaction size analytics will be calculated using eksportisto data

### Tested

Not tested, no logic change- just adding analytics

### Related issues

- Related to epics #4008 and #4004 
- Fee tracking to help identify the extent of #4010 

### Backwards compatibility

Yes
  • Loading branch information
annakaz committed Jun 25, 2020
1 parent 9b47278 commit e74c778
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/mobile/src/analytics/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ export enum CustomEventNames {
import_contacts = 'import_contacts',
import_contact_error = 'import_contact_error',
import_contacts_skip = 'import_contacts_skip',
fetched_contacts = 'fetched_contacts',
add_contact_match = 'add_contact_match',

// Escrowed payments
escrowed_payment_review = 'escrowed_payment_review',
Expand Down Expand Up @@ -293,7 +295,8 @@ export enum CustomEventNames {
transaction_error = 'transaction_error',
transaction_exception = 'transaction_exception',

// Fee errors
// Fee
fee_rendered = 'fee_rendered',
estimate_fee_failed = 'estimate_fee_failed',
fetch_tobin_tax_failed = 'fetch_tobin_tax_failed',

Expand Down Expand Up @@ -323,6 +326,8 @@ export type EventPropertyType = {
export enum PropertyPathWhitelist {
address = 'address',
component = 'component',
contacts = 'contacts',
contactsMatched = 'contactsMatched',
context = 'context',
countryCode = 'countryCode',
cta = 'cta',
Expand All @@ -335,6 +340,7 @@ export enum PropertyPathWhitelist {
error = 'error',
exchangeInputAmount = 'exchangeInputAmount',
exchangeRate = 'exchangeRate',
fee = 'fee',
feeType = 'feeType',
fullName = 'fullName',
gethOutcome = 'gethOutcome',
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/identity/contactMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function* doImportContacts(doMatchmaking: boolean) {
yield put(updateImportContactsProgress(ImportContactsStatus.Importing))

const contacts: MinimalContact[] = yield call(getAllContacts)
CeloAnalytics.track(CustomEventNames.fetched_contacts, { contacts: contacts.length })
if (!contacts || !contacts.length) {
Logger.warn(TAG, 'Empty contacts list. Skipping import.')
return true
Expand Down
8 changes: 7 additions & 1 deletion packages/mobile/src/identity/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dotProp from 'dot-prop-immutable'
import { RehydrateAction } from 'redux-persist'
import CeloAnalytics from 'src/analytics/CeloAnalytics'
import { CustomEventNames } from 'src/analytics/constants'
import { Actions, ActionTypes } from 'src/identity/actions'
import { ContactMatches, ImportContactsStatus, VerificationStatus } from 'src/identity/types'
import { AttestationCode } from 'src/identity/verification'
Expand Down Expand Up @@ -176,9 +178,13 @@ export const reducer = (
askedContactsPermission: true,
}
case Actions.ADD_CONTACT_MATCHES:
const matchedContacts = { ...state.matchedContacts, ...action.matches }
CeloAnalytics.track(CustomEventNames.add_contact_match, {
contactsMatched: Object.keys(matchedContacts).length,
})
return {
...state,
matchedContacts: { ...state.matchedContacts, ...action.matches },
matchedContacts,
}
case Actions.VALIDATE_RECIPIENT_ADDRESS:
return {
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/send/SendConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export class SendConfirmation extends React.Component<Props, State> {
// so we adjust it here
const securityFee = isInvite && fee ? fee.minus(inviteFee) : fee

CeloAnalytics.track(CustomEventNames.fee_rendered, { feeType: 'Security', fee: securityFee })
const totalAmount = {
value: amountWithFee,
currencyCode: CURRENCIES[CURRENCY_ENUM.DOLLAR].code,
Expand Down
9 changes: 8 additions & 1 deletion packages/mobile/src/tokens/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ export function tokenFetchFactory({ actionName, token, actionCreator, tag }: Tok
const tokenContract = yield call(getTokenContract, token)
const balanceInWei: BigNumber = yield call([tokenContract, tokenContract.balanceOf], account)
const balance: BigNumber = yield call(convertFromContractDecimals, balanceInWei, token)
CeloAnalytics.track(CustomEventNames.fetch_balance)
CeloAnalytics.track(
CustomEventNames.fetch_balance,
token === CURRENCY_ENUM.DOLLAR
? {
dollarBalance: balance,
}
: { goldBalance: balance }
)
yield put(actionCreator(balance.toString()))
} catch (error) {
Logger.error(tag, 'Error fetching balance', error)
Expand Down

0 comments on commit e74c778

Please sign in to comment.