Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-google-gtag): correct script to match google's current #36993

Merged
merged 5 commits into from
Nov 17, 2022

Conversation

benomatis
Copy link
Contributor

When taking the script from GA directly, it doesn't have this additional check for window.dataLayer, also the related documentation shows it without it.

window.gtag = function gtag() { window.dataLayer.push(arguments); }

window.gtag = function gtag() { window.dataLayer.push(arguments) }

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 9, 2022
@LekoArts LekoArts added topic: plugins-analytics Various analytics plugins like gatsby-plugin-google-analytics and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Nov 16, 2022
@LekoArts
Copy link
Contributor

https://developers.google.com/tag-platform/gtagjs/install shows a different snippet:

  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

Can you also update all the docs that include this? Thanks!

@benomatis
Copy link
Contributor Author

https://developers.google.com/tag-platform/gtagjs/install shows a different snippet:

  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

Yes, indeed, I forgot to remove window from in front of dataLayer.push(arguments).

Can you also update all the docs that include this? Thanks!

Will do!

@benomatis
Copy link
Contributor Author

@LekoArts should be done now.

Copy link
Contributor

@LekoArts LekoArts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@LekoArts LekoArts merged commit 5cb5014 into gatsbyjs:master Nov 17, 2022
@benomatis benomatis deleted the patch-2 branch November 17, 2022 11:41
@joaquingatica
Copy link

joaquingatica commented Sep 25, 2023

Came across this other older PR while troubleshooting an error in Safari and DuckDuckGo Browser: #11431, and appears to be the reason the window.dataLayer && window. check was introduced.

Not questioning the decision of removing it, just wanted to add context in case it was missing at the time of merging, or to anybody who comes across this issue again.

@benomatis
Copy link
Contributor Author

benomatis commented Sep 25, 2023

@joaquingatica the changes in this PR are in line with GA's current manual install instructions of the GA4 tag, and in that snippet they only check window.dataLayer, not windows and then proceed to use dataLayer as a standalone function. It is further detailed in the description of the data layer.

I believe it must be happening for some other reason, most probably a browser plugin or privacy settings - this question on SO may provide some valid answers to such cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: plugins-analytics Various analytics plugins like gatsby-plugin-google-analytics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants