diff --git a/docs/docs/reference/built-in-components/gatsby-script.md b/docs/docs/reference/built-in-components/gatsby-script.md index 824c0d01a07f5..e635b2a727302 100644 --- a/docs/docs/reference/built-in-components/gatsby-script.md +++ b/docs/docs/reference/built-in-components/gatsby-script.md @@ -153,9 +153,9 @@ import { Script } from "gatsby" /> diff --git a/packages/gatsby-plugin-google-gtag/src/gatsby-ssr.js b/packages/gatsby-plugin-google-gtag/src/gatsby-ssr.js index 7671d4f6bfe01..17d096706a28a 100644 --- a/packages/gatsby-plugin-google-gtag/src/gatsby-ssr.js +++ b/packages/gatsby-plugin-google-gtag/src/gatsby-ssr.js @@ -59,7 +59,7 @@ exports.onRenderBody = ( : `true` }) { window.dataLayer = window.dataLayer || []; - function gtag(){window.dataLayer && window.dataLayer.push(arguments);} + function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); ${pluginOptions.trackingIds diff --git a/packages/gatsby-script/README.md b/packages/gatsby-script/README.md index 6b2c3126443a8..799dd02bdb61c 100644 --- a/packages/gatsby-script/README.md +++ b/packages/gatsby-script/README.md @@ -37,8 +37,8 @@ function IndexPage() { {` // Example configuration of Google Analytics for use in Partytown window.dataLayer = window.dataLayer || []; - window.gtag = function gtag() { window.dataLayer.push(arguments); } - gtag('js', new Date()); + function gtag(){dataLayer.push(arguments)}; + gtag('js', new Date()); gtag('config', ${GTM}, { send_page_view: false }) `}