Track custom user actions (Goals)
DataFast allows you to track specific user actions beyond pageviews, known as Goal (signup, newsletter subscribe, checkout initiated, etc.).
- This helps you understand what visitors do
- Unlock the Journey feature
- Improve the revenue predictions and conversion funnels
You can track goals using three methods:
1. Client-side tracking (simple)
Add a JavaScript snippet where the conversion occurs (e.g., on a "thank you" page after signup, when a user clicks a button, etc.).
Basic usage
window?.datafast("goal_name");
Rules for goal_name
:
- Use lowercase letters.
- Numbers, underscores (_), and hyphens (-) are allowed.
- Maximum 32 characters.
Advanced usage with custom parameters
Add an object with custom parameters to your goals for richer analytics in Journey:
window?.datafast("checkout_initiated", {
name: "Elon Musk",
email: "elon@x.com",
product_id: "prod_123",
});
Rules for custom parameters:
- Property names: lowercase letters, numbers, underscores (_), and hyphens (-) only. Max 32 characters.
- Property values: any string, max 255 characters.
- Limits: maximum 10 custom parameters per event.
2. HTML data attributes (simple)
Track goals automatically when users click on any element or submit any form with the data-fast-goal
attribute. This is the simplest way to track button clicks and form submissions.
Basic usage
<button data-fast-goal="signup_clicked">Sign Up</button>
In this example DataFast will send a goal with the name signup_clicked
.
Advanced usage with custom parameters
Add additional data-fast-goal-*
attributes to include custom parameters:
<button data-fast-goal="pricing_plan_selected" data-fast-goal-price="49" data-fast-goal-plan-type="pro">
Subscribe to Pro Plan
</button>
In this example DataFast will send a goal with the name pricing_plan_selected
and { price: '49', plan_type: 'pro' }
custom parameters.
Form submissions
DataFast automatically tracks form submissions if a data-fast-goal
attribute is added to the form element. DataFast will track the form submission event and include all form fields (except empty values and type=password
) as custom parameters.
<form data-fast-goal="contact_form_submitted">
<input type="text" name="email" />
<input type="text" name="name" />
<button type="submit">Submit</button>
</form>
In this example DataFast will send a goal with the name contact_form_submitted
and { email: '...', name: '...' }
custom parameters.
We skip fields with empty values and type=password
.
Rules for data attribute values:
- Goal names: same as JavaScript method (lowercase letters, numbers, underscores (_), and hyphens (-) only, max 32 characters)
- Parameter names: extracted from attribute name and converted from kebab-case to snake_case (e.g.,
data-fast-goal-product-id
→product_id
) - Parameter values: any string, max 255 characters (automatically sanitized)
- Maximum 10 custom parameters per event (same as JavaScript method)
Ensure reliable tracking (recommended)
Add this script to your HTML <head>
to guarantee events are captured even when triggered before the main script loads:
<script id="datafast-queue">
window.datafast = window.datafast || function() {
window.datafast.q = window.datafast.q || [];
window.datafast.q.push(arguments);
};
</script>
While easy to implement, client-side tracking might be less accurate due to ad blockers or network issues. For better reliability, use server-side tracking.
3. Server-side tracking (most accurate)
Track goals by sending data directly from your server using the DataFast API. This is the recommended method for accuracy.
- Get an API Key: Go to your Website Settings > API tab and create an API key to authenticate your requests.
- Send Goal data: Use the Goal API endpoint to send goal information from your backend whenever a user completes the desired action.
See the API documentation for creating goals for detailed implementation examples.
To track revenue specifically (e.g., completed purchases), use the dedicated revenue attribution setup instead of custom goals for payments. This provides more detailed financial analytics thanks to Stripe, LemonSqueezy, or Polar integration.
Billing
Custom goals count towards your DataFast monthly usage. Make sure to track only what you need. You can view your usage in your DataFast billing.