Skip to content

Commit

Permalink
fix(website): fix gtag errors
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Apr 29, 2024
1 parent 29d2de3 commit 0b6bfbe
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 31 deletions.
36 changes: 20 additions & 16 deletions src/website/app/root.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Links, LiveReload, Meta, Outlet, Scripts, ScrollRestoration } from '@remix-run/react';
import styles from './tailwind.css';
import * as gtag from "~/utils/gtags.client";
import {
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from '@remix-run/react';
import { useEffect } from 'react';
import * as gtag from '~/utils/gtags.client';
import styles from './tailwind.css';

export function meta() {
return [{ title: 'Utah Roadkill Reporter' }];
Expand All @@ -14,11 +21,8 @@ export function links() {
const gaTrackingId = 'G-P135E0DCLT';

export default function App() {

useEffect(() => {
if (gaTrackingId?.length) {
gtag.pageview(location.pathname, gaTrackingId);
}
gtag.pageview(location.pathname, gaTrackingId);
}, []);

return (
Expand All @@ -29,7 +33,8 @@ export default function App() {
<Meta />
<Links />
</head>
{process.env.NODE_ENV === "development" || !gaTrackingId ? null : (
<body className="p-10 font-sans text-gray-700">
{process.env.NODE_ENV === 'development' ? null : (
<>
<script
async
Expand All @@ -40,19 +45,18 @@ export default function App() {
id="gtag-init"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gaTrackingId}', {
page_path: window.location.pathname,
});
`,
gtag('config', '${gaTrackingId}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
)}
<body className="p-10 font-sans text-gray-700">
<Outlet />
<ScrollRestoration />
<Scripts />
Expand Down
196 changes: 181 additions & 15 deletions src/website/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 src/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"eslint-config-prettier": "^9.1.0",
"prettier": "^3.2.5",
"prettier-plugin-organize-imports": "^3.2.4",
"prettier-plugin-packagejson": "^2.5.0",
"tailwindcss": "^3.4.3"
},
"engines": {
Expand Down

0 comments on commit 0b6bfbe

Please sign in to comment.