Skip to content

Commit 486b511

Browse files
committed
fix: plausible csp and tracking navigation changes
1 parent b4e4a24 commit 486b511

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ app.use(
6868
'*.google-analytics.com',
6969
'*.cloudfunctions.net',
7070
'sentry.io',
71+
'*.sentry.io',
72+
'https://plausible.io',
7173
...wsUrls,
7274
],
7375
defaultSrc: [
@@ -88,6 +90,7 @@ app.use(
8890
'*.analytics.google.com',
8991
'*.google-analytics.com',
9092
'www.youtube.com',
93+
'https://plausible.io',
9194
"'unsafe-eval'",
9295
"'unsafe-inline'",
9396
],

src/common/Analytics/GoogleAnalytics.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@ import ReactGA from 'react-ga4'
33
import { useLocation } from '@remix-run/react'
44
import { GA_TRACKING_ID } from 'src/config/config'
55

6+
declare global {
7+
interface Window {
8+
plausible?: (event: string, options?: Record<string, any>) => void
9+
}
10+
}
11+
612
export const GoogleAnalytics = () => {
713
const location = useLocation()
814

15+
// TODO: remove GA
916
useEffect(() => {
1017
if (GA_TRACKING_ID) {
1118
ReactGA.initialize([{ trackingId: GA_TRACKING_ID }])
@@ -18,6 +25,12 @@ export const GoogleAnalytics = () => {
1825
}
1926
}, [location])
2027

28+
useEffect(() => {
29+
if (window.plausible) {
30+
window.plausible('pageview')
31+
}
32+
}, [location.pathname, location.search])
33+
2134
const sendPageView = (location: any) => {
2235
ReactGA.set({ page: location.pathname })
2336
ReactGA.send({ hitType: 'pageview', page: location.pathname })

0 commit comments

Comments
 (0)