Skip to content

Commit

Permalink
Merge pull request #248 from UTDNebula/google-analytics
Browse files Browse the repository at this point in the history
Add Google analytics
  • Loading branch information
AbhiramTadepalli authored Oct 8, 2024
2 parents a915abd + c284df9 commit 7642291
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/components/common/GoogleAnalytics/googleAnalytics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Script from 'next/script';
import React from 'react';

const GoogleAnalytics = () => {
return (
<>
<Script
strategy="lazyOnload"
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_MEASUREMENT_ID}`}
/>

<Script id="" strategy="lazyOnload">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_MEASUREMENT_ID}', {
page_path: window.location.pathname,
});
`}
</Script>
</>
);
};

export default GoogleAnalytics;
2 changes: 2 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import React from 'react';

import FeedbackPopup from '../components/common/FeedbackPopup/feedbackPopup';
import GitHubButton from '../components/common/GitHubButton/gitHubButton';
import GoogleAnalytics from '../components/common/GoogleAnalytics/googleAnalytics';

const inter = Inter({
subsets: ['latin'],
Expand Down Expand Up @@ -108,6 +109,7 @@ function MyApp({ Component, pageProps }: AppProps) {

return (
<>
<GoogleAnalytics />
<Head>
<title>UTD Trends</title>
<link
Expand Down

0 comments on commit 7642291

Please sign in to comment.