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 10, 2024
1 parent a1fee5d commit b06af92
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,
},
});
};

1 comment on commit b06af92

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.6% (1765/2111) 78.81% (837/1062) 78.14% (447/572)
apps/web Coverage: 83%
83.6% (1765/2111) 78.81% (837/1062) 78.14% (447/572)
packages/components Coverage: 97%
97.28% (179/184) 95.23% (80/84) 86.53% (45/52)
packages/core Coverage: 81%
82.22% (222/270) 71.73% (99/138) 81.96% (50/61)
packages/crypto Coverage: 100%
100% (28/28) 100% (3/3) 100% (5/5)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (35/35)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.61% (792/936) 80.97% (166/205) 78.72% (296/376)
packages/tezos Coverage: 86%
85.57% (89/104) 89.47% (17/19) 82.75% (24/29)
packages/tzkt Coverage: 86%
84.05% (58/69) 81.25% (13/16) 76.92% (30/39)

Please sign in to comment.