DataSag guides · Updated 27 October 2026
Track custom events on Nuxt
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. This guide applies to Nuxt.
Start with the Nuxt installation
Add one external script entry to app.head.script in nuxt.config.ts. Merge it into existing head settings rather than replacing them. The public project key is intended for the browser; it is not a server credential.
Check whether a plugin or useHead call already installs the same tracker. A server route cannot access window.datasag. Use browser handlers and retain your app's existing consent controls.
Use the public project key from the DataSag project you are inspecting. A test on a preview domain does not confirm that the production domain has the same code or settings.
Track custom events in Nuxt
- Place the event call in the client-side Vue handler that knows the action succeeded. Do not access window while an SSR setup function evaluates or inside a server API route.
- Keep the global script configured in nuxt.config.ts and use an optional typed API from the action code. If you wrap the API in a client plugin, make that wrapper consume the existing tracker rather than inject another copy.
- Test a successful action, a validation failure, and the same action after Nuxt client navigation. Inspect the named payload and check that page remounts or watchers do not invoke the success event again.
The client action reports confirmed success once without introducing SSR errors or another tracker installation.
Complete the collection checks
- 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' });Invoke the tracker in a client-side Vue handler after success. Do not put browser globals in an SSR setup path without a client guard.
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 public path you tested, the browser state, the approximate time and the observed request. Check one direct page load and one later navigation so the result covers more than the homepage.
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.
Installation snippet for Nuxt
The shared installation belongs in the app head configuration in nuxt.config.ts. Use this as the installation reference while checking the procedure above.
export default defineNuxtConfig({
app: {
head: {
script: [{
src: "https://www.datasag.com/tracker.js",
"data-datasag-key": "YOUR_PUBLIC_KEY",
defer: true
}]
}
}
});Related Nuxt guides
References
Official Nuxt documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.