Skip to content
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_GA_ID=G-XXXXXXXXXX
NEXT_PUBLIC_CLARITY_ID=XXXXXXXXXX
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ yarn-error.log*

# local env files
.env*.local
.env

# vercel
.vercel
Expand Down
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"lint": "next lint"
},
"dependencies": {
"@microsoft/clarity": "^1.0.2",
"@next/third-parties": "^16.2.1",
"@types/node": "20.2.1",
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
Expand Down
16 changes: 16 additions & 0 deletions src/app/components/ClarityInit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use client'

import Clarity from '@microsoft/clarity'
import { useEffect } from 'react'

export default function ClarityInit() {
useEffect(() => {
if (!process.env.NEXT_PUBLIC_CLARITY_ID) {
console.warn('Warning: NEXT_PUBLIC_CLARITY_ID is not set. Microsoft Clarity will not be initialized.')
return
}
Clarity.init(process.env.NEXT_PUBLIC_CLARITY_ID)
}, [])

return null
}
10 changes: 10 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import './globals.css'
import { Poppins } from 'next/font/google'
import { GoogleAnalytics } from '@next/third-parties/google'
import ClarityInit from './components/ClarityInit'

const poppins = Poppins({
weight: ['200', '300', '400', '500', '600', '700'],
Expand All @@ -18,9 +20,17 @@ export default function RootLayout({
}: {
children: React.ReactNode
}) {
if (!process.env.NEXT_PUBLIC_GA_ID) {
console.warn('Warning: NEXT_PUBLIC_GA_ID is not set. Google Analytics will not be initialized.')
}

return (
<html lang='en' className='scroll-smooth'>
<body className={poppins.className}>{children}</body>
{process.env.NEXT_PUBLIC_GA_ID && (
<GoogleAnalytics gaId={process.env.NEXT_PUBLIC_GA_ID} />
)}
<ClarityInit />
</html>
)
}
Loading