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
You can track goals using two methods:
1. Client-side tracking (simple)
Add a JavaScript snippet where the conversion occurs (e.g., on a "thank you" page after signup).
<script>
window?.datafast("goal_name", {
description: "A short description of the event",
});
</script>
Rules for goal_name
:
- Use lowercase letters.
- Numbers, underscores (_), and spaces are allowed (spaces will be converted to underscores).
- Maximum 32 characters.
description
is optional. Use it to add more context about the goal for better insights.
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.
2. 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. You'll need the
visitorId
(available from thedatafast_visitor_id
cookie) andgoal_name
.
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 integration.