Skip to content

Commit ab4f2b7

Browse files
Merge pull request #140 from OceanParcels/analytics
Add Google Analytics for page views
2 parents 085224e + fe34328 commit ab4f2b7

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"react": "^18.3.1",
4141
"react-apexcharts": "^1.4.1",
4242
"react-dom": "^18.3.1",
43+
"react-ga4": "^2.1.0",
4344
"react-icons": "^5.3.0",
4445
"react-syntax-highlighter": "^15.5.0",
4546
"rehype-slug": "^6.0.0",

src/components/layout.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { Header } from '@/components/header'
44
import { Link } from '@/components/mdx'
55
import { Box, Flex } from '@chakra-ui/react'
66
import Head from 'next/head'
7+
import ReactGA from 'react-ga4'
8+
import { useEffect } from 'react'
9+
10+
// Google Analytics
11+
ReactGA.initialize('G-62W42QPRQC')
712

813
export const Layout = ({
914
title,
@@ -13,6 +18,11 @@ export const Layout = ({
1318
url = 'https://oceanparcels.org',
1419
enableBanner = false,
1520
}) => {
21+
// Track page views
22+
useEffect(() => {
23+
ReactGA.send({ hitType: 'pageview' })
24+
}, [])
25+
1626
const bannerTitle = 'Parcels v4 currently in development'
1727
const bannerDescription = ''
1828
const bannerChildren = (

0 commit comments

Comments
 (0)