# Next.js boilerplate with DataFast

> Revenue-first web analytics. The DataFast script loads from your own origin after hydration. A route handler forwards events, so ad blockers have no hostname to match. Goals are typed against a catalogue and stripped of personal data. Server-side goals go through the Goals API after the response. With Stripe, Polar or Dodo selected, every checkout carries the visitor id in its metadata. Revenue lands on the channel that earned it.

Web analytics that tells you which channel made money, not just which one made visits.

- **Category:** Analytics
- **Pricing:** No free plan. A 14-day trial with no card. Starter is $9/month (1 site, 1 team member) and Growth $19/month (30 sites, 30 team members), both at 10k monthly events. Go over and tracking continues, but you must upgrade to open the dashboard. API, CLI and MCP access are on both plans.
- **Best for:** Indie hackers and small SaaS teams who want one answer: which referrer, campaign or page produced revenue. Checkout attribution is wired for Stripe, Polar and Dodo. One script tag, no event plan needed on day one.
- **Conflicts with:** posthog
- **Vendor docs:** https://datafa.st/docs

## Trade-offs

- It is web analytics, not product analytics. Page views, referrers, goals and revenue. No session replay, no feature flags, no cohorts over custom person properties. Pick PostHog if you need those.
- Attribution depends on one cookie. The checkout must carry the `datafast_visitor_id` from the same browser that visited, which is what the `checkout-attribution` slot does. Payments made on another device, or before consent, land as direct traffic.
- Goal parameters are capped at 10 per event and 255 characters per value, all stored as strings. Typed properties are converted for you; numbers you want to sum belong in your database.
- Every goal counts toward your monthly event quota. Track decisions, not every click.
- The script writes a first-party cookie for a year. In the EU and the UK that needs consent. `src/lib/analytics/consent.ts` ships a gate you must switch on before you serve traffic there.

## Known fixes it ships

- [Cookie consent for DataFast in Next.js without breaking attribution](https://agenticboilerplate.com/cookbook/datafast/cookie-consent-for-datafast): DataFast sets a year-long first-party cookie, which needs opt-in consent in the EU and UK. Gate the script render, the goal queue and the checkout metadata on one flag.
- [DataFast shows nothing on localhost? That is on purpose. How to debug it anyway](https://agenticboilerplate.com/cookbook/datafast/datafast-not-tracking-localhost): The script skips localhost, 127.0.0.1, .local hosts, iframes and browsers flagged with datafast_ignore. Turn on data-allow-localhost for a session, check the network tab, then turn it off.
- [DataFast goals versus page views, and when you need neither](https://agenticboilerplate.com/cookbook/datafast/goals-vs-pageviews): Page views are free and automatic. Goals cost events and need a name, a reason and a side of the network. A decision table, the naming rule, and what never to put in a goal.
- [Proxy DataFast through your Next.js domain so ad blockers stop eating visits](https://agenticboilerplate.com/cookbook/datafast/proxy-datafast-through-nextjs): Blockers match the datafa.st hostname. Serve the script and the events endpoint from your own origin with two route handlers, and forward the visitor's IP.
- [DataFast shows revenue as direct traffic? Pass the visitor id into checkout metadata](https://agenticboilerplate.com/cookbook/datafast/revenue-attribution-checkout-metadata): DataFast attributes a payment by reading datafast_visitor_id from the checkout's metadata. Read the cookie on the server when you create the Stripe, Polar, Lemon Squeezy or Dodo checkout.
- [Server-side DataFast goals from Next.js, and why the Goals API returns 404](https://agenticboilerplate.com/cookbook/datafast/server-side-goals-api): Send goals from route handlers and server actions with POST /api/v1/goals, after the response. The visitor id comes from the request cookie, and it must already have a page view.

## Generate it

[Build a repo with DataFast](https://agenticboilerplate.com/build?b=datafast)

---

Agentic Boilerplate: A Next.js repo your agent already knows. Free during launch, then $99 once.

- Site map for agents: https://agenticboilerplate.com/llms.txt
- Public API: https://agenticboilerplate.com/openapi.json
- Contact: agenticstudio@gmail.com
