DataSag guides · Updated 27 October 2026

Track custom events on Angular

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 Angular.

Start with the Angular installation

Inspect the Angular workspace project configuration to identify its index document, commonly src/index.html. Add the deferred external script once to the existing head and preserve the root element and build-managed assets. Build the intended application project and inspect its deployed output rather than a library package.

A workspace can contain several applications with different index files and build targets. Component templates and services should not repeatedly insert the global loader. For server rendering, keep browser API calls out of server execution.

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 Angular

  1. Use an Angular browser handler or successful observable result that confirms the intended action. A request starting, a form submit or a Router event is not automatically a completed signup.
  2. Keep the API typed and browser-scoped, especially if the app also runs SSR. Leave the loader in the selected index document rather than injecting another script from the component or tracking service.
  3. Test accepted and rejected results, then destroy and revisit the route. Confirm subscriptions are cleaned up and the success result emits one agreed event. Do not infer completion from a generic change-detection cycle.

The Angular browser action reports its confirmed result once and remains correct after route component destruction.

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' });

Use a goal attribute for click intent or a typed browser call after an Angular action succeeds. A router event or observable emission is only a completion event when its meaning actually confirms the business action.

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 Angular

The shared installation belongs in the head of the application index document selected by the build configuration. 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 Angular guides

Full Angular setup guide · Search and AI visibility

References

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