Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
></script>
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-H3ZTJT4LNW"
src="https://www.googletagmanager.com/gtag/js?id=G-E7XGKV9GNF"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-H3ZTJT4LNW', {
gtag('config', 'G-E7XGKV9GNF', {
debug_mode: true,
});
</script>
Expand Down
3 changes: 3 additions & 0 deletions src/components/common/Layout/DefaultLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Outlet } from 'react-router-dom';
import Navigation from '@/components/common/Navigation/Navigation';
import usePageViewTracking from '@/hooks/usePageViewTracking';

export default function DefaultLayout() {
usePageViewTracking();

return (
<div className="relative w-full h-full mx-auto my-0 min-h-lvh max-w-[480px]">
<div className="pb-[80px]">
Expand Down
3 changes: 3 additions & 0 deletions src/components/common/Layout/SubLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Outlet } from 'react-router-dom';
import usePageViewTracking from '@/hooks/usePageViewTracking';

export default function SubLayout() {
usePageViewTracking();

return (
<div className="w-full h-lvh min-h-lvh mx-auto my-0 desktop:w-[480px]">
<Outlet />
Expand Down
6 changes: 5 additions & 1 deletion src/components/poll-detail/Button/PollButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useQueryClient } from '@tanstack/react-query';
import ReactGA from 'react-ga4';
import usePost from '@/api/usePost';
import { Button } from '@/components/common/Button/Button';
import useToast from '@/components/common/Toast/hooks';
Expand All @@ -16,6 +17,10 @@ export default function PollButton({ postId, checkedItems }: PollButtonProps) {

const { mutate: vote, isPending } = usePost({
onSuccess: () => {
ReactGA.event('poll_voted', {
post_id: postId,
});

queryClient.invalidateQueries({ queryKey: ['post', String(postId)] });
queryClient.invalidateQueries({
queryKey: ['postResult', String(postId)],
Expand All @@ -26,7 +31,6 @@ export default function PollButton({ postId, checkedItems }: PollButtonProps) {
description: '투표가 성공적으로 완료되었어요.',
});

// voteMode 종료
setVoteMode(false);
},
});
Expand Down
14 changes: 14 additions & 0 deletions src/hooks/usePageViewTracking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useEffect } from 'react';
import ReactGA from 'react-ga4';
import { useLocation } from 'react-router-dom';

export default function usePageViewTracking() {
const location = useLocation();

useEffect(() => {
ReactGA.send({
hitType: 'pageview',
page: location.pathname + location.search,
});
}, [location]);
}
7 changes: 7 additions & 0 deletions src/pages/OnBoarding/OnBoardingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from 'react';
import ReactGA from 'react-ga4';
import { useNavigate } from 'react-router-dom';
import useGetMyInfo from '@/api/useGetMyInfo';
import onboardingImage from '@/assets/images/onboarding/onboarding.png';
Expand All @@ -22,6 +23,12 @@ export default function OnBoardingPage() {
}, 2500);
}, []);

useEffect(() => {
if (!showSplash) {
ReactGA.event('onboarding_viewed');
}
}, [showSplash]);

if (showSplash) {
return (
<div className="flex w-full h-screen justify-center items-center">
Expand Down
10 changes: 10 additions & 0 deletions src/pages/PollDetail/PollResultPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useEffect } from 'react';
import ReactGA from 'react-ga4';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { useGetNotificationPresent } from '@/api/useGetNotificationPresent';
import { useGetPost } from '@/api/useGetPost';
Expand Down Expand Up @@ -29,6 +31,14 @@ export default function PollResultPage() {
},
});

useEffect(() => {
if (post && result) {
ReactGA.event('poll_result_viewed', {
post_id: postId,
});
}
}, [post, result, postId]);

if (isPostLoading || isResultLoading) return <Loading />;
if (!post || !result) return <NotFoundPage />;

Expand Down