Skip to content

Commit

Permalink
[web] Add GA tracking for some onboarding actions
Browse files Browse the repository at this point in the history
  • Loading branch information
asiia-trilitech committed Oct 9, 2024
1 parent 9384c4b commit 4b7f574
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 6 deletions.
7 changes: 6 additions & 1 deletion apps/web/src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Flex, Link, Text } from "@chakra-ui/react";

import { useColor } from "../../styles/useColor";
import { trackButtonClick } from "../../utils/analytics";

export const Footer = () => {
const color = useColor();
Expand Down Expand Up @@ -29,7 +30,11 @@ export const Footer = () => {
>
Terms
</Link>
<Link href="https://umamiwallet.com/privacypolicy.html" isExternal>
<Link
href="https://umamiwallet.com/privacypolicy.html"
isExternal
onClick={() => trackButtonClick("onboarding", "open_terms_of_use")}
>
Privacy
</Link>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { FormProvider } from "react-hook-form";

import { CheckmarkIcon, CloseIcon, FileUploadIcon } from "../../../assets/icons";
import { useColor } from "../../../styles/useColor";
import { trackSuccessfulConnection } from "../../../utils/analytics";
import { persistor } from "../../../utils/persistor";
import { PasswordInput } from "../../PasswordInput";

Expand Down Expand Up @@ -42,6 +43,7 @@ export const ImportBackupTab = () => {
}
const backup = JSON.parse(await file[0].text());
await restoreBackup(backup, password, persistor);
trackSuccessfulConnection("onboarding", "restore_from_backup");
});

const { ref, ...inputRegisterProps } = register("file", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OnboardWithGoogleButton } from "./OnboardWithGoogleButton";
import { OnboardWithRedditButton } from "./OnboardWithRedditButton";
import { OnboardWithTwitterButton } from "./OnboardWithTwitterButton";
import { useColor } from "../../../styles/useColor";
import { trackButtonClick } from "../../../utils/analytics";
import { AccountTileWrapper } from "../../AccountTile";
import { NameAccountModal } from "../../NameAccountModal";
import { ImportWallet } from "../ImportWallet";
Expand Down Expand Up @@ -68,17 +69,26 @@ export const OnboardOptions = ({ children }: PropsWithChildren) => {
</Center>

<Flex flexDirection="column" gap="12px" width="full">
<Button width="full" onClick={handleCreateNewWallet} size="lg" variant="primary">
<Button
width="full"
onClick={() => {
trackButtonClick("onboarding", "create_new_wallet");
return handleCreateNewWallet();
}}
size="lg"
variant="primary"
>
Create a new wallet
</Button>
<Button
width="full"
onClick={() =>
openWith(<ImportWallet />, {
onClick={() => {
trackButtonClick("onboarding", "use_existing_wallet");
return openWith(<ImportWallet />, {
size: "xl",
variant: "onboarding",
})
}
});
}}
size="lg"
variant="secondary"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { getPublicKeyPairFromSk } from "@umami/tezos";
import { minutesToMilliseconds } from "date-fns";
import { useCallback } from "react";

import {
trackSocialLoginButtonClick,
trackSuccessfulSocialConnection,
} from "../../../utils/analytics";

const LOGIN_TIMEOUT = minutesToMilliseconds(1);

/**
Expand All @@ -24,12 +29,14 @@ export const useOnboardWithSocial = (idp: Auth.IDP, onAuth?: () => void) => {
() =>
handleAsyncAction(
async () => {
trackSocialLoginButtonClick("onboarding", idp);
const { secretKey, name, id, email } = await withTimeout(
() => Auth.forIDP(idp).getCredentials(),
LOGIN_TIMEOUT
);
const { pk, pkh } = await getPublicKeyPairFromSk(secretKey);
restoreSocial(pk, pkh, email || name || id, idp);
trackSuccessfulSocialConnection("onboarding", idp);
toast({ description: `Successfully added ${name || id} account`, status: "success" });
onAuth?.();
},
Expand Down
60 changes: 60 additions & 0 deletions apps/web/src/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type * as Auth from "@umami/social-auth";

interface EventProps {
eventName: GAEvent;
params: Record<string, string | number | undefined>;
}

enum GAEvent {
BUTTON_CLICK = "button_click",
CONNECT_SUCCESS = "connect_success",
}

const trackGAEvent = ({ eventName, params }: EventProps) => {
(window as any).gtag("event", eventName, {
...params,
surface: "web",
});
};

export const trackSocialLoginButtonClick = (section: string, idp: Auth.IDP) => {
trackGAEvent({
eventName: GAEvent.BUTTON_CLICK,
params: {
section,
action: "social_login",
idp,
},
});
};

export const trackButtonClick = (section: string, action: string) => {
trackGAEvent({
eventName: GAEvent.BUTTON_CLICK,
params: {
section,
action,
},
});
};

export const trackSuccessfulConnection = (section: string, connectionType: string) => {
trackGAEvent({
eventName: GAEvent.CONNECT_SUCCESS,
params: {
section,
connectionType,
},
});
};

export const trackSuccessfulSocialConnection = (section: string, idp: Auth.IDP) => {
trackGAEvent({
eventName: GAEvent.CONNECT_SUCCESS,
params: {
section,
connectionType: "social",
idp,
},
});
};

0 comments on commit 4b7f574

Please sign in to comment.