> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Track clicks with data-cs-event attributes

> Send a CrispStats custom event when someone clicks an element by adding data-cs-event and data-cs-prop-* attributes in HTML, without writing any JavaScript.

To track clicks without JavaScript, add a `data-cs-event` attribute to any element. When someone clicks the element, or anything inside it, the CrispStats script sends a custom event with that name. Each `data-cs-prop-*` attribute on the same element becomes a property of the event.

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<button data-cs-event="add to cart" data-cs-prop-sku="tee-01" data-cs-prop-price="19">
  Add to cart
</button>
```

A click on this button sends the event `add to cart` with the properties `sku: "tee-01"` and `price: "19"`. It is the same event as calling `crispstats("add to cart", { sku: "tee-01", price: "19" })`, and it shows under **Events** in the dashboard like any other [custom event](https://docs.crispstats.com/track/custom-events.md).

## Add an event to an element

**1. Name the event**

Add `data-cs-event` with the event name to the element people click: a button, a link, a card, a list item.

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<a href="/pricing" data-cs-event="pricing cta">See pricing</a>
```

**2. Add properties**

Add one `data-cs-prop-<key>` attribute per property. The part after `data-cs-prop-` is the property key.

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<a href="/pricing" data-cs-event="pricing cta" data-cs-prop-location="hero">See pricing</a>
```

**3. Click it and check the dashboard**

Deploy the change, click the element on your live site, then open **Events** in the dashboard. Select the event to see its properties. To test on your own machine, see [localhost and testing](https://docs.crispstats.com/tracking/localhost-and-testing.md).

## How clicks are matched

* **Clicks inside the element count.** A click on an icon or a `<span>` inside a `<button data-cs-event="…">` sends the button's event. The script looks for the closest element with `data-cs-event`, starting at the clicked element and walking up.
* **The innermost element wins.** If elements with `data-cs-event` are nested, a click sends only the event of the closest one, with only that element's properties.
* **Stopped clicks still count.** The script listens for clicks on the window in the capture phase, so the event is sent even when a handler on the page calls `event.stopPropagation()` or `event.preventDefault()`.
* **Elements added later work.** Nothing is attached to each element, so content rendered by a framework after the page loads is tracked without extra setup.
* **Navigation does not lose the event.** The event is sent with `navigator.sendBeacon`, so a link that leaves the page still reports its click.
* **Only clicks are tracked.** A keyboard press that activates a button or link fires a click and counts. Middle clicks, hovers and focus do not.

Declarative events are part of the core tracker. They work with `d.js` and with the smaller `d.core.js` build, with no extra attribute on the script tag.

## Property values and keys

Attribute values are text, so every property sent from `data-cs-prop-*` is a string. `data-cs-prop-price="19"` sends `"19"`, not the number `19`, and `data-cs-prop-trial="true"` sends `"true"`. If you need a number or a boolean, call [`crispstats()`](https://docs.crispstats.com/track/custom-events) from JavaScript instead.

| Rule | Detail |
| - | - |
| Key | Everything after `data-cs-prop-`. HTML lowercases attribute names, so `data-cs-prop-planName` sends the key `planname`. Use lowercase keys, with hyphens if you like: `data-cs-prop-plan-name` sends `plan-name`. |
| Value | Always a string, cut to 500 characters. An attribute with no value sends `""`. |
| Name length | Up to 120 characters. A longer name drops the event. |
| Key length | Up to 60 characters. A longer key drops the event. |
| Count | Up to 40 properties per event are kept. |
| Empty name | `data-cs-event=""` sends nothing. |

## Examples

Track which plan a visitor picks on a pricing page:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<div class="plans">
  <a href="/signup?plan=starter" data-cs-event="plan selected" data-cs-prop-plan="starter">Choose Starter</a>
  <a href="/signup?plan=growth" data-cs-event="plan selected" data-cs-prop-plan="growth">Choose Growth</a>
</div>
```

Track a whole card, including clicks on its image and text:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<article data-cs-event="template opened" data-cs-prop-template="blog">
  <img src="/templates/blog.png" alt="Blog template" />
  <h3>Blog</h3>
  <p>A clean starting point for writing.</p>
</article>
```

Use the attributes from a component framework. They are plain HTML attributes, so they pass straight through JSX, Vue and Svelte templates:

```tsx theme={"theme":{"light":"github-light","dark":"github-dark"}}
export function DemoButton() {
  return (
    <button type="button" data-cs-event="demo requested" data-cs-prop-source="navbar">
      Book a demo
    </button>
  );
}
```

## Next steps

> [card] [Custom events in JavaScript](https://docs.crispstats.com/track/custom-events.md)
>
> Send events with typed values and from code that runs on any action.

> [card] [Outbound links and downloads](https://docs.crispstats.com/track/outbound-links-and-downloads.md)
>
> Track clicks on external links and files with one attribute on the script tag.

> [card] [Events in the dashboard](https://docs.crispstats.com/dashboard/events.md)
>
> Read counts, visitors and property breakdowns for each event.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.