Skip to content

Commit

Permalink
Merge pull request #1298 from FoalTS/add-ga4-event
Browse files Browse the repository at this point in the history
Add GA4 event to track when the "get-started" button is clicked
  • Loading branch information
LoicPoullain authored Jan 22, 2025
2 parents 7a36afd + c7e9e8f commit e973676
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/src/pages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -79,6 +101,7 @@ function Home() {
</h3>
<div>
<Link
onClick={(event) => sendGA4EventOnLink(event, 'click_get_started')}
className={styles.btn}
to={useBaseUrl("docs/tutorials/simple-todo-list/1-installation")}>
Get started
Expand Down

0 comments on commit e973676

Please sign in to comment.