Skip to content

Commit

Permalink
fix(gatsby-plugin-google-gtag): correct script to match google's curr…
Browse files Browse the repository at this point in the history
…ent (#36993)

Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
benomatis and LekoArts authored Nov 17, 2022
1 parent 644c84b commit 5cb5014
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions docs/docs/reference/built-in-components/gatsby-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ import { Script } from "gatsby"
/>
<Script id="gtag-config" strategy="off-main-thread" forward={[`gtag`]}>
{`
window.dataLayer = window.dataLayer || []
window.gtag = function gtag() { window.dataLayer.push(arguments) }
gtag('js', new Date())
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>
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-google-gtag/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
`}
</Script>
Expand Down

0 comments on commit 5cb5014

Please sign in to comment.