Skip to content

Commit

Permalink
Merge pull request #63 from Nexters/feat/gtm
Browse files Browse the repository at this point in the history
feat: add events for button clicks
  • Loading branch information
eric-jy-park authored Apr 21, 2024
2 parents 2df4451 + 1d1bde0 commit 28d5e56
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
11 changes: 10 additions & 1 deletion src/app/(input)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,29 @@ import Link from "next/link";
import React from "react";
import Logo from "@/components/common/logo/logo";
import { useStocksStore } from "@/state/stores/stocks-store";
import { sendGAEvent } from "@next/third-parties/google";

export const viewport: Viewport = {
themeColor: "var(--color-white)",
};

const InputLayout = ({ children }: { children: React.ReactNode }) => {
const { removeAllStocks } = useStocksStore();

const onResetClick = React.useCallback(() => {
removeAllStocks();
sendGAEvent({
event: "Reset Button Click",
});
}, [removeAllStocks]);

return (
<div className="flex size-full flex-col">
<div className="sticky top-0 z-10 flex h-11 w-full shrink-0 items-center justify-between bg-white px-5">
<Link href="/">
<Logo />
</Link>
<div onClick={removeAllStocks} className="cursor-pointer text-body3 text-grey-900">
<div onClick={onResetClick} className="cursor-pointer text-body3 text-grey-900">
Reset
</div>
</div>
Expand Down
15 changes: 9 additions & 6 deletions src/app/(input)/ticker/_components/intro.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Button } from "@/components/ui/button";
import { useDrawerStore } from "@/state/stores/drawer-store";
import { useStocksStore } from "@/state/stores/stocks-store";
import { sendGAEvent } from "@next/third-parties/google";
import { Plus } from "lucide-react";
import React from "react";

Expand All @@ -9,18 +10,20 @@ const Intro = () => {
const { stocks } = useStocksStore();
const hasStock = stocks.length > 0;

const onAddStockClick = React.useCallback(() => {
isDrawerOpenChange(true);
sendGAEvent({
event: "Add Stock Button Click",
});
}, [isDrawerOpenChange]);

return (
<>
<h2 className="px-4 pt-4 text-h2">
You added <span className="text-main-700">{stocks.length}</span> {`${stocks.length > 1 ? "stocks" : "stock"}`}.
</h2>
<div className="sticky top-4 flex flex-col justify-start bg-white px-4 pb-4 pt-10 text-lg">
<Button
onClick={() => {
isDrawerOpenChange(true);
}}
className="flex w-full items-center justify-start gap-4 pl-0"
>
<Button onClick={onAddStockClick} className="flex w-full items-center justify-start gap-4 pl-0">
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-grey-100 text-grey-500">
<Plus />
</div>
Expand Down
8 changes: 6 additions & 2 deletions src/app/(input)/ticker/_components/ticker-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"use client";
import { Button } from "@/components/ui/button";
import { useStocksStore } from "@/state/stores/stocks-store";
import { sendGAEvent } from "@next/third-parties/google";
import { useRouter } from "next/navigation";
import React from "react";

export default function TickerFooter() {
const { stocks } = useStocksStore();
const router = useRouter();

const handleTickerSubmit = () => {
const handleTickerSubmit = React.useCallback(() => {
sendGAEvent({
event: "Analyzie My Portfolio Button Click",
});
router.push(`/report`);
};
}, [router]);

if (stocks.length === 0) return null;

Expand Down
10 changes: 1 addition & 9 deletions src/app/(landing)/_components/floating-footer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";

import { Button } from "@/components/common/button/button";
import { event } from "@/utils/gtag";
import { sendGAEvent } from "@next/third-parties/google";
import { useRouter } from "next/navigation";
import React from "react";
Expand All @@ -11,15 +10,8 @@ const FloatingFooter = React.memo(() => {

const onButtonClick = React.useCallback(() => {
router.push("/ticker");
event({
action: "buttonClicked",
category: "landing page",
label: "",
value: "",
});
sendGAEvent({
event: "buttonClicked",
value: "Landing Page",
event: "Landing Page Button Click",
});
}, [router]);

Expand Down
3 changes: 2 additions & 1 deletion src/app/global-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { hotjar } from "react-hotjar";
import axios, { AxiosError, AxiosResponse } from "axios";
import React from "react";
import { useViewEvent } from "@/hooks/use-view-event";

export const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -32,6 +33,7 @@ const HJSV = 6;

export const GlobalProvider = ({ children }: { children: React.ReactNode }) => {
const [client] = React.useState(() => new QueryClient());
useViewEvent();

React.useEffect(() => {
if (process.env.NODE_ENV !== "development") {
Expand All @@ -45,7 +47,6 @@ export const GlobalProvider = ({ children }: { children: React.ReactNode }) => {
return (
<QueryClientProvider client={client}>
{children}
{/* <GAProvider /> */}
<GoogleAnalytics gaId="G-K20DRKXNTC" />
<ReactQueryDevtools />
</QueryClientProvider>
Expand Down
13 changes: 13 additions & 0 deletions src/hooks/use-view-event.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sendGAEvent } from "@next/third-parties/google";
import { usePathname } from "next/navigation";
import React from "react";

export const useViewEvent = () => {
const pathname = usePathname();

React.useEffect(() => {
sendGAEvent({
event: `${pathname} Viewed`,
});
}, [pathname]);
};

0 comments on commit 28d5e56

Please sign in to comment.