Track custom goals
Track signups, checkouts and any other action in Datasense with one function call or a data-ds-goal attribute, with up to 10 properties per goal.
A goal is any action you want to count: a signup, a checkout, a download. Goals show on the overview with completions, unique visitors and conversion rate.
From JavaScript
js
// After the action succeeds
window.datasense?.("signup", { plan: "pro" })
window.datasense?.("download", { file: "pricing.pdf", size: 120 })The optional chaining (?.) keeps your code working when an ad blocker stopped the script.
From HTML
Add data-ds-goal to any element. Clicks on it, or on anything inside it, record the goal. Every data-ds-goal-* attribute becomes a property:
html
<button data-ds-goal="checkout" data-ds-goal-plan="pro">Buy Pro</button>Before the script loads
Calls made before the script loads are queued if you add this stub first:
html
<script>
window.datasense = window.datasense || function () {
(window.datasense.q = window.datasense.q || []).push(arguments)
}
</script>Rules
- Goal names: up to 64 characters.
- Up to 10 properties per goal. Values must be strings, numbers or booleans; strings are cut at 255 characters.
- Goals count toward your monthly events, like pageviews.
Where goals show up
- The Goals card on the overview, with conversion rate.
- The Realtime feed, as they happen.
- Each visitor's timeline on the Visitors page.
- The goals endpoint and the
datasense_analytics_goals_breakdownMCP tool.