What are goals?
Goals are custom events that you want to track, such as:- Button clicks
- Form submissions
- Video plays
- File downloads
- Newsletter signups
- Product purchases
- Any custom user action
Create a goal
Goals are auto-created when you track them. You can also predefine goals in the dashboard:- Go to your website settings in the dashboard
- Click “Goals” in the sidebar
- Click “Create Goal”
- Enter:
- Name - A descriptive name (e.g., “Newsletter Signup”)
- Event - The event identifier (e.g., “newsletter_signup”)
- Description - Optional description
Reliable tracking (recommended)
Add this script to your HTML<head> to guarantee events are captured even when triggered before the main script loads:
Method 1: JavaScript
Simple goal (by name)
Goal with custom parameters
- Use lowercase letters
- Numbers, underscores (_), and hyphens (-) are allowed
- Maximum 64 characters
- Property names: lowercase letters, numbers, underscores (_), and hyphens (-) only. Max 64 characters.
- Property values: any string, max 255 characters.
- Maximum 10 custom parameters per event.
Goal with value
Method 2: HTML data attributes
Track goals automatically when users click elements with thedata-postmetric-goal attribute.
Simple button
With custom parameters
data-postmetric-goal-product-id → product_id).
Method 3: Server-side API
For best reliability (avoids ad blockers), track goals from your backend:Using the v1 API (requires API key)
Using the tracking endpoint (uses cookies)
Common goal examples
Form submission
Button click
Video play
File download
Test your setup
Visit/test-goals on your PostMetric instance to verify goal tracking works. Click the buttons to fire events and check your dashboard analytics.
Best practices
- Use descriptive event names - Use clear, consistent naming (e.g.
newsletter_signup, notns) - Track meaningful actions - Focus on actions that matter to your business
- Include values when relevant - Add numeric values for revenue-related goals
- Prefer server-side for critical events - Newsletter signups and purchases are more reliable when tracked from the backend
Next steps
Track conversion funnels
Learn how to track multi-step conversion funnels