-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
974e6cc
commit fc74eb8
Showing
3 changed files
with
22 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
このイベント (
/unlocked
へ遷移した) は, Google Analytics の “ページとスクリーン” から見られるから不要かも?将来的に何かを追加するためにとりあえず書いたのならこのコメントは無視して OK です.