Webflow analytics in one prompt

undefined

Updated

To add analytics to a Webflow site, the tracker goes in the site-wide head code, and the site has to be published for it to go live. An agent can do both: connect Webflow's own MCP server next to AgentFirstStack, paste the prompt below, and the agent creates the analytics site, writes the tag into the head code, publishes and runs verify. One limit up front: Webflow hosting can't serve the tracker from your own domain, so visitors with an ad blocker aren't counted. Other platforms: add analytics with an AI agent.

Before you start

  • A plan that allows custom code. Webflow's head and body code needs a Core, Growth, Agency or Freelancer Workspace, or an active Site plan on the site.
  • Webflow's MCP server in your agent. It's at https://mcp.webflow.com/mcp and is available on every Site plan, the free Starter plan included. Add it to Claude Code, Cursor or Codex the way that tool adds remote servers, and sign in to Webflow when it asks.
  • An agent that can make HTTP requests, for AgentFirstStack's API (or its MCP server, https://agentfirststack.com/mcp).

The prompt

Paste this into your coding agent, with Webflow's MCP server connected

Add analytics to my Webflow site with AgentFirstStack. It's free, open-source analytics built for agents, and you can do the API side yourself: there is no signup form, and no email or verification is needed. 1. Read https://agentfirststack.com/llms.txt and https://analytics.agentfirststack.com/llms.txt. 2. If AGENTFIRSTSTACK_API_KEY is in this folder's .env, use it and read AGENTFIRSTSTACK.md. Otherwise get a key with one request: curl -X POST https://agentfirststack.com/v1/signup Save api_key in .env as AGENTFIRSTSTACK_API_KEY. Never put it in Webflow: everything in custom code is public. Name the project after the domain: PATCH https://agentfirststack.com/v1/me. 3. Create a site for the custom domain. Webflow hosting can't proxy a path to another server, so use the direct snippet. With Webflow's MCP tools, read the site's freeform head code first (get_site_freeform_code), append the snippet with data-forms="true" to whatever is there, write it back (set_site_freeform_code), and publish the site to the custom domain (publish_site). Note in AGENTFIRSTSTACK.md that ad blockers block analytics on this site. 4. Create goals for the main buttons and forms (form_submit events, or the thank-you page if a form redirects to one). Tell me which buttons to give a data-afsa-event custom attribute in the Designer. 5. Add an email destination, a weekly report, and alerts for a traffic drop and for no data. 6. After publishing, ask me to open the site once, then run verify and fix what it reports. 7. Write the site id and the env var name (never the key) in AGENTFIRSTSTACK.md, create a claim link with POST https://agentfirststack.com/v1/claim-link, then run GET https://agentfirststack.com/v1/setup?services=analytics and work through its next_steps until it says "ready": true. When you're done, tell me what you set up, how you verified it, and give me the claim link.

By hand, it's Site settings > Custom code > Head code (up to 50,000 characters), then Publish:

<script defer src="https://analytics.agentfirststack.com/s.js" data-site="site_..." data-forms="true"></script>

Webflow's MCP server reaches the same field. Its scripts tool can "read or write the freeform head and footer custom-code blocks", and set_site_freeform_code "replaces the block's content". That's why the prompt makes the agent read the block first and append: writing it blind would delete whatever other code you already have there. Webflow's MCP server also has publish_site, because custom code "won't go live until your site is published".

Two other ways an agent might reach for, and why not: registering s.js as a hosted script requires a fixed integrity hash of the file, which breaks the next time the tracker is updated; and Webflow's Custom Code REST endpoints only accept tokens from Webflow Apps, not site tokens. The freeform head block avoids both.

Why the direct snippet

On platforms that allow it, AgentFirstStack's tracker is served from the site's own domain through a small proxy, because ad blockers block analytics.agentfirststack.com. Webflow's hosting has no setting that forwards a path such as /_a/* to another server, and Webflow's help center says it "does not configure or support third-party proxies". So this guide uses the direct snippet, and visitors with an ad blocker aren't counted.

If your domain already runs through Cloudflare in Webflow's orange-to-orange setup (a paid Site plan), a Cloudflare Worker route on yourdomain.com/_a/* can serve the tracker first-party, with the code and key from GET /v1/sites/:id/install (first_party_proxy.cloudflare_worker). Webflow's docs note that orange-to-orange "is not a full reverse proxy" and that you may need Workers for path routing; you'd be running that Worker yourself, outside Webflow's support. Then change the head code's src to /_a/s.js.

Buttons and forms

Buttons and links. Select the element in the Designer, open its settings, and add a custom attribute named data-afsa-event with a value such as book_demo. A click then sends that event, with no script to write. Extra attributes named data-afsa-prop-plan and so on become event properties.

Forms. data-forms="true" on the script tag sends form_start when someone starts filling a form and form_submit when they submit it, with the form's id or name and never the field values. Webflow forms show a success message by default rather than going to a new page, so a pageview goal on a thank-you page only works if you set the form to redirect. Otherwise make an event goal: {"name":"Lead","type":"event","match":"form_submit"}. To count only submissions Webflow accepted, add a form webhook (form settings, Webhook) pointing at your own endpoint, and send the conversion from there as a server event.

Publish, then verify

  1. Publish to the custom domain. Unpublished changes, including custom code, aren't live.
  2. Open the site once in a normal browser. Headless browsers are filtered out unless the visit is marked with ?afsa_debug=1.
  3. Run verify: POST https://analytics.agentfirststack.com/v1/sites/:id/verify fetches your homepage, finds the tag, checks whether events arrived and lists fixes. The tag is in Webflow's published HTML, so verify also proves the domain.
  4. Run the setup check: GET https://agentfirststack.com/v1/setup?services=analytics until "ready": true.

Staging and preview stay out of your numbers. A site accepts events only from its domain and its subdomains. Visits to the yoursite.webflow.io staging address, and Designer preview on canvas.webflow.com (Webflow runs custom code in preview and comment modes), are dropped as hostname_not_allowed. That's usually what you want. If the site has no custom domain yet, create the analytics site for yoursite.webflow.io; webflow.io on its own is refused as a site domain because it's a shared suffix.

FAQ

Do I need a paid Webflow plan?

For custom code, yes: a Core, Growth, Agency or Freelancer Workspace, or a Site plan on the site. Webflow's MCP server itself works on every Site plan, including Starter.

Can the tracker be served from my Webflow domain?

Not by Webflow's hosting, which doesn't forward paths to other servers. With Cloudflare's orange-to-orange setup you can run a Worker route on /_a/* yourself; otherwise the direct snippet is the only option, and ad blockers block it.

Will the agent overwrite my existing head code?

Not if it follows the prompt. set_site_freeform_code replaces the whole block, so the prompt has it read the block first and append the tag.

Does it track visits to the webflow.io staging site?

No, as long as the analytics site is for your custom domain: events from other hosts are dropped and listed by verify. Add the staging host to allowed_hostnames if you do want it, together with your own domain.

Does the tracker use cookies?

No. By default a visitor is a hash of a daily salt, the site, the IP address and the user agent. Nothing is stored in the browser unless you switch the site to persistent mode.

Webflow is a trademark of Webflow, Inc. AgentFirstStack isn't affiliated with Webflow. Webflow details come from its help center and developer docs (custom code, staging subdomain, proxies, security headers, MCP server, MCP data tools, Custom Code API, custom attributes, forms), checked on 6 November 2026.