Goal Tracking

Track custom conversions and events with EngageTrack's goal system.

Goal Tracking

Goals let you track specific user actions — signups, purchases, button clicks, or any custom event that matters to your business.

HTML Data Attributes

The simplest way to track goals is with data-goal attributes on any HTML element:

<button data-goal="signup-click">Sign Up Free</button>
 
<a href="/pricing" data-goal="pricing-view">View Pricing</a>

When a user clicks the element, EngageTrack automatically fires a goal event.

JavaScript API

Plain JavaScript

Call window.engagetrack() directly or use the .track() alias:

// Simple goal
window.engagetrack("newsletter-subscribe");
 
// Goal with custom properties
window.engagetrack("purchase", {
	plan: "startup",
	interval: "yearly",
	amount: "29.99",
});
 
// Alternative .track() alias
window.engagetrack.track("newsletter-subscribe");

TypeScript / Next.js

Because the SDK is loaded via a <script> tag, TypeScript doesn't know about window.engagetrack. Add a declaration file to your project once and all usages will type-check correctly:

// engagetrack.d.ts  (place in your project root or src/)
declare global {
	interface Window {
		engagetrack: {
			(eventName: string, properties?: Record<string, string>): void;
			track: (eventName: string, properties?: Record<string, string>) => void;
			trackPurchase: (
				orderId: string,
				revenue: number,
				currency?: string,
			) => void;
			identify: (
				userId: string,
				traits?: {
					name?: string;
					email?: string;
					avatar?: string;
					custom?: Record<string, string>;
				},
			) => void;
			getVisitorId: () => string;
			getSessionId: () => string;
			ignore: () => void;
			unignore: () => void;
		};
	}
}
 
export {};

After adding the file, use window.engagetrack normally — no casts needed:

// In any component or event handler
window.engagetrack("signup_complete", { plan: "pro" });

Only call window.engagetrack in browser contexts. In Next.js, wrap calls in useEffect or check typeof window !== "undefined" before calling.

Goal names must be lowercase letters, numbers, underscores, or hyphens only — e.g. "signup_click", "add-to-cart". Uppercase letters and special characters are silently rejected by the SDK and the event is dropped.

Goal Properties

You can attach up to 10 custom properties to any goal using data-goal-* attributes:

<button
	data-goal="add-to-cart"
	data-goal-product="pro-plan"
	data-goal-price="49"
	data-goal-currency="EUR"
>
	Add to Cart
</button>

Properties are available in the dashboard under Goals → Properties for drill-down analysis.

Revenue Goals

Use engagetrack.trackPurchase() to record a purchase with revenue. This sends a dedicated purchase event with first-class revenue and currency fields:

window.engagetrack.trackPurchase("ORD-12345", 99.0, "EUR");
// signature: trackPurchase(orderId, revenue, currency)

Do not pass revenue as a regular goal property — it will be stored as a plain string and will not appear in revenue reports. Use window.engagetrack.trackPurchase() instead.

Revenue is automatically normalized to your site's base currency using daily exchange rates.

For payment providers with redirect flows (Stripe Payment Links, LemonSqueezy, Polar), the SDK auto-detects the purchase on the return URL via query parameters and fires the event for you — no extra code required.

Viewing Goal Data

Navigate to Dashboard → Goals to see:

  • Total completions over time
  • Conversion rate (completions / unique visitors)
  • Property breakdown for each goal
  • Revenue attributed to each goal (if applicable)