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

feat(web): Add Google Analytics integration #649

Merged
merged 7 commits into from
Jan 22, 2025
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
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@mdx-js/loader": "^3.0.1",
"@mdx-js/react": "^3.0.1",
"@next/mdx": "^14.2.3",
"@next/third-parties": "^15.1.5",
"@tsparticles/engine": "^3.3.0",
"@tsparticles/react": "^3.0.0",
"@tsparticles/slim": "^3.3.0",
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './global.css'
import type { Metadata } from 'next'
import { GoogleAnalytics } from '@next/third-parties/google'

const description =
'Manage all your secrets securely with public key encryption and realtime based tools, that seamlessly fits into your codebase'
Expand Down Expand Up @@ -80,6 +81,9 @@ export default function RootLayout({
return (
<html lang="en">
<body>{children}</body>
<GoogleAnalytics
gaId={process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID}
/>
</html>
)
}
27 changes: 27 additions & 0 deletions apps/web/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { type TypeOf, z } from 'zod'

const zodEnv = z.object({
NEXT_PUBLIC_GOOGLE_ANALYTICS_MEASUREMENT_ID: z.string().url()
})

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace -- we need to extend the global namespace
namespace NodeJS {
// eslint-disable-next-line @typescript-eslint/no-empty-interface -- we need to extend the global namespace
interface ProcessEnv extends TypeOf<typeof zodEnv> {}
}
}

try {
zodEnv.parse(process.env)
} catch (error) {
if (error instanceof z.ZodError) {
const { fieldErrors } = error.flatten()
const errorMessage = Object.entries(fieldErrors)
.map(([field, errors]) => `${field}: ${errors?.join(', ')}`)
.join('\n ')
throw new Error(
`Missing environment variables: \n ${errorMessage}\n Please check your .env file.`
)
}
}
Loading
Loading