Merged in fix/pageloadtime-fix (pull request #1248)
tracking: wait on document.readystate * tracking: wait on document.readystate
This commit is contained in:
@@ -49,9 +49,8 @@ export default function RouterTransition({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!hasRun && !hasRunInitial.current) {
|
if (!hasRun && !hasRunInitial.current) {
|
||||||
if (performance) {
|
const handleLoad = () => {
|
||||||
const entry = performance.getEntriesByType("navigation")[0]
|
const entry = performance.getEntriesByType("navigation")[0]
|
||||||
|
|
||||||
if (entry) {
|
if (entry) {
|
||||||
const trackingData = {
|
const trackingData = {
|
||||||
...pageData,
|
...pageData,
|
||||||
@@ -69,7 +68,14 @@ export default function RouterTransition({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If the page is already loaded, execute immediately
|
||||||
|
if (document.readyState === "complete") {
|
||||||
|
handleLoad()
|
||||||
|
} else {
|
||||||
|
// Otherwise wait for the load event
|
||||||
|
window.addEventListener("load", handleLoad)
|
||||||
|
return () => window.removeEventListener("load", handleLoad)
|
||||||
|
}
|
||||||
hasRunInitial.current = true
|
hasRunInitial.current = true
|
||||||
setHasRun()
|
setHasRun()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user