Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avenmia/add google analytics #206

Merged
merged 4 commits into from
Apr 27, 2024
Merged
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
13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.3",
"@types/gtag.js": "^0.0.19",
"@types/leaflet": "^1.9.0",
"@types/node": "^18.11.18",
"@types/prettier": "^2.7.2",
Expand Down
10 changes: 10 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ npx prisma db push

> Note: The demographic questions will not populate because they are hard-coded in the SQL migrations.

# Add Google Analytics Environment variable

- In the .env file add

```
NEXT_PUBLIC_GA_ID = {MyGoogleAnalyticsID}
```

- This will enable google analytics on the site

# Working with prisma

When the data model changes, run the following to update your local database with the latest migrations
Expand Down
32 changes: 32 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Document, { Html, Head, Main, NextScript } from "next/document";
// Importing the Google Analytics Measurement ID from the environment variable
const gaTag = process.env.NEXT_PUBLIC_GA_ID ?? "";
const gtag = `https://www.googletagmanager.com/gtag/js?id=${gaTag}`;
export default class MyDocument extends Document {
render() {
return (
<Html>
<Head>
{/* Google Analytics Measurement ID*/}
<script async src={gtag} />
<script
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaTag}', {
page_path: window.location.pathname
});
`,
}}
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
Loading