DataSag guides · Updated 27 October 2026

Track custom events on Vue with Vite

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 Vue with Vite.

Start with the Vue with Vite installation

Add one deferred external script to the root index.html used by the Vue Vite app. Keep it outside single-file components and preserve the application mount element and module entry. Build and publish the correct Vite application so the HTML visitors receive contains the project key.

An onMounted loader inside a route component can execute again when that component is recreated. Keep loading in the document rather than adding a new tracker through watchEffect or a route watcher. Inspect SSR-specific execution separately if your app adds server rendering.

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 Vue with Vite

  1. Use the Vue component method that receives a successful action response. A computed property or watchEffect can rerun for unrelated reactive updates, so it should not define a one-time conversion by rendering state alone.
  2. Call the typed optional browser API after that outcome and leave loading in index.html. For click intent, use a goal attribute or your click handler, but do not report the same goal through both.
  3. Test successful and failed actions and repeat after route unmount and remount. Check for one named payload per confirmed result. Clean up any manually attached DOM listener through the owning component lifecycle.

The Vue action handler emits one accurate event without relying on repeated reactive evaluation.

Complete the collection checks

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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 API from the successful browser action in the Vue component. Do not use a computed property or watchEffect to report a one-time business outcome. Keep a typed optional browser API if using TypeScript.

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 Vue with Vite

The shared installation belongs in the head of the Vite application root index.html. Use this as the installation reference while checking the procedure above.

<script defer src="https://www.datasag.com/tracker.js" data-datasag-key="YOUR_PUBLIC_KEY"></script>

Related Vue with Vite guides

Full Vue with Vite setup guide · Search and AI visibility

References

Official Vue with Vite documentation covers the integration point. For DataSag data handling, read the privacy policy. Use support if a request fails after these checks.