Track Events
Send custom events and conversions from your app.
X-Ray records pageviews automatically. Clicks, form submits, outbound links and web vitals are captured too while they're on under What X-Ray collects on Tracking > Setup, as they are by default. Shopify installs record pageviews and store events only. Add explicit tracking for conversion events that should feed campaign reports and ad platform postbacks.
Conversion events
Use the cv constant for type-safe conversion names. Import it from @hellyeah/x-ray in client code or @hellyeah/x-ray/server in server code.
import { cv, track } from "@hellyeah/x-ray";
track(cv.leadSubmit, {
plan: "pro",
});
track(cv.purchase, {
revenue: 49.99,
currency: "USD",
});cv.purchase sends "cv_purchase", cv.leadSubmit sends "cv_lead_submit", and the typed constants prevent typos that would otherwise break ad platform postbacks.
Script tag
For a script-tag install, queue the conversion once it has completed, for example on the confirmation page. The queue keeps the event until the deferred tracker script loads:
window._hy = window._hy || [];
window._hy.push(["track", "cv_purchase"]);To send a custom event when a visitor clicks an element, add data-hy-event with the event name. Each data-hy-prop-* attribute becomes an event property:
<button data-hy-event="pricing_viewed" data-hy-prop-plan="pro">See pricing</button>Do not use data-hy-event for conversion events. It fires on click, before any validation, payment or success check, so failed attempts would count as conversions.
For Google Tag Manager, put the same queue call in a Custom HTML tag fired by the trigger that means the conversion completed. The tracker runs queued commands once it loads, and runs later pushes at once:
<script>
window._hy = window._hy || [];
window._hy.push(["track", "cv_registration_complete"]);
</script>Server events
Use the server import for webhooks, background jobs, and API routes.
import { XRay, cv } from "@hellyeah/x-ray/server";
const xray = new XRay("your-website-id");
await xray.trackImmediate(cv.purchase, {
revenue: 49.99,
currency: "USD",
distinctId: "user-123",
});Conversion events appear in campaign reports and help Hellyeah understand what happened after the ad click.
Custom events
Custom events are available for product-specific behavior that is not a conversion. Keep them secondary to typed conversion events.
import { track } from "@hellyeah/x-ray";
track("pricing_viewed", {
plan: "pro",
});Naming rules
- Use
snake_case - Keep names stable
- Use
cvconstants for business outcomes - Put details in properties instead of creating too many event names