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(() => {
|
||||
if (!hasRun && !hasRunInitial.current) {
|
||||
if (performance) {
|
||||
const handleLoad = () => {
|
||||
const entry = performance.getEntriesByType("navigation")[0]
|
||||
|
||||
if (entry) {
|
||||
const trackingData = {
|
||||
...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
|
||||
setHasRun()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user