Skip to content

Commit

Permalink
設定忘れ
Browse files Browse the repository at this point in the history
  • Loading branch information
nasubi-dev committed Sep 28, 2024
1 parent 974e6cc commit fc74eb8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
30 changes: 18 additions & 12 deletions src/lib/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
export function sendAnalytics(
eventName: "unlock" | "achievementDetail" | "memberDetail" | "",
url: string,
): void {
window.gtag("event", eventName, {
items: [
{
item_id: url,
},
],
});
}
import { useEffect } from "react";
import ReactGA from "react-ga4";
import { useLocation } from "react-router-dom";

export const usePageTracking = (): void => {
const location = useLocation();

useEffect(() => {
// Google Analytics 測定 ID を入力して設定
ReactGA.initialize("G-8KV8Z5BX8M");
ReactGA.send({
hitType: "pageview",
// アクセスしたパス (pathname) とクエリ文字列 (search) を送付する (必要に応じて編集する)
page: location.pathname + location.search,
});
}, [location]);
};

3 changes: 2 additions & 1 deletion src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Expanded } from "@/components/Expanded";
import { Footer } from "@/components/Footer";
import { Header } from "@/components/Header";
import { Redirects } from "@/components/Redirects";

import { usePageTracking } from "@/lib/utils/analytics";
import "the-new-css-reset/css/reset.css";
import "@radix-ui/themes/styles.css";
import "@fontsource-variable/noto-sans-jp";
Expand Down Expand Up @@ -60,6 +60,7 @@ const ThemeStyle = styled(Theme)`
`;

export default function Layout(): ReactElement {
usePageTracking();
return (
<ThemeStyle>
<Main>
Expand Down
5 changes: 2 additions & 3 deletions src/pages/unlocked/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box } from "@radix-ui/themes";
import { useState, type ReactElement } from "react";
import ReactGA from "react-ga4";
import { useLocation } from "react-router-dom";

Check failure on line 4 in src/pages/unlocked/index.tsx

View workflow job for this annotation

GitHub Actions / build

'useLocation' is declared but its value is never read.
import styled from "styled-components";
import useSWRImmutable from "swr/immutable";
Expand All @@ -11,7 +12,6 @@ import { useUnlockedAchievements } from "@/hooks/db/unlocked-achievements";
import { useMember } from "@/hooks/member";
import { useTeam } from "@/hooks/teams";
import { S } from "@/lib/consts";
import { sendAnalytics } from "@/lib/utils/analytics";
import { handleSWRError } from "@/lib/utils/swr";
import { type CurrentMember } from "@/types/member";
import { type Achievement } from "@/types/post-data/achievements";
Expand All @@ -24,7 +24,6 @@ const BoxStyle = styled(Box)`
`;

export default function Page(): ReactElement {
const url = useLocation().pathname;
const { fetchCurrentMember } = useMember();
const { fetch: fetchAchievements } = useAchievements(useTeam);
const { fetch: fetchUnlockedAchievements, update } =
Expand Down Expand Up @@ -61,7 +60,7 @@ export default function Page(): ReactElement {
({ achievementID: id }) => id !== targetAchievementId,
),
);
sendAnalytics("unlock", url);
ReactGA.event("unlocked achievement");

This comment has been minimized.

Copy link
@wappon28dev

wappon28dev Sep 29, 2024

Member

このイベント (/unlocked へ遷移した) は, Google Analytics の “ページとスクリーン” から見られるから不要かも?
将来的に何かを追加するためにとりあえず書いたのならこのコメントは無視して OK です.

This comment has been minimized.

Copy link
@nasubi-dev

nasubi-dev Sep 29, 2024

Author Member

あーコレは実績を解除した回数をイベントとして数えたいんだけど、やり方ミスってるね。修正します。

await mutate();
} finally {
setIsUILocked(false);
Expand Down

0 comments on commit fc74eb8

Please sign in to comment.