From c7e9e8fa23607f85f1ee0b861fcaaeadfc38bd35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Wed, 22 Jan 2025 08:05:44 +0100 Subject: [PATCH] Add GA4 event to track when the "get-started" button is clicked --- docs/src/pages/index.jsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/src/pages/index.jsx b/docs/src/pages/index.jsx index e2157c6614..355d1704a1 100644 --- a/docs/src/pages/index.jsx +++ b/docs/src/pages/index.jsx @@ -62,6 +62,28 @@ function CompanyLogos() { ) } +function sendGA4EventOnLink( + event, + eventName, +) { + event.preventDefault() + + window.dataLayer?.push([ + 'event', + eventName, + { + event_callback: function () { + window.location.href + }, + }, + ]) + + // Fallback + setTimeout(() => { + window.location.href = event.target.href + }, 300) +} + function Home() { const context = useDocusaurusContext(); return ( @@ -79,6 +101,7 @@ function Home() {
sendGA4EventOnLink(event, 'click_get_started')} className={styles.btn} to={useBaseUrl("docs/tutorials/simple-todo-list/1-installation")}> Get started