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

gatsby-plugin-google-analytics: sendPageView should be called via requestAnimationFrame, when available #28591

Closed
d4h0 opened this issue Dec 13, 2020 · 7 comments
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby

Comments

@d4h0
Copy link

d4h0 commented Dec 13, 2020

React-Helm uses requestAnimationFrame to avoid FOUC.

This lead to a bug in gatsby-plugin-google-analytics where a page view was sent with the title of the previous page.

A workaround was implemented to fix the problem:

    if (`requestAnimationFrame` in window) {
      requestAnimationFrame(() => {
        requestAnimationFrame(sendPageView)
      })
    } else {
      // simulate 2 rAF calls
      setTimeout(sendPageView, 32)
    }

For some reason, requestAnimationFrame was removed later (see here):

  // Minimum delay for reactHelmet's requestAnimationFrame
  const delay = Math.max(32, pluginOptions.pageTransitionDelay || 0)
  setTimeout(sendPageView, delay)

Basically, this code assumes that every display has a refresh rate of 60, which is not the case (the iPad Pro has a refresh rate of 120, for example).

Because React-Helm uses requestAnimationFrame when available (and this plugin does not), this means, that on devices with a higher refresh rate than 60, the wrong title still could be sent.

See MDN on requestAnimationFrame:

The number of callbacks is usually 60 times per second, but will generally match the display refresh rate in most web browsers as per W3C recommendation.

An easy fix would be, to restore the original implementation (see above)

@d4h0 d4h0 added the type: bug An issue or pull request relating to a bug in Gatsby label Dec 13, 2020
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 13, 2020
@LekoArts LekoArts added topic: helmet and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 14, 2020
@LekoArts
Copy link
Contributor

We'd be happy to receive a PR to fix this. Thanks for the issue!

@d4h0
Copy link
Author

d4h0 commented Dec 14, 2020

@LekoArts: Sorry, I'm not using Google Analytics myself, and I'm behind with my own projects, so I won't create a PR myself (researching and reporting this bug used up all my available time for this).

@github-actions
Copy link

github-actions bot commented Jan 3, 2021

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 3, 2021
@d4h0
Copy link
Author

d4h0 commented Jan 3, 2021

If we missed this issue or if you want to keep it open, please reply here.

Looks like nobody is interested in fixing this, but this issue is still about a bug that should get fixed at some point, so it should be kept open, IMO.

@github-actions github-actions bot removed the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 4, 2021
@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jan 24, 2021
@github-actions
Copy link

github-actions bot commented Mar 5, 2021

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

@github-actions github-actions bot closed this as completed Mar 5, 2021
@seanflahertyT4
Copy link

Hi, is this still an issue? I am experiencing incorrect (unset) title names on google analytics. If so, I can do the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants