Skip to content

Commit

Permalink
analytics: wallet types (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSinclair authored Aug 18, 2023
1 parent 22d9d66 commit bb5b697
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
67 changes: 67 additions & 0 deletions src/analytics/identify/walletTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { KeychainType } from '~/core/types/keychainTypes';
import { getStatus, getWallets } from '~/entries/popup/handlers/wallet';

import { analytics } from '..';

export const identifyWalletTypes = async () => {
const { unlocked, ready } = await getStatus();
if (!unlocked || !ready) return;

const wallets = await getWallets();

const ownedAccounts = wallets
.filter(
(a) =>
a.type === KeychainType.HdKeychain ||
a.type === KeychainType.KeyPairKeychain,
)
.reduce((count, wallet) => count + wallet.accounts.length, 0);

const watchedAccounts = wallets
.filter((a) => a.type === KeychainType.ReadOnlyKeychain)
.reduce((count, wallet) => count + wallet.accounts.length, 0);

const recoveryPhrases = wallets.filter(
(a) => a.type === KeychainType.HdKeychain,
).length;

const importedRecoveryPhrases = wallets.filter(
(a) => a.type === KeychainType.HdKeychain && !a.imported,
).length;

const privateKeys = wallets.filter(
(a) => a.type === KeychainType.KeyPairKeychain,
).length;

const importedPrivateKeys = wallets.filter(
(a) => a.type === KeychainType.KeyPairKeychain && !a.imported,
).length;

const hasImported = importedPrivateKeys > 0 || importedRecoveryPhrases > 0;

const hardwareWallets = wallets.filter(
(a) => a.type === KeychainType.HardwareWalletKeychain,
);

const hardwareAccounts = hardwareWallets.reduce(
(count, wallet) => count + wallet.accounts.length,
0,
);

const ledgerDevices = wallets.filter((a) => a.vendor === 'Ledger').length;

const trezorDevices = wallets.filter((a) => a.vendor === 'Trezor').length;

analytics.identify({
ownedAccounts,
hardwareAccounts,
watchedAccounts,
recoveryPhrases,
importedRecoveryPhrases,
privateKeys,
importedPrivateKeys,
ledgerDevices,
trezorDevices,
hasImported,
});
};
16 changes: 13 additions & 3 deletions src/analytics/userProperties.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
// these are all reported seperately so they must be optional
export interface UserProperties {}
// these can be reported separately so they must be optional
export interface UserProperties {
ownedAccounts?: number;
hardwareAccounts?: number;
watchedAccounts?: number;
recoveryPhrases?: number;
importedRecoveryPhrases?: number;
privateKeys?: number;
importedPrivateKeys?: number;
trezorDevices?: number;
ledgerDevices?: number;
hasImported?: boolean;
}
2 changes: 2 additions & 0 deletions src/entries/popup/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useAccount } from 'wagmi';

import { analytics } from '~/analytics';
import { event } from '~/analytics/event';
import { identifyWalletTypes } from '~/analytics/identify/walletTypes';
import { shortcuts } from '~/core/references/shortcuts';
import { useCurrentAddressStore } from '~/core/state';
import { usePendingRequestStore } from '~/core/state/requests';
Expand Down Expand Up @@ -142,6 +143,7 @@ export function Home() {

useEffect(() => {
analytics.track(event.walletViewed);
identifyWalletTypes();
removeImportWalletSecrets();
}, []);

Expand Down

0 comments on commit bb5b697

Please sign in to comment.