loren ipsun.

Copycopy code to clipboard
import { Script } from "gatsby"

// `process.env.GTAG` is your Google Analytics 4 identifier defined in your `.env.production` and `.env.development` files

<Script
  src={`https://www.googletagmanager.com/gtag/js?id=${process.env.GTAG}`}
  strategy="off-main-thread"
/>
<Script id="gtag-config" strategy="off-main-thread" forward={[`gtag`]}>
  {`
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments)};
    gtag('js', new Date());
    gtag('config', ${process.env.GTAG}, { page_path: location ? location.pathname + location.search + location.hash : undefined })
  `}
</Script>