Skip to content

Commit

Permalink
Move hosts, keys and ids 'constants.ts'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixep committed Jun 18, 2024
1 parent b11afbd commit 36af176
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material/Container';
import { lightTheme } from '@/theme';
import PatchCssStyle from '@/PatchCssStyle';

import { GOOGLE_TAG_ID } from '@/constants/constants';
import Header from '@/components/Header';
import Footer from '@/components/Footer';

Expand Down Expand Up @@ -53,15 +55,20 @@ export default function RootLayout({ children }: { children: React.ReactNode })
return (
<html lang="en" className={open_sans_font.className}>
<body>
<Script async src="https://www.googletagmanager.com/gtag/js?id=G-C9SQS63TJQ" />
<Script
async
src={'https://www.googletagmanager.com/gtag/js?id=' + GOOGLE_TAG_ID}
/>
<Script id="gtag">
{`
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-C9SQS63TJQ', {
gtag('config', '` +
GOOGLE_TAG_ID +
`', {
anonymize_ip: true,
client_storage: 'none',
ad_storage: 'denied',
Expand Down
4 changes: 2 additions & 2 deletions src/app/submit-project/SubmitProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import TextField from '@mui/material/TextField';
import Typography from '@mui/material/Typography';

import ReCAPTCHA from 'react-google-recaptcha';
import submitProject from './submitProject';

const RECAPTCHA_SITE_KEY = '6LeuSEYeAAAAAJrZY05dnjlIkU-3EAe4JqDdd3wz';
import { RECAPTCHA_SITE_KEY } from '@/constants/constants';
import submitProject from './submitProject';

const enum FormState {
NotSubmitted,
Expand Down
4 changes: 3 additions & 1 deletion src/components/GaPageEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import React, { useEffect } from 'react';
import { usePathname } from 'next/navigation';

import { GOOGLE_TAG_ID } from '@/constants/constants';

const GaPageEvent = () => {
const pathname = usePathname();
useEffect(() => {
if (!window.gtag) {
return;
}
window.gtag('config', 'G-C9SQS63TJQ', {
window.gtag('config', GOOGLE_TAG_ID, {
page_path: pathname,
});
}, [pathname]);
Expand Down
4 changes: 4 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const RECAPTCHA_SITE_KEY = '6LeuSEYeAAAAAJrZY05dnjlIkU-3EAe4JqDdd3wz';
export const GOOGLE_TAG_ID = 'G-C9SQS63TJQ';
export const PRODUCTION_HOST = 'https://meaningfulcode.org';
export const LOCAL_DEV_HOST = 'http://localhost:3000';
9 changes: 5 additions & 4 deletions src/utils/getHost.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { PRODUCTION_HOST, LOCAL_DEV_HOST } from '@/constants/constants';

export default function getHost() {
if (typeof window !== 'undefined' && process.env.NODE_ENV !== 'test') {
throw new Error('getHost() should only be called on the server side');
}

const productionHost = 'https://meaningfulcode.org';
if (process.env.NEXT_PUBLIC_VERCEL_ENV) {
if (process.env.NEXT_PUBLIC_VERCEL_ENV === 'production') {
return productionHost;
return PRODUCTION_HOST;
} else {
return `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`;
}
} else if (process.env.MEANINGFUL_DEV) {
return 'http://localhost:3000';
return LOCAL_DEV_HOST;
} else {
return productionHost;
return PRODUCTION_HOST;
}
}

0 comments on commit 36af176

Please sign in to comment.