fix(gtag): send the newly rendered page's title instead of the old one's (#7424)

Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Ori Shalom 2022-05-27 17:48:29 +03:00 committed by GitHub
parent 7ab97d4726
commit 49ecd8f472
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View file

@ -13,10 +13,16 @@ function logPage(
location: Location,
previousLocation: Location | null,
): void {
console.log(`${event}
Previous location: ${previousLocation?.pathname}
Current location: ${location.pathname}
Current heading: ${document.getElementsByTagName('h1')[0]?.innerText}`);
console.log(event, location.pathname, {
location,
prevLocation: previousLocation,
heading: document.getElementsByTagName('h1')[0]?.innerText,
title: document.title,
description: (
document.querySelector('meta[name="description"]') as HTMLMetaElement
)?.content,
htmlClassName: document.getElementsByTagName('html')[0]?.className,
});
}
export function onRouteUpdate({