This document is a work in progress. If you feel there is information missing please email [email protected]
Refer to Event/property names reference – Datahappy for reserved event/property names.
<head>
section of each page on your website
If you already know the user's ID when initialising the SDK (e.g. in a server-rendered application where the user is already authenticated), you can provide it directly during initialisation:
datahappy.init('YOUR_PROJECT_ID', {
userId: 'user-123',
})
Let’s imagine you have a lead form on your website, built with Tally.
Here’s how you would detect a form submission, track the lead event with datahappy and then redirect to a thank you page on success.
<script>
window.addEventListener('message', function(e) {
if (e?.data && e.data.includes('Tally.FormSubmitted')) {
// prepare form data entered by the lead
const userTraits = e.data.reduce((obj, item) => {
obj[item.id] = item.value
return obj
}, {})
// track lead event
datahappy.trackLeadCreation({
userTraits,
eventProperties: {
value: 10,
currency: "GBP"
}
}).then(() => window.location.href = "/thank-you")
}
})
</script>