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

GTag #18

Merged
merged 1 commit into from
Dec 8, 2023
Merged

GTag #18

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
5 changes: 5 additions & 0 deletions src/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ import { primaryFont } from "src/theme/typography";
import ProgressBar from "src/components/progress-bar";
import { MotionLazy } from "src/components/animate/motion-lazy";
import { SettingsProvider, SettingsDrawer } from "src/components/settings";
import GTag from "src/components/GTag";
import { GTAG_ID } from "src/config-global";

export default function RootLayout({ children }) {
return (
<html lang="en" className={primaryFont.className}>
<head>
<GTag gtagId={GTAG_ID} />
</head>
<body>
<SettingsProvider
defaultSettings={{
Expand Down
22 changes: 22 additions & 0 deletions src/components/GTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import PropTypes from "prop-types";
import Script from 'next/script'

export default function GTag({ gtagId }) {
return (<>
<Script async src={`https://www.googletagmanager.com/gtag/js?id=${gtagId}`}></Script>
<Script id="google-analytics">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${gtagId}');
`}
</Script>
</>
);
}

GTag.propTypes = {
gtagId: PropTypes.string,
};
1 change: 1 addition & 0 deletions src/config-global.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const HOST_API = process.env.NEXT_PUBLIC_HOST_API;
export const GTAG_ID = process.env.GTAG_ID || ""
Loading