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(gtag): send the newly rendered page's title instead of the old one's #7424

Merged
merged 5 commits into from
May 27, 2022

Conversation

ori-shalom
Copy link
Contributor

@ori-shalom ori-shalom commented May 15, 2022

Pre-flight checklist

Motivation

Fix #7420

Test Plan

I manually tested it with the reproduction environment on stackblitz.
I also have on my private project repo this implementation fix of the gtag plugin that I deployed and debuged using GA debug tools.
It can be clearly seen in the logs and in GA debug panel that the correct title is used now.

Test links

https://stackblitz.com/edit/github-fab3de?file=plugin%2Fclient-module.js

Deploy preview: https://deploy-preview-7424--docusaurus-2.netlify.app/

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label May 15, 2022
@Josh-Cena Josh-Cena added the pr: bug fix This PR fixes a bug in a past release. label May 15, 2022
Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

Please also add a brief comment explaining this, and linking to the issue.

(And fixing the syntax error, of course)

@netlify
Copy link

netlify bot commented May 15, 2022

[V2]

Name Link
🔨 Latest commit d1596e4
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/6290dd688645ee0008c987fc
😎 Deploy Preview https://deploy-preview-7424--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented May 15, 2022

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟢 95 🟢 100 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟢 90 🟢 99 🟢 100 🟢 100 🟢 90 Report

Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

This makes sense to me.

@slorber seems to dislike setTimeout for good reason, so I'll wait for his decision on this.

@Josh-Cena Josh-Cena changed the title fix:(plugin-google-gtag) wrong document title is sent with gtag fix(gtag): send the newly rendered page's title instead of the old one's May 16, 2022
@ori-shalom
Copy link
Contributor Author

@slorber any comment on that?

@Kennysong55

This comment was marked as off-topic.

@slorber
Copy link
Collaborator

slorber commented May 27, 2022

Related to #6732

I don't think we should ask all analytics plugin authors to use setTimeout (including ourselves)

I'd rather make it a guarantee that page metadatas/title are already updated when routeDidUpdate callback is fired

Some local tests:

CleanShot 2022-05-27 at 15 05 07@2x

The easy solution would be to move to useEffect instead of useLayoutEffect: this is nice for analytics but likely not ideal for other use-cases where we need to update the DOM synchronously

@slorber
Copy link
Collaborator

slorber commented May 27, 2022

Waiting for an answer here: https://twitter.com/sebastienlorber/status/1530180431475265537

@slorber
Copy link
Collaborator

slorber commented May 27, 2022

Going to merge this, as at least it fixes the GTAG plugin for the next release

But clearly we are not done yet with those lifecycles, and this setTimeout should not be necessary

@slorber slorber merged commit 49ecd8f into facebook:main May 27, 2022
tisonkun added a commit to korandoru/town that referenced this pull request Nov 2, 2022
This is the same solution as
facebook/docusaurus#7424.

Signed-off-by: tison <wander4096@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The gtag plugin sends the previous document title
5 participants