Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GA4 event to track when the "get-started" button is clicked #1298

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading