Skip to content

Commit

Permalink
Avenmia/add google analytics (#206)
Browse files Browse the repository at this point in the history
* Adding google analytics

* Updating README for google analytics

* Fixing errors
  • Loading branch information
avenmia authored Apr 27, 2024
1 parent 92d47a4 commit 65f307f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
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>
);
}
}

0 comments on commit 65f307f

Please sign in to comment.