This guide will walk you through the two essential steps to get started with Datahappy: installing the Pixel and sending your first event.

1. Install the Pixel

The Datahappy Pixel is a small JavaScript snippet that you add to the <head> section of your website. It asynchronously loads the full SDK without impacting your page load times.
  1. Copy the code snippet below
  2. Paste it into the <head> tag of your website’s HTML, just before the closing </head> tag
  3. Replace YOUR_PROJECT_ID with your actual Project ID from the Datahappy dashboard
<script>
  // prettier-ignore
  !function(){let e=window.datahappy=window.datahappy??{};if(e.initialised)return;if(e.invoked)return console.error("[Datahappy] Snippet included multiple times");e.invoked=!0;let t={};e.ready=new Promise((e,a)=>{t.resolve=e,t.reject=a}),e.ready.resolve=t.resolve,e.ready.reject=t.reject,e.buffered=[],e.initArgs=null,e.init=function(){return e.initArgs=Array.prototype.slice.call(arguments),e.ready},["updateConsent","updateIdentity","page","track","reset"].forEach(t=>{e[t]=function(){let a=Array.prototype.slice.call(arguments);a.unshift(t),e.buffered.push(a)}}),e.load=t=>{let a=(t=t||"https://cdn.datahappy.co/sdk/v0.8/datahappy.js").match(/.+sdk\/v?(.+)\/datahappy.js/);null!==a&&a.length>=2&&(e.version=a[1]);let r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src=t,(document.head||document.body).appendChild(r)}}()

  datahappy.load()
  datahappy.init("YOUR_PROJECT_ID")
  datahappy.page()
</script>
The snippet automatically initialises the SDK and tracks the first page view for you. For more details, see the Installing the Pixel guide.

2. Send a Test Event

Once the Pixel is installed, you can send events from anywhere in your application’s frontend code. Use the datahappy.track() method to send a custom event. For example, you could track a signup_completed event when a new user registers.
datahappy.track({
  event: "signup_completed",
  userId: "user-123",
  traits: {
    email: "hello@example.com",
    name: "Alex Smith",
  },
})
That’s it! You’ve successfully installed the Pixel and sent your first event. You can now view your live data in the Datahappy dashboard.

Next Steps

Now that you have the basics in place, you can explore the core concepts that make Datahappy powerful.