Skip to content
Merged

ds #158

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ jobs:
run: npm ci
- name: Build website
working-directory: ./app
env:
VITE_GA_MEASUREMENT_ID: ${{ secrets.VITE_GA_MEASUREMENT_ID }}
run: |
if [ "${{ github.repository }}" = "ACCIDDA/RespiLens-staging" ]; then
npm run build:staging
Expand Down
8 changes: 8 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>RespiLens</title>
<meta name="description" content="Explore the latest forecasts of respiratory disease activity across every U.S. state. RespiLens provides intuitive and consolidated visualization of influenza, COVID-19, and RSV forecasts from CDC-led competitions." />
<!-- Google Analytics (GA4) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=%VITE_GA_MEASUREMENT_ID%"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '%VITE_GA_MEASUREMENT_ID%');
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
Expand Down
18 changes: 17 additions & 1 deletion app/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BrowserRouter as Router, Routes, Route, useNavigate } from 'react-router-dom';
import { BrowserRouter as Router, Routes, Route, useNavigate, useLocation } from 'react-router-dom';
import { useEffect } from 'react';
import { HelmetProvider } from 'react-helmet-async';
import { ViewProvider } from './contexts/ViewContext';
import { useView } from './hooks/useView';
Expand Down Expand Up @@ -53,9 +54,24 @@ const AppLayout = () => {
};

const App = () => {
const AnalyticsTracker = () => {
const location = useLocation();

useEffect(() => {
if (typeof window !== 'undefined' && window.gtag) {
window.gtag('config', import.meta.env.VITE_GA_MEASUREMENT_ID, {
page_path: location.pathname + location.search,
});
}
}, [location]);

return null;
};

return (
<HelmetProvider>
<Router>
<AnalyticsTracker />
<ViewProvider>
<AppLayout />
</ViewProvider>
Expand Down
Loading