Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): lease conversion events #817

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import { wallets as leap } from "@cosmos-kit/leap";
import { ChainProvider, DefaultModal } from "@cosmos-kit/react";
import { useChain } from "@cosmos-kit/react";
import { useAtom } from "jotai";
import { event } from "nextjs-google-analytics";

import { akash, akashSandbox, akashTestnet, assetLists } from "@src/chains";
import networkStore from "@src/store/networkStore";
import walletStore from "@src/store/walletStore";
import { AnalyticsCategory } from "@src/types/analytics";
import { AnalyticsEvents } from "@src/types/analytics";
import { customRegistry } from "@src/utils/customRegistry";

type Props = {
Expand Down Expand Up @@ -78,6 +81,11 @@ const ModalWrapper = (props: WalletModalProps) => {

if (isWalletModalOpen && !props.isOpen && isWalletConnected) {
setSelectedWalletType("custodial");

event(AnalyticsEvents.CONNECT_WALLET, {
category: AnalyticsCategory.WALLET,
label: "Connect wallet"
});
}
}, [isWalletModalOpen, props.isOpen, isWalletConnected]);

Expand Down
21 changes: 7 additions & 14 deletions apps/deploy-web/src/context/WalletProvider/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ type ContextType = {
walletName: string;
isWalletConnected: boolean;
isWalletLoaded: boolean;
connectWallet: () => Promise<void>;
connectManagedWallet: () => void;
logout: () => void;
signAndBroadcastTx: (msgs: EncodeObject[]) => Promise<any>;
Expand Down Expand Up @@ -120,6 +119,13 @@ export const WalletProvider = ({ children }) => {
});
}

if (selectedWalletType === "managed" && userWallet.isWalletConnected) {
event(AnalyticsEvents.CONNECT_WALLET, {
category: AnalyticsCategory.WALLET,
label: "Connect wallet"
});
}

setSelectedWalletType(prev => (prev === "custodial" ? "managed" : "custodial"));
}

Expand All @@ -145,18 +151,6 @@ export const WalletProvider = ({ children }) => {
}
}

async function connectWallet() {
console.log("Connecting wallet with CosmosKit...");
await userWallet.connect();

await loadWallet();

event(AnalyticsEvents.CONNECT_WALLET, {
category: AnalyticsCategory.WALLET,
label: "Connect wallet"
});
}

async function loadWallet(): Promise<void> {
const networkId =
isManaged && selectedNetworkId !== browserEnvConfig.NEXT_PUBLIC_MANAGED_WALLET_NETWORK_ID
Expand Down Expand Up @@ -309,7 +303,6 @@ export const WalletProvider = ({ children }) => {
walletName: username as string,
isWalletConnected: isWalletConnected,
isWalletLoaded: isWalletLoaded,
connectWallet,
connectManagedWallet,
logout,
signAndBroadcastTx,
Expand Down
9 changes: 9 additions & 0 deletions apps/deploy-web/src/hooks/useManagedWallet.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { useEffect, useMemo } from "react";
import { useAtom } from "jotai";
import { event } from "nextjs-google-analytics";

import { browserEnvConfig } from "@src/config/browser-env.config";
import { useSelectedChain } from "@src/context/CustomChainProvider";
import { useUser } from "@src/hooks/useUser";
import { useCreateManagedWalletMutation, useManagedWalletQuery } from "@src/queries/useManagedWalletQuery";
import walletStore from "@src/store/walletStore";
import { AnalyticsEvents } from "@src/types/analytics";
import { AnalyticsCategory } from "@src/types/analytics";
import { deleteManagedWalletFromStorage, ensureUserManagedWalletOwnership, getSelectedStorageWallet, updateStorageManagedWallet } from "@src/utils/walletUtils";
import { useCustomUser } from "./useCustomUser";

Expand All @@ -27,11 +30,17 @@ export const useManagedWallet = () => {
if (selectedWalletType === "custodial" && wallet && !userWallet.isWalletConnected && !userWallet.isWalletConnecting) {
setSelectedWalletType("managed");
}

event(AnalyticsEvents.CONNECT_MANAGED_WALLET, {
category: AnalyticsCategory.WALLET,
label: "Connect managed wallet"
});
}
});
const { mutate: create, data: created, isLoading: isCreating, isSuccess: isCreated } = useCreateManagedWalletMutation();
const wallet = useMemo(() => queried || created, [queried, created]);
const isLoading = isFetching || isCreating;

const [, setIsSignedInWithTrial] = useAtom(walletStore.isSignedInWithTrial);
const selected = getSelectedStorageWallet();

Expand Down
1 change: 1 addition & 0 deletions apps/deploy-web/src/types/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum AnalyticsEvents {
CONNECT_WALLET = "connect_wallet",
CONNECT_MANAGED_WALLET = "connect_managed_wallet",
DISCONNECT_WALLET = "disconnect_wallet",
SUCCESSFUL_TX = "successful_transaction",
FAILED_TX = "failed_tx",
Expand Down