Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"tailwindcss": "^3.4.4"
},
"engines": {
"node": "^22",
"node": "^23",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this just because I was getting an error message stating that the version of Node on my local is too new (v23) and preventing me from being able to commit. The app runs just fine for me on v23– should be fine to bump it up to that.

"npm": "use-pnpm"
},
"packageManager": "[email protected]+sha512.beb9e2a803db336c10c9af682b58ad7181ca0fbd0d4119f2b33d5f2582e96d6c0d93c85b23869295b765170fbdaa92890c0da6ada457415039769edf3c959efe",
Expand Down
9 changes: 9 additions & 0 deletions src/lib/gtag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// eslint-disable-next-line no-restricted-globals, n/prefer-global/process
export const GA_TRACKING_ID = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_KEY;

// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
export const logPageview = (url) => {
window.gtag("config", GA_TRACKING_ID, {
page_path: url,
});
};
17 changes: 16 additions & 1 deletion src/pages/_app.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import "../../faust.config";
import { WordPressBlocksProvider } from "@faustwp/blocks";
import { FaustProvider } from "@faustwp/core";
import { useRouter } from "next/router";
import { useEffect } from "react";
import "../../faust.config";
import "./global.css";
import Layout from "@/components/layout";
import "@faustwp/core/dist/css/toolbar.css";
import * as gtag from "@/lib/gtag";
import blocks from "@/wp-blocks";

export default function MyApp({ Component, pageProps }) {
const router = useRouter();

// Record a Google Analytics pageview on route change
useEffect(() => {
const handleRouteChange = (url) => gtag.logPageview(url);

router.events.on("routeChangeComplete", handleRouteChange);
return () => {
router.events.off("routeChangeComplete", handleRouteChange);
};
}, [router.events]);

return (
<FaustProvider pageProps={pageProps}>
{/* eslint-disable-next-line unicorn/no-null */}
Expand Down
19 changes: 19 additions & 0 deletions src/pages/_document.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
import { Html, Head, Main, NextScript } from "next/document";
import { GA_TRACKING_ID } from "@/lib/gtag";

export default function Document() {
return (
<Html lang="en">
<Head>
{/* Global Site Tag (gtag.js) - Google Analytics */}
<script
async
src={`https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}`}
/>
<script
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GA_TRACKING_ID}', {
page_path: window.location.pathname,
});
`,
}}
/>
<link href="/images/favicon-32x32.png" rel="icon" sizes="32x32" />
<link href="/images/favicon-192x192.png" rel="icon" sizes="192x192" />
</Head>
Expand Down
Loading