Skip to content

Commit

Permalink
Update analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNikita committed Dec 30, 2023
1 parent c8e14b8 commit da9282f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonkeeper/desktop",
"version": "3.4.8",
"version": "3.4.9",
"description": "Your desktop wallet on The Open Network",
"main": ".webpack/main",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const Loader: FC = () => {
const navigate = useNavigate();
useAppHeight();

const { data: tracker } = useAnalytics(sdk.storage, account, activeWallet);
const { data: tracker } = useAnalytics(account, activeWallet);

useEffect(() => {
if (
Expand Down
13 changes: 4 additions & 9 deletions apps/desktop/src/libs/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useQuery } from '@tanstack/react-query';
import { IStorage } from '@tonkeeper/core/dist/Storage';
import { AccountState } from '@tonkeeper/core/dist/entries/account';
import { WalletState } from '@tonkeeper/core/dist/entries/wallet';
import { throttle } from '@tonkeeper/core/dist/utils/common';
Expand Down Expand Up @@ -45,22 +44,18 @@ export const useAppWidth = () => {

declare const REACT_APP_MEASUREMENT_ID: string;

export const useAnalytics = (
storage: IStorage,
account?: AccountState,
wallet?: WalletState | null
) => {
export const useAnalytics = (account?: AccountState, wallet?: WalletState | null) => {
return useQuery<Analytics>(
[QueryKey.analytics],
async () => {
const tracker = new Gtag(REACT_APP_MEASUREMENT_ID);
const version = `Desktop-${window.backgroundApi.platform()}-${window.backgroundApi.arch()}`;
tracker.init(
version,
'Desktop',
toWalletType(wallet),
account,
wallet,
window.backgroundApi.version()
window.backgroundApi.version(),
`${window.backgroundApi.platform()}-${window.backgroundApi.arch()}`
);

return tracker;
Expand Down
4 changes: 3 additions & 1 deletion packages/uikit/src/hooks/analytics/amplitude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class Amplitude implements Analytics {
walletType: string,
account?: AccountState,
wallet?: WalletState | null,
version?: string
version?: string,
platform?: string
) {
amplitude.init(this.key, undefined, {
defaultTracking: {
Expand All @@ -29,6 +30,7 @@ export class Amplitude implements Analytics {
event.set('network', wallet?.network === Network.TESTNET ? 'testnet' : 'mainnet');
event.set('accounts', account!.publicKeys.length);
event.set('version', version ?? 'Unknown');
event.set('platform', platform ?? 'Unknown');

amplitude.identify(event);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/uikit/src/hooks/analytics/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class GoogleAnalytics4 implements Analytics {
walletType: string,
account?: AccountState,
wallet?: WalletState | null,
version?: string
version?: string,
platform?: string
) {
this.user_properties['application'] = { value: application };
this.user_properties['walletType'] = { value: walletType };
Expand All @@ -44,6 +45,7 @@ export class GoogleAnalytics4 implements Analytics {
};
this.user_properties['accounts'] = { value: account!.publicKeys.length };
this.user_properties['version'] = { value: version };
this.user_properties['platform'] = { value: platform };
}

pageView(location: string) {
Expand Down
6 changes: 4 additions & 2 deletions packages/uikit/src/hooks/analytics/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ export class Gtag implements Analytics {
walletType: string,
account?: AccountState,
wallet?: WalletState | null,
version?: string
version?: string,
platform?: string
) {
ReactGA.gtag('set', 'user_properties', {
application,
walletType,
network: wallet?.network === Network.TESTNET ? 'testnet' : 'mainnet',
accounts: account!.publicKeys.length,
version
version,
platform
});
}

Expand Down
10 changes: 7 additions & 3 deletions packages/uikit/src/hooks/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export interface Analytics {
walletType: string,
account?: AccountState,
wallet?: WalletState | null,
version?: string
version?: string,
platform?: string
) => void;
track: (name: string, params: Record<string, any>) => Promise<void>;
}
Expand All @@ -29,9 +30,12 @@ export class AnalyticsGroup implements Analytics {
walletType: string,
account?: AccountState,
wallet?: WalletState | null,
version?: string
version?: string,
platform?: string
) {
this.analytics.forEach(c => c.init(application, walletType, account, wallet, version));
this.analytics.forEach(c =>
c.init(application, walletType, account, wallet, version, platform)
);
}

async track(name: string, params: Record<string, any>) {
Expand Down

0 comments on commit da9282f

Please sign in to comment.