Data attributes Pro

Wire up click tracking directly from HTML — no JavaScript required. Mark any element with data-clamp-eventand Clamp captures clicks on it as a custom event. Ideal for marketing pages, CMS-driven content, A/B test variants, and anywhere a developer isn’t on standby.

Enable

init
init("proj_xxx", { extensions: { dataAttributes: true } })

// or, in React:
<Analytics projectId="proj_xxx" extensions={{ dataAttributes: true }} />

How it works

A single delegated click listener is attached to document. When a click happens, Clamp walks up the DOM from the click target and looks for the nearest ancestor with a data-clamp-event attribute. If found, it fires track(eventName, props).

Examples

Simple click
<button data-clamp-event="signup_click">Get started</button>
// → track("signup_click")
With properties
<a
  href="/pricing"
  data-clamp-event="pricing_view"
  data-clamp-source="hero"
  data-clamp-variant="control"
>
  See pricing
</a>
// → track("pricing_view", { source: "hero", variant: "control" })
With Money
<button
  data-clamp-event="checkout_clicked"
  data-clamp-plan="pro"
  data-clamp-money-price="29.00 USD"
>
  Start on Pro — $29/mo
</button>
// → track("checkout_clicked", {
//     plan: "pro",
//     price: { amount: 29, currency: "USD" }
//   })
Wrapping a complex element
<button data-clamp-event="cta_click" data-clamp-location="nav">
  <svg>...</svg>
  <span>Start free</span>
</button>
// Clicks on the svg or span both fire the event — Clamp walks up to the button.

When to use this vs track()

Gotchas