Skip to content

Commit

Permalink
feat: add connect wallet analytics event
Browse files Browse the repository at this point in the history
  • Loading branch information
nounspaceryan committed Jul 4, 2024
1 parent ff046b6 commit 86dd6ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/providers/AnalyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useCurrentSpaceIdentityPublicKey } from "@/common/lib/hooks/useCurrentS
import { useCurrentFid } from "@/common/lib/hooks/useCurrentFid";

export enum AnalyticsEvent {
CONNECT_WALLET = "Connect Wallet",
SIGN_UP = "Sign Up",
LINK_FID = "Link FID",
SAVE_SPACE_THEME = "Save Space Theme",
Expand All @@ -16,6 +17,7 @@ export enum AnalyticsEvent {
}

type AnalyticsEventProperties = {
[AnalyticsEvent.CONNECT_WALLET]: Record<string, never>;
[AnalyticsEvent.SIGN_UP]: Record<string, never>;
[AnalyticsEvent.LINK_FID]: { fid: number };
[AnalyticsEvent.SAVE_SPACE_THEME]: Record<string, never>;
Expand Down
16 changes: 16 additions & 0 deletions src/common/providers/LoggedInStateProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { ALCHEMY_API } from "@/constants/urls";
import { AlchemyIsHolderOfContract } from "@/pages/api/signerRequests";
import axios from "axios";
import { NOGS_CONTRACT_ADDR } from "@/constants/nogs";
import usePrevious from "@/common/lib/hooks/usePrevious";
import {
analytics,
AnalyticsEvent,
} from "@/common/providers/AnalyticsProvider";

type LoggedInLayoutProps = { children: React.ReactNode };

Expand Down Expand Up @@ -91,6 +96,7 @@ const LoggedInStateProvider: React.FC<LoggedInLayoutProps> = ({ children }) => {
const { signMessage, ready: walletsReady } = useSignMessage();
const authenticatorManager = useAuthenticatorManager();
const logout = useLogout();
const previousStep = usePrevious(currentStep);

async function loadWallet() {
if (walletsReady && ready && authenticated && user) {
Expand All @@ -106,6 +112,16 @@ const LoggedInStateProvider: React.FC<LoggedInLayoutProps> = ({ children }) => {
}
}

useEffect(() => {
// need to check previous step, otherwise this gets called twice
if (
previousStep == SetupStep.NOT_SIGNED_IN &&
currentStep === SetupStep.SIGNED_IN
) {
analytics.track(AnalyticsEvent.CONNECT_WALLET);
}
}, [previousStep, currentStep]);

async function loadIdentity() {
if (walletsReady && ready && authenticated && user) {
if (isUndefined(getCurrentIdentity())) {
Expand Down

0 comments on commit 86dd6ba

Please sign in to comment.