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.

Integration


Steps

  1. Add the datahappy pixel high up in the <head> section of each page on your website
  2. Add a line of code for each event – see SDK reference below

Initialising with a User ID

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',
})

Event example

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>