Skip to content

Commit

Permalink
update ga4 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
totegamma committed Dec 11, 2024
1 parent f5edca6 commit b2299a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
12 changes: 12 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
<meta property="og:description" content="Concrntはあなたの世界をちょっとだけより豊かにする、新しい時代のSNSです" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://concrnt.world/" /><meta property="og:image" content="https://concrnt.world/concrnt.png"/>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Y4V0V7XYWX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-Y4V0V7XYWX', {
//debug_mode: true,
send_page_view: false
});
</script>
</head>
<body>
<div id="root"></div>
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.10",
"react-ga4": "^2.1.0",
"react-helmet-async": "^2.0.5",
"react-i18next": "^13.2.2",
"react-icons": "^5.2.1",
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions src/context/GA4.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createContext, useEffect } from 'react'
import { useLocation } from 'react-router-dom'
import ReactGA from 'react-ga4'

const GA4Context = createContext({})

Expand All @@ -12,17 +11,18 @@ interface GA4ProviderProps {
export const GA4Provider = (props: GA4ProviderProps): JSX.Element => {
const location = useLocation()

useEffect(() => {
ReactGA.initialize(props.tag)
}, [])

useEffect(() => {
setTimeout(() => {
ReactGA.send({
hitType: 'pageview',
page: location.pathname,
title: document.title
})
const gtag = (window as any).gtag
if (typeof gtag === 'function') {
gtag('config', props.tag, {
// debug_mode: true,
page_path: location.pathname,
page_title: document.title
})
} else {
console.error('gtag not found')
}
}, 100)
}, [location.pathname])

Expand Down

0 comments on commit b2299a8

Please sign in to comment.