How to Install Bubblegum: Developer Guide (Vercel Edition)

Introduction

Modern AI tools like ChatGPT, Perplexity, and Claude are becoming key discovery engines — crawling, interpreting, and recommending brand content. To ensure these tools interpret your site accurately, Bubblegum offers a lightweight middleware solution.

This comprehensive guide covers the complete setup and deployment process for Bubblegum Middleware for Vercel-hosted sites.


What is Middleware?

AI agents are now an important segment of web traffic, discovering, indexing, and interacting with your digital content. This middleware acts as an intelligent router – seamlessly directing recognized AI bot traffic to AI-optimized, relevant pages while serving regular visitors as normal.

What are the key benefits?
  • AI Traffic Middleware: Detects AI bots using advanced user-agent filtering and pattern recognition

  • Seamless Routing: AI or LLM bot requests are routed to special "AI-ready" content (Markdown, structured data endpoints, etc.) set by your team

  • Multi-model Ready: Routes can be adapted or extended for different bot types (OpenAI, GoogleBot-AI, Perplexity, Claude, social/chat bots, etc.)

  • No Impact on UX or SEO: Human visitors and standard search engine crawlers are unaffected.

  • Comprehensive Logging: All routes, bot hits, and errors are logged for analytics


How It Works

1

Interception

The Middleware sits between your domain and all incoming traffic

2

Bot Detection

Each request's user-agent (and optionally headers) are checked against a curated list of bot patterns, including major LLMs, scrapers, and headless browsers

3

Dynamic Routing

  • AI bot requests: Redirected to an AI-ready version of the content (e.g., /about becomes /about.md)

  • Non-bot traffic: Served as usual with no disruption or latency


Setup Instructions (Vercel Projects)

Bubblegum supports two integration approaches for Vercel projects, depending on your framework and routing needs:

1. Using vercel.json (Framework Agnostic)

Works for any site hosted on Vercel, including static sites, non-Next.js frameworks, and custom setups.

Pros:

  • Framework agnostic: You don’t need Next.js or any specific tech stack.

  • Simple setup: One file, predictable rewrite rules.

Cons:

  • No fallback logic: If a page isn’t available in .md AI-optimized form, the bot will not get a fallback version.

  • Requires coverage: You'll need to ensure all intended pages are provided as .md versions.

How to Setup

  1. Add a vercel.json file at the root of your project, or update your existing one:

  1. Commit and Deploy:

  • Commit your changes and trigger a redeploy in Vercel.

  • The rules are picked up automatically, no additional code is required.

2. Next.js Middleware Approach (Fine-Grained Control)

Gives you flexible, programmatic control—ideal for Next.js projects.

Pros:

  • Supports fallback logic: If a page doesn’t exist in .md, bots get standard site content as a fallback.

  • Customizable: Define bot detection, logging, IP range controls, etc.

Cons:

  • Requires basic knowledge of Next.js middleware/configuration.

How to Setup

  1. Add this middleware.ts file at the root of your Next.js project:

middleware.ts

  • All the code you provided, including helper functions, bot logic, config, and AI routing, should be copied verbatim.

  1. Add this auto-generated ai-ip-addresses.ts at the project root:

ai-ip-addresses.ts

  • This ensures known bot IP detection stays current.

  • File will be updated as new AI services are onboarded.

  1. BUBBLEGUM_AI_URL:

  • The AI routing URL will be provided via onboarding, or you can request this from [email protected].

  1. Commit and Deploy (Agnostic):

  • Once both files are added/updated, commit changes and redeploy as usual.

  • The rules are picked up automatically, no additional code is required.


How to Test

To verify that bot redirects are working as expected:

  1. Use a tool like curl or Postman

  2. Send a request with one of the bot user-agent headers (e.g. GPTBot)

  3. Confirm the request is rewritten to the .md version hosted on your Bubblegum domain

Need help generating a test command? Reach out to us at [email protected]


Decision Table: Which Option Should You Use?

Approach
Works For
Fallback
Customization Level
Recommended For

vercel.json

Any Vercel site

Basic rewriting

Static sites, non-Next.js

Next.js middleware

Next.js only

Advanced (logging, IPs, custom routing)

Next.js, hybrid, or dynamic sites

Additional Resources


Frequently Asked Questions:

Q: Can I customize bot traffic destinations?

A: Yes. The middleware is fully configurable. You can define which AI-ready content (like Markdown files or structured endpoints) each AI bot should be routed to, allowing for granular control by page or bot type.

Q: How does the new markdown content work with our existing website and code?

A: You don’t need to change your site or code. We use something called “middleware” that runs through Cloudflare. It simply detects if a request is coming from a bot (like ChatGPT or Perplexity) and, if so, shows them your AI-optimized content. Regular visitors still see your usual site.

Q: Can I see which AI bots are visiting my storefront and what pages they access?

A: Yes. All bot hits and route matches are logged by the middleware. You can use this data to analyze AI bot traffic patterns, page-level access, and even export this for analytics dashboards.

Q: How do I test the routing for different types of AI bots before going live?

A: You can simulate bot traffic by using tools like curl or Postman and setting the User-Agent header to match known AI bots (e.g., ChatGPT, Claude, PerplexityBot). This allows you to verify detection and routing without deploying to production.

Q: Can I segment analytics to see where AI-driven purchases or conversions originate?

A: Yes, if you integrate the middleware logs with downstream analytics tools (e.g., Segment, GA4, or custom attribution systems), you can isolate AI-sourced traffic and measure downstream conversions or revenue impact.

Q: What happens if a bot is misidentified or a legitimate customer is mistaken for an AI bot?

A: The bot detection logic is carefully curated and updated to minimize false positives. In the rare case of misidentification, fallback behavior is non-disruptive—most misrouted users would still see product content, just via the AI-ready page.

Q: How does this work with my existing CDN, headless commerce platform, or CMS?

A: The middleware runs at the Cloudflare edge, before any request reaches your origin or CMS. This means it is compatible with any platform (e.g. Shopify, Contentful, Sanity, BigCommerce) without needing backend changes.

Q: Are there risks to privacy or customer data when directing bot traffic?

A: No. The middleware only affects bots—it does not expose any private customer data or session-specific content. AI-ready pages are typically static or structured summaries, ensuring privacy is maintained.

Last updated

Was this helpful?