-
Notifications
You must be signed in to change notification settings - Fork 660
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
Title update lag #189
Comments
@alukach if your component tree is rather deep, then that could cause more delay, but in general we are at the mercy of the DOM's update latency. Although, we are due for some performance metrics for Helmet because we may be able to optimize more. I'll mark this as a todo to measure performance and see if there's a way to optimize. |
It also seems to be on render, but if it were before mount I'd reckon it'd be quicker. My document tree is very small but I'm still seeing a noticeable delay. Admittedly though, I did try it with |
This is probably out of the scope of this library, but I thought I'd pop in a note of where this is problematic: Analytics. I am sending Google Tag Manager events on history change, and the events getting sent to Google Analytics are always off-by-one on the URL <-> Browser Title relationship. Hooks I've tried in my setup:
The only hook I've found where I can get the correct timing is in To note again: I don't actually think this is helmet's problem, but I probably won't be the last person to hit a wall here and wanted to leave some information behind. |
I had same issue. This change b22e2f4 should also resolve this issue because it will be possible to disabling But for now downgrading to |
I'm running into this exact issue with PIwik Analytics as well. It will capture the previous document title since it triggers on history change. I'm hoping that what @adam187 said really does fix this issue. |
@dpehrson Ah, hah! I'm so glad you posted about this with regard to analytics problems. We recently upgraded from For now, we temporarily resolved it by wrapping our tracking functions inside a trackCurrentPage() {
return (dispatch) => {
setTimeout(() => {
dispatch(AnalyticsActions.track.resetPageCustomVars());
dispatch(AnalyticsActions.track.deviceType());
dispatch(AnalyticsActions.track.user());
dispatch(AnalyticsActions.sendPageViewToGA());
}, 0);
};
} |
I solved this by adding a variable to my component class called I tried the |
// Added this hack:
window.gaplugins.UrlChangeTracker.prototype.handleUrlChange = function(historyDidUpdate) {
window.requestIdleCallback(() => {
setTimeout(() => {
origHandleUrlChange.call(this, historyDidUpdate);
}, 100);
});
};
window.ga('create', config.googleAnalyticsId, 'auto');
window.ga('require', 'eventTracker');
window.ga('require', 'outboundLinkTracker');
window.ga('require', 'urlChangeTracker');
window.ga('send', 'pageview'); In fact, Why 100ms? It's an arbitary value actually. It's short enough to not miss any page change event, but long enough for React to complete its rendering. This works well enough for most cases. |
Seeing something similar to this problem, but not as a result of analytics. I have a script I run locally against my site. This script hits all key pages in the sitemap, as well a few odd cases (301s, 404s, 400s, and 500s). We run this script on every commit (against a baseline) to ensure we have no SEO regressions or unexpected 500s or what have you After switching to react-helmet, the script is off-by-one. What i mean by this is that no page when tested individually returns incorrect tags, but when tested as a group, I often get undefined back on the first test, with each subsequent test being behind 1 url behind (so that the 2nd test returns the correct seo tags for the 1st test, which obviously fails the 2nd test). If there is some inexplicable intentional ms delay, then I guess this is to be expected, but it doesn't make any sense to me. All my script does is hit a url, get the html back, and then uses cheerio to scrape the page and compare against the baseline Why would react-helmet be set up this way? Seems like it would be a disaster for any SEO crawler |
Hi, I got this issue as well at the moment. Is there any good or correct solution ?? |
Downdreading to version 4 when using React 16 created errors with prototypes. And after changing this to see if this helps created new errors. I see that this issue is quite popular and people are moving away from Helmet just to sort this issue. Are you planning to address this issue?? Cause if not I will need to use something else as well?? |
Removing the enhancement tag and escalating to a bug. We are in the process of discussing the roadmap for the next update major update and will be addressing some of these bugs. |
@tmbtech Hi. Thanks for the quick replay. I think this is a major disadvantage of your class. Everyone Is now want to have Analytics and Google stuff connected right for their marketing purposes and this puts your class back in the pack but it works ok for any other purpose. I think the solution to this one will somehow connect it to the Router and apply changes to head before the path will change. I know this sounds weird but I think this will prevent for having head data behind a change of URL for sure. I will love to see this done and especially you did not have any publish for a year according to npm and you still have crazy numbers of downloads weekly (~300k). I think this puts you guys in responsibility to keep this up to date. Especially that react is growing fast. Regards and I will check up on this issue :) Thanks for promoting this and pushing this forwards :) Keep up the good work :) |
Alot of overkill fixes on this thread, you can set the title tag easily through |
what happened to this issue? |
Reading through the solutions above, none were quite right for what I needed. An arbitrary delay is insufficient, as for us the page title is dependent on the results of an asynchronous API call. I'm using import React from 'react';
import Piwik from 'react-piwik';
import { Helmet } from 'react-helmet';
new Piwik({
url: 'https://analytics.example.com', // insert your analytics URL here
siteId: 1,
trackErrors: true,
});
Piwik.push(['enableHeartBeatTimer']);
let lastPath = null;
const onHelmetChange = ({ metaTags }) => {
if (
'undefined' !== typeof window &&
lastPath !== window.location.pathname &&
metaTags.filter(m => m.name === 'page-loaded' && m.content === 'true').length > 0
) {
if (lastPath !== null) {
Piwik.push(['setReferrerUrl', `${window.location.origin}${lastPath}`]);
}
Piwik.push(['setDocumentTitle', document.title]);
Piwik.push(['setCustomUrl', window.location.href]);
Piwik.push(['trackPageView']);
lastPath = window.location.pathname;
}
}
export default () => (
<Helmet onChangeClientState={onHelmetChange}>
<meta name="page-loaded" content="false" />
</Helmet>
) then on each page, when I set the metadata using Helmet, I also set <Helmet>
<meta name="page-loaded" content="true" />
</Helmet> The same approach can be used to trigger Google Analytics or any other events on true page load. Make sure you set |
Did someone resolved this issues using react-tag-manger ? |
I'm having the same problem with the document title sent out in analytics lagging one behind. |
Still the same problem in google analytics. Any news about this bug ? Thanks |
We are still having issues with this, title always showing one behind from url on GA. Any news on this please? |
I've tried for a bit to think in a good solution, but there are only two solutions that I can think of:
As I'm a bit out of schedule, for now, my solution was to use an abstraction that I had for SEO with ReactHelmet to manage the tracking of all pages. When if (prevPathname !== window.location.pathname) {
analytics.onPageChange();
prevPathname = window.location.pathname;
} |
To handle this, in my useEffect I gave a setTimeout of ~750-1000ms to execute ReactGA.pageview(), like : useEffect(() => {
setTimeout(() => {
ReactGA.pageview(window.location.pathname);
}, 1000);
}) However, I'm still looking for a cleaner solution. |
I'm having the same problem when implementing Segment tracking on a React SPA. |
Is there any update on this? |
This is still a major issue that could lead to my project migrating away from react-helmet. |
BUMP! |
I've noticed that there's a bit of a lag between a route changing and the
title
property updating. I'm guessing that this is around 200 - 300ms. While minor, it does look just a bit off. I experience this in both my project and also running the react-helmet-example. Are there any suggestions about reducing this lag? If not, is there any known faster way to update the document's title?The text was updated successfully, but these errors were encountered: