DataSag guides · Updated 27 October 2026
Track custom events on your website
Use data-datasag-goal for a click goal, or call window.datasag.track after a completed action. Choose a stable event name and distinguish a click from a successful conversion.
Before you start
Install the DataSag script once on the pages you intend to measure. Use the public key from the project you are inspecting. Publish your change, then test the public domain rather than relying on an editor preview.
Account credentials, database credentials and provider API keys do not belong in the tracking snippet. Keep existing consent controls in place. Report availability depends on your current plan and provider connections.
Track custom events: step by step
- Write the event definition first. For example, signup_click means a visitor pressed a signup link, while signup_completed means your application confirmed account creation.
- For click intent, add data-datasag-goal to the element. The tracker delegates clicks, so you do not also need a JavaScript handler for the same goal.
- For a completed action, call the JavaScript API in the success handler. Wait for the tracker to be available. An optional guard avoids a crash but intentionally drops the event if the tracker has not loaded.
- Send only the context needed for the report, such as a form or plan name. Do not include email addresses, passwords, payment details or freeform form contents.
- Complete one successful and one failed attempt. Inspect /api/track for the exact eventName and properties. Only the successful attempt should emit a completed-action event.
- Check the event report available to your plan. Collection and access to reports are separate; review current plan details before depending on a particular report.
<!-- Click intent: use this OR your own click handler -->
<a href="/signup" data-datasag-goal="signup_click">Create account</a>
// JavaScript: inside the confirmed-success handler
window.datasag?.track('signup_completed', { form: 'main_signup' });What a successful check looks like
A controlled successful action produces one event with the agreed name. A validation failure does not emit a success event. Network evidence matches the report definition.
Record the tested URL, date, browser state and observed request. Repeat on a nested page to check the shared installation. Keep the evidence so you can distinguish a later regression from a report-filter change.
Common mistake
A goal attribute on a submit button measures clicks, including attempts that fail. Do not report those clicks as completed signups or purchases.
Find your platform's installation point
- Next.js App Router
- Next.js Pages Router
- React with Vite
- Astro
- SvelteKit
- Nuxt
- WordPress
- Webflow
- Framer
- Shopify storefront themes
- Squarespace
- HTML websites
- Laravel Blade
- Django templates
- Flask with Jinja
- Ruby on Rails
- Express with EJS
- Remix v2
- Angular
- Vue with Vite
- Standalone Blazor WebAssembly
- PHP templates
- Gatsby
- Hugo
- Ghost
- Carrd
- Docusaurus
- VitePress
- Material for MkDocs
- Jekyll
- Eleventy
- Hexo
- Pelican
- Grav 1.7 Twig themes
- Drupal Twig themes