feat: integrate Microsoft Clarity and Google Analytics with environment variable support
This commit is contained in:
@@ -32,6 +32,8 @@ ARG NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET
|
||||
ARG NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID
|
||||
ARG NEXT_PUBLIC_FIREBASE_APP_ID
|
||||
ARG NEXT_PUBLIC_FIREBASE_VAPID_KEY
|
||||
ARG NEXT_PUBLIC_CLARITY_ID
|
||||
ARG NEXT_PUBLIC_GA_ID
|
||||
|
||||
# Set environment variables for build (NEXT_PUBLIC_* must be set at build time)
|
||||
ENV NEXT_TELEMETRY_DISABLED=1
|
||||
@@ -45,6 +47,8 @@ ENV NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=${NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET}
|
||||
ENV NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=${NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID}
|
||||
ENV NEXT_PUBLIC_FIREBASE_APP_ID=${NEXT_PUBLIC_FIREBASE_APP_ID}
|
||||
ENV NEXT_PUBLIC_FIREBASE_VAPID_KEY=${NEXT_PUBLIC_FIREBASE_VAPID_KEY}
|
||||
ENV NEXT_PUBLIC_CLARITY_ID=${NEXT_PUBLIC_CLARITY_ID}
|
||||
ENV NEXT_PUBLIC_GA_ID=${NEXT_PUBLIC_GA_ID}
|
||||
|
||||
# Build the application
|
||||
RUN npm run build
|
||||
|
||||
@@ -145,6 +145,27 @@ export default function RootLayout({
|
||||
data-website-id="00e1ce31-e174-4519-8b59-63e8d4556b01"
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
{/* Microsoft Clarity */}
|
||||
{process.env.NEXT_PUBLIC_CLARITY_ID && (
|
||||
<Script id="ms-clarity" strategy="afterInteractive">
|
||||
{`(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y)})(window,document,"clarity","script","${process.env.NEXT_PUBLIC_CLARITY_ID}");`}
|
||||
</Script>
|
||||
)}
|
||||
{/* Google Analytics 4 */}
|
||||
{process.env.NEXT_PUBLIC_GA_ID && (
|
||||
<>
|
||||
<Script
|
||||
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_ID}`}
|
||||
strategy="afterInteractive"
|
||||
/>
|
||||
<Script id="ga4" strategy="afterInteractive">
|
||||
{`window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '${process.env.NEXT_PUBLIC_GA_ID}');`}
|
||||
</Script>
|
||||
</>
|
||||
)}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user