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", src: "https://www.googletagmanager.com/gtag/js?id=G-9B66JQQH2F",
async: true, 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) { export default function gtag(...args) {
if (window.gtag) { if (window.gtagFeedback) {
window.gtag(...args); window.gtagFeedback(...args);
} }
} }

View File

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

View File

@ -1,7 +1,11 @@
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag() { function gtag(){dataLayer.push(arguments);}
dataLayer.push(arguments); gtag('js', new Date());
}
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');