Skip to content

Commit

Permalink
Merge branch 'feat/ga4' into tmp/20250117
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed Jan 21, 2025
2 parents 90612e9 + 30cc40c commit 435e242
Show file tree
Hide file tree
Showing 25 changed files with 292 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ import Browser from 'webextension-polyfill';
import { hashSafeMessage } from '@safe-global/protocol-kit';
import { userGuideService } from '../service/userGuide';
import { metamaskModeService } from '../service/metamaskModeService';
import { ga4 } from '@/utils/ga4';

const stashKeyrings: Record<string | number, any> = {};

Expand Down Expand Up @@ -4898,6 +4899,10 @@ export class WalletController extends BaseController {
action: 'Success Add Network',
label: `${source}_${String(chain.id)}`,
});

ga4.fireEvent('Add_CustomNetwork', {
event_category: 'Custom Network',
});
}
return res;
};
Expand Down
27 changes: 26 additions & 1 deletion src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import { isSameAddress } from './utils';
import rpcCache from './utils/rpcCache';
import { storage } from './webapi';
import { metamaskModeService } from './service/metamaskModeService';
import { ga4 } from '@/utils/ga4';
import { ALARMS_USER_ENABLE } from './utils/alarms';

Safe.adapter = fetchAdapter as any;

Expand Down Expand Up @@ -116,9 +118,14 @@ async function restoreAppState() {
syncChainService.roll();
transactionWatchService.roll();
transactionBroadcastWatchService.roll();
startEnableUser();
walletController.syncMainnetChainList();

// check if user has enabled the extension
chrome.alarms.create(ALARMS_USER_ENABLE, {
when: Date.now(),
periodInMinutes: 60,
});

if (!keyringService.isBooted()) {
userGuideService.init();
}
Expand Down Expand Up @@ -171,6 +178,10 @@ restoreAppState();
action: 'Custom Network Status',
value: customTestnetLength,
});

ga4.fireEvent('Has Custom Network', {
event_category: 'Custom Network',
});
}
const chains = preferenceService.getSavedChains();
matomoRequestEvent({
Expand Down Expand Up @@ -201,6 +212,10 @@ restoreAppState();
label: [group[0].action, group[0].label, group.length].join('|'),
value: group.length,
});

ga4.fireEvent(`${group[0].category}_${group[0].label}`, {
event_category: 'UserAddress',
});
});
preferenceService.updateSendLogTime(Date.now());
};
Expand Down Expand Up @@ -422,6 +437,10 @@ function startEnableUser() {
category: 'User',
action: 'enable',
});

ga4.fireEvent('User_Enable', {
event_category: 'User Enable',
});
preferenceService.updateSendEnableTime(Date.now());
}

Expand All @@ -434,3 +453,9 @@ async function onInstall() {
await userGuideService.openUserGuide();
}
}

browser.alarms.onAlarm.addListener((alarm) => {
if (alarm.name === ALARMS_USER_ENABLE) {
startEnableUser();
}
});
9 changes: 9 additions & 0 deletions src/background/service/customTestnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { http as axios } from '../utils/http';
import { matomoRequestEvent } from '@/utils/matomo-request';
import RPCService, { RPCServiceStore } from './rpc';
import { storage } from '../webapi';
import { ga4 } from '@/utils/ga4';

const MAX_READ_CONTRACT_TIME = 8000;

Expand Down Expand Up @@ -194,6 +195,10 @@ class CustomTestnetService {
action: 'Custom Network Status',
value: this.getList().length,
});

ga4.fireEvent('Has_CustomNetwork', {
event_category: 'Custom Network',
});
}
return this.store.customTestnet[chain.id];
};
Expand All @@ -211,6 +216,10 @@ class CustomTestnetService {
action: 'Custom Network Status',
value: this.getList().length,
});

ga4.fireEvent('Has_CustomNetwork', {
event_category: 'Custom Network',
});
}
};

Expand Down
1 change: 1 addition & 0 deletions src/background/utils/alarms.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const ALARMS_SYNC_CHAINS = 'ALARMS_SYNC_CHAINS';
export const ALARMS_SYNC_METAMASK_DAPPS = 'ALARMS_SYNC_METAMASK_DAPPS';
export const ALARMS_USER_ENABLE = 'ALARMS_USER_ENABLE';
12 changes: 12 additions & 0 deletions src/ui/utils/sendPersonalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { WalletControllerType } from '@/ui/utils';
import { getKRCategoryByType } from '@/utils/transaction';
import eventBus from '@/eventBus';
import { matomoRequestEvent } from '@/utils/matomo-request';
import { ga4 } from '@/utils/ga4';

// fail code
export enum FailedCode {
Expand Down Expand Up @@ -37,6 +38,17 @@ const report = async ({
].join('|'),
transport: 'beacon',
});

if (action === 'createSignText') {
ga4.fireEvent('Init_SignText', {
event_category: 'SignText',
});
} else if (action === 'startSignText') {
ga4.fireEvent('Submit_SignText', {
event_category: 'SignText',
});
}

await wallet.reportStats(action, {
type: currentAccount.brandName,
category: getKRCategoryByType(currentAccount.type),
Expand Down
9 changes: 9 additions & 0 deletions src/ui/views/Approval/components/CoinbaseWaiting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useSessionStatus } from '@/ui/component/WalletConnect/useSessionStatus'
import { adjustV } from '@/ui/utils/gnosis';
import { findChain, findChainByEnum } from '@/utils/chain';
import { emitSignComponentAmounted } from '@/utils/signEvent';
import { ga4 } from '@/utils/ga4';

interface ApprovalParams {
address: string;
Expand Down Expand Up @@ -175,6 +176,14 @@ const CoinbaseWaiting = ({ params }: { params: ApprovalParams }) => {
action: 'Submit',
label: chainInfo?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(
`Submit_${chainInfo?.isTestnet ? 'Custom' : 'Integrated'}`,
{
event_category: 'Transaction',
}
);

isSignTriggered = true;
}
if (isText && !isSignTriggered) {
Expand Down
6 changes: 6 additions & 0 deletions src/ui/views/Approval/components/CommonWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { adjustV } from '@/ui/utils/gnosis';
import { message } from 'antd';
import { findChain } from '@/utils/chain';
import { emitSignComponentAmounted } from '@/utils/signEvent';
import { ga4 } from '@/utils/ga4';

interface ApprovalParams {
address: string;
Expand Down Expand Up @@ -191,6 +192,11 @@ export const CommonWaiting = ({ params }: { params: ApprovalParams }) => {
action: 'Submit',
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Submit_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

setSignFinishedData({
data: sig,
approvalId: approval.id,
Expand Down
5 changes: 5 additions & 0 deletions src/ui/views/Approval/components/ImKeyHardwareWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useImKeyStatus } from '@/ui/component/ConnectStatus/useImKeyStatus';
import * as Sentry from '@sentry/browser';
import { findChain } from '@/utils/chain';
import { emitSignComponentAmounted } from '@/utils/signEvent';
import { ga4 } from '@/utils/ga4';

interface ApprovalParams {
address: string;
Expand Down Expand Up @@ -208,6 +209,10 @@ export const ImKeyHardwareWaiting = ({
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Submit_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

setSignFinishedData({
data: sig,
approvalId: approval.id,
Expand Down
5 changes: 5 additions & 0 deletions src/ui/views/Approval/components/LedgerHardwareWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Props as ApprovalPopupContainerProps,
} from './Popup/ApprovalPopupContainer';
import { isLedgerLockError } from '@/ui/utils/ledger';
import { ga4 } from '@/utils/ga4';

interface ApprovalParams {
address: string;
Expand Down Expand Up @@ -198,6 +199,10 @@ const LedgerHardwareWaiting = ({ params }: { params: ApprovalParams }) => {
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Submit_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

setSignFinishedData({
data: sig,
approvalId: approval.id,
Expand Down
6 changes: 6 additions & 0 deletions src/ui/views/Approval/components/PrivatekeyWaiting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { id } from 'ethers/lib/utils';
import { findChain } from '@/utils/chain';
import { emitSignComponentAmounted } from '@/utils/signEvent';
import { SafeClientTxStatus } from '@safe-global/sdk-starter-kit/dist/src/constants';
import { ga4 } from '@/utils/ga4';

interface ApprovalParams {
address: string;
Expand Down Expand Up @@ -204,6 +205,11 @@ export const PrivatekeyWaiting = ({ params }: { params: ApprovalParams }) => {
action: 'Submit',
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Submit_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

setSignFinishedData({
data: sig,
approvalId: approval.id,
Expand Down
11 changes: 11 additions & 0 deletions src/ui/views/Approval/components/SignTestnetTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SignAdvancedSettings } from '../SignAdvancedSettings';
import clsx from 'clsx';
import { useGasAccountSign } from '@/ui/views/GasAccount/hooks';
import { Modal } from 'antd';
import { ga4 } from '@/utils/ga4';

const checkGasAndNonce = ({
recommendGasLimitRatio,
Expand Down Expand Up @@ -385,6 +386,11 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => {
action: 'init',
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Init_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

if (currentAccount.type === KEYRING_TYPE.GnosisKeyring) {
setIsGnosisAccount(true);
}
Expand Down Expand Up @@ -677,6 +683,11 @@ export const SignTestnetTx = ({ params, origin }: SignTxProps) => {
action: 'Submit',
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Submit_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

resolveApproval({
...transaction,
nonce: realNonce || tx.nonce,
Expand Down
12 changes: 12 additions & 0 deletions src/ui/views/Approval/components/SignText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { generateTypedData } from '@safe-global/protocol-kit';
import { useGetCurrentSafeInfo } from '../hooks/useGetCurrentSafeInfo';
import { useGetMessageHash } from '../hooks/useGetCurrentMessageHash';
import { useCheckCurrentSafeMessage } from '../hooks/useCheckCurrentSafeMessage';
import { ga4 } from '@/utils/ga4';

interface SignTextProps {
data: string[];
Expand Down Expand Up @@ -195,6 +196,17 @@ const SignText = ({ params }: { params: SignTextProps }) => {
].join('|'),
transport: 'beacon',
});

if (action === 'createSignText') {
ga4.fireEvent('Init_SignText', {
event_category: 'SignText',
});
} else if (action === 'startSignText') {
ga4.fireEvent('Submit_SignText', {
event_category: 'SignText',
});
}

await wallet.reportStats(action, {
type: currentAccount.brandName,
category: getKRCategoryByType(currentAccount.type),
Expand Down
10 changes: 10 additions & 0 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import {
ActionRequireData,
ParsedTransactionActionData,
} from '@rabby-wallet/rabby-action';
import { ga4 } from '@/utils/ga4';

interface BasicCoboArgusInfo {
address: string;
Expand Down Expand Up @@ -1217,6 +1218,11 @@ const SignTx = ({ params, origin }: SignTxProps) => {
action: 'Submit',
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Submit_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

resolveApproval({
...transaction,
nonce: realNonce || tx.nonce,
Expand Down Expand Up @@ -1606,6 +1612,10 @@ const SignTx = ({ params, origin }: SignTxProps) => {
label: chain?.isTestnet ? 'Custom Network' : 'Integrated Network',
});

ga4.fireEvent(`Init_${chain?.isTestnet ? 'Custom' : 'Integrated'}`, {
event_category: 'Transaction',
});

if (currentAccount.type === KEYRING_TYPE.GnosisKeyring) {
setIsGnosisAccount(true);
await getSafeInfo();
Expand Down
12 changes: 12 additions & 0 deletions src/ui/views/Approval/components/SignTypedData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import { useGetMessageHash } from '../hooks/useGetCurrentMessageHash';
import { useCheckCurrentSafeMessage } from '../hooks/useCheckCurrentSafeMessage';
import GnosisDrawer from './TxComponents/GnosisDrawer';
import { generateTypedData } from '@safe-global/protocol-kit';
import { ga4 } from '@/utils/ga4';

interface SignTypedDataProps {
method: string;
Expand Down Expand Up @@ -340,6 +341,17 @@ const SignTypedData = ({ params }: { params: SignTypedDataProps }) => {
].join('|'),
transport: 'beacon',
});

if (action === 'createSignText') {
ga4.fireEvent('Init_SignText', {
event_category: 'SignText',
});
} else if (action === 'startSignText') {
ga4.fireEvent('Submit_SignText', {
event_category: 'SignText',
});
}

await wallet.reportStats(action, {
type: currentAccount.brandName,
category: getKRCategoryByType(currentAccount.type),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useSessionStatus } from '@/ui/component/WalletConnect/useSessionStatus'
import { adjustV } from '@/ui/utils/gnosis';
import { findChain, findChainByEnum } from '@/utils/chain';
import { emitSignComponentAmounted } from '@/utils/signEvent';
import { ga4 } from '@/utils/ga4';

interface ApprovalParams {
address: string;
Expand Down Expand Up @@ -255,6 +256,14 @@ const WatchAddressWaiting = ({ params }: { params: ApprovalParams }) => {
? 'Custom Network'
: 'Integrated Network',
});

ga4.fireEvent(
`Submit_${chainInfo?.isTestnet ? 'Custom' : 'Integrated'}`,
{
event_category: 'Transaction',
}
);

isSignTriggered = true;
}
if (isText && !isSignTriggered) {
Expand Down
Loading

0 comments on commit 435e242

Please sign in to comment.