Skip to content

feat: add agent-analytics-starter example#1461

Open
Gdewilde wants to merge 4 commits intovercel:mainfrom
Gdewilde:add-agent-analytics-starter
Open

feat: add agent-analytics-starter example#1461
Gdewilde wants to merge 4 commits intovercel:mainfrom
Gdewilde:add-agent-analytics-starter

Conversation

@Gdewilde
Copy link
Copy Markdown

@Gdewilde Gdewilde commented Apr 19, 2026

Next.js 15 starter that tracks AI agent traffic (ClaudeBot, GPTBot, PerplexityBot, Google-Extended, and 20+ more) in PostHog via middleware. Drop in a PostHog key, deploy, and agent
fetches show up as doc_view events with is_ai_bot, source, and user_agent properties.

Demonstrates the full agent-readiness pattern:

  • /docs/[slug] serves HTML to browsers, clean Markdown to agents
  • Three triggers: .md suffix, Accept: text/markdown, known AI-bot UA
  • Content-Signal, x-markdown-tokens, and Vary headers on every Markdown response
  • Synthesized pointer document for routes without a pre-built mirror
  • public/llms.txt for agent discovery

Wires in the @apideck/agent-analytics npm package (MIT, zero deps).

Live demo: https://agent-analytics-nextjs-starter.vercel.app
Source repo: https://github.com/apideck-libraries/agent-analytics-nextjs-starter

Next.js 15 starter that tracks AI agent traffic (ClaudeBot, GPTBot,
PerplexityBot, Google-Extended, and 20+ more) in PostHog via middleware.
Drop in a PostHog key, deploy, and agent fetches show up as doc_view
events with is_ai_bot, source, and user_agent properties.

Demonstrates the full agent-readiness pattern:
- /docs/[slug] serves HTML to browsers, clean Markdown to agents
- Three triggers: .md suffix, Accept: text/markdown, known AI-bot UA
- Content-Signal, x-markdown-tokens, and Vary headers on every
  Markdown response
- Synthesized pointer document for routes without a pre-built mirror
- public/llms.txt for agent discovery

Wires in the @apideck/agent-analytics npm package (MIT, zero deps).
Live demo: https://agent-analytics-nextjs-starter.vercel.app
Source repo: https://github.com/apideck-libraries/agent-analytics-nextjs-starter

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mintlify-docs-rewrite Error Error Apr 19, 2026 8:48am

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 19, 2026

@Gdewilde is attempting to deploy a commit to the Vercel Examples Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 19, 2026

Deployment failed with the following error:

The `vercel.ts` schema validation failed with the following message: `rewrites[0]` missing required property `destination`

Learn More: https://vercel.com/docs/concepts/projects/project-configuration

@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 19, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​next@​15.5.1562100919870
Addednpm/​@​apideck/​agent-analytics@​0.3.07410010091100
Addednpm/​@​types/​node@​22.19.171001008195100

View full report

- turbo.json: standard monorepo build-pipeline config (build outputs
  under .next/**, excluding the cache) so Turbo can cache and parallelize
  this example alongside the others
- .npmrc: legacy-peer-deps=true to match the peer-dep tolerance other
  examples use (avoids conflicts with next@canary across the monorepo)
- package.json: bump @apideck/agent-analytics ^0.1.0 → ^0.1.1 so Socket's
  dep scan reports the current minor (0.1.1 adds bot_name as a captured
  property; semver range auto-upgraded but the explicit bump is tidier
  for supply-chain reports)

The mintlify-docs-rewrite deployment failure flagged by the Vercel bot
is a pre-existing issue in cdn/mintlify-docs-rewrite/vercel.ts on main
and is unrelated to this PR — we touch only edge-middleware/ files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
<h2>What&apos;s in this template</h2>
<ul>
<li>
<code>middleware.ts</code> — fires <code>trackDocView</code> on every
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<code>middleware.ts</code> fires <code>trackDocView</code> on every
<code>middleware.ts</code> fires <code>trackVisit</code> on every

UI text in app/page.tsx references the old function name trackDocView while middleware.ts uses the renamed trackVisit from @apideck/agent-analytics ^0.3.0.

Fix on Vercel

<!-- code -->
<g font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="14" font-weight="400">
<text x="24" y="72"><tspan fill="#c084fc">import</tspan><tspan fill="#9ca3af"> {</tspan></text>
<text x="24" y="94"><tspan fill="#e5e7eb"> trackDocView, posthogAnalytics</tspan></text>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hero.svg decorative code snippet shows the old function name trackDocView instead of trackVisit, mismatching the actual middleware code.

Fix on Vercel

**Swap analytics backends** — replace the PostHog adapter with a webhook, Mixpanel, or your own callback:

```ts
import { trackDocView, webhookAnalytics } from '@apideck/agent-analytics'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README, page.tsx, and hero.svg still reference the renamed trackDocView function which no longer exists in @apideck/agent-analytics ^0.3.0, causing broken copy-paste imports for users.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant