diff --git a/.env.example b/.env.example index de49146b26..7b68318025 100644 --- a/.env.example +++ b/.env.example @@ -434,4 +434,8 @@ NEXT_PUBLIC_QUERY_AVAILABLE_SLOTS_INTERVAL_SECONDS= # Used to invalidate available slots when navigating to booking form NEXT_PUBLIC_INVALIDATE_AVAILABLE_SLOTS_ON_BOOKING_FORM=0 # Used to enable quick availability checks for x% of all visitors -NEXT_PUBLIC_QUICK_AVAILABILITY_ROLLOUT=10 \ No newline at end of file +NEXT_PUBLIC_QUICK_AVAILABILITY_ROLLOUT=10 + +# Deprecated. Use NEXT_PUBLIC_BODY_SCRIPTS instead. NEXT_PUBLIC_HEAD_SCRIPTS are now injected into the body only. +NEXT_PUBLIC_HEAD_SCRIPTS= +NEXT_PUBLIC_BODY_SCRIPTS= \ No newline at end of file diff --git a/apps/web/app/(use-page-wrapper)/layout.tsx b/apps/web/app/(use-page-wrapper)/layout.tsx index b06a3a5fe6..761b529d3a 100644 --- a/apps/web/app/(use-page-wrapper)/layout.tsx +++ b/apps/web/app/(use-page-wrapper)/layout.tsx @@ -1,14 +1,39 @@ import { headers } from "next/headers"; +import Script from "next/script"; import PageWrapper from "@components/PageWrapperAppDir"; export default async function PageWrapperLayout({ children }: { children: React.ReactNode }) { const h = await headers(); const nonce = h.get("x-nonce") ?? undefined; + const headScript = process.env.NEXT_PUBLIC_HEAD_SCRIPTS; + const bodyScript = process.env.NEXT_PUBLIC_BODY_SCRIPTS; + + const scripts = [ + { + id: "injected-head-script", + script: headScript ?? "", + }, + { + id: "injected-body-script", + script: bodyScript ?? "", + }, + ].filter((script): script is { id: string; script: string } => !!script.script); return ( {children} + {scripts.map((script) => ( +