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: add connect wallet analytics event #231

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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