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.
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.
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.2
Add properties
Add one
data-cs-prop-<key> attribute per property. The part after data-cs-prop- is the property key.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.
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 withdata-cs-event, starting at the clicked element and walking up. - The innermost element wins. If elements with
data-cs-eventare 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()orevent.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.
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 fromdata-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() from JavaScript instead.
Examples
Track which plan a visitor picks on a pricing page:Next steps
Custom events in JavaScript
Send events with typed values and from code that runs on any action.
Outbound links and downloads
Track clicks on external links and files with one attribute on the script tag.
Events in the dashboard
Read counts, visitors and property breakdowns for each event.