docs[patch]: Update how GA4 is collected (#18821)

There's some issue/setting with the current python GA4 app. I created a
new one just for feedback.
This commit is contained in:
Brace Sproul 2024-03-08 14:32:40 -08:00 committed by GitHub
parent a8de6d1533
commit 9c218d0154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 22 additions and 17 deletions

View File

@ -335,6 +335,10 @@ const config = {
src: "https://www.googletagmanager.com/gtag/js?id=G-9B66JQQH2F",
async: true,
},
{
src: "https://www.googletagmanager.com/gtag/js?id=G-WFT0J048RF",
async: true,
}
],
};

View File

@ -1,5 +1,5 @@
export default function gtag(...args) {
if (window.gtag) {
window.gtag(...args);
if (window.gtagFeedback) {
window.gtagFeedback(...args);
}
}

View File

@ -97,7 +97,7 @@ export default function Feedback() {
const [feedbackSent, setFeedbackSent] = useState(false);
/**
* @param {"yes" | "no"} feedback
* @param {"good" | "bad"} feedback
*/
const handleFeedback = (feedback) => {
const cookieName = `${FEEDBACK_COOKIE_PREFIX}_${window.location.pathname}`;
@ -105,15 +105,12 @@ export default function Feedback() {
return;
}
const feedbackType =
const feedbackEnv =
process.env.NODE_ENV === "production"
? "page_feedback"
: "page_feedback_dev";
gtag("event", feedbackType, {
url: window.location.pathname,
feedback,
});
gtag("event", `${feedbackEnv}_${feedback}`, {});
// Set a cookie to prevent feedback from being sent multiple times
setCookie(cookieName, window.location.pathname, 1);
setFeedbackSent(true);
@ -168,12 +165,12 @@ export default function Feedback() {
// Handle keyboard interaction
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
handleFeedback("yes");
handleFeedback("good");
}
}}
onClick={(e) => {
e.preventDefault();
handleFeedback("yes");
handleFeedback("good");
}}
>
<SvgThumbsUp />
@ -186,12 +183,12 @@ export default function Feedback() {
// Handle keyboard interaction
if (e.key === "Enter" || e.key === " ") {
e.preventDefault();
handleFeedback("no");
handleFeedback("bad");
}
}}
onClick={(e) => {
e.preventDefault();
handleFeedback("no");
handleFeedback("bad");
}}
>
<SvgThumbsDown />

View File

@ -1,7 +1,11 @@
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag("js", new Date());
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag("config", "G-9B66JQQH2F");
gtag('config', 'G-9B66JQQH2F');
// Only for feedback
function gtagFeedback(){dataLayer.push(arguments);}
gtagFeedback('js', new Date());
gtagFeedback('config', 'G-WFT0J048RF');