AlphaWe’re still building this tool. Results may be incomplete or inaccurate, and features may change.It’s publicly accessible so others can try it and share feedback.

Netlify Edge Functions

Use a Netlify Edge Function to stream HTML page views to AI Search Index. Works on any Netlify plan including free.

Works on Free, Pro, Business, and Enterprise plans
Zero-latency tracking with non-blocking requests
Runs on Deno at the edge, close to your visitors

Tracking Endpoint

POSTaisearchindex.com/api/v1/logs/custom
URL: https://aisearchindex.com/api/v1/logs/custom
Headers:
  X-API-Key: YOUR_BOT_TRACKING_KEY
  Content-Type: application/json

Required fields:
  timestamp, method, host, path, status_code, ip, user_agent

Edge Function Script

Create a new Edge Function at netlify/edge-functions/tracking.ts:

netlify/edge-functions/tracking.ts
/**
 * Netlify Edge Function – stream HTML page views to AI Search Index
 * Runs at the edge with zero-latency tracking using waitUntil.
 */

import type { Context } from "@netlify/edge-functions";

const TRACKING_KEY = "YOUR_BOT_TRACKING_KEY";
const TRACKING_ENDPOINT = "https://aisearchindex.com/api/v1/logs/custom";

// Skip common static assets and system paths
const SKIP_PATHS = ['/robots.txt', '/sitemap.xml', '/.well-known/', '/favicon.ico'];
const SKIP_EXT = /\.(js|css|png|jpg|jpeg|gif|svg|ico|woff2?|ttf|webp|pdf|mp4|webm|mp3|wav|ogg|json|xml|zip|rar|gz)$/i;

export default async function handler(request: Request, context: Context) {
  const url = new URL(request.url);
  
  // Skip static assets and system paths
  if (SKIP_EXT.test(url.pathname) || SKIP_PATHS.some(p => url.pathname.startsWith(p))) {
    return context.next();
  }
  
  // Build tracking payload with all required fields
  const payload = {
    timestamp: new Date().toISOString(),
    method: request.method,
    host: url.hostname,
    path: url.pathname + url.search,
    status_code: 200,
    ip: context.ip || request.headers.get('x-forwarded-for') || '',
    user_agent: request.headers.get('user-agent') || '',
    referer: request.headers.get('referer') || undefined,
  };
  
  console.log('[AIS] Sending tracking:', url.pathname);
  
  // Send tracking request asynchronously (non-blocking)
  context.waitUntil(
    fetch(TRACKING_ENDPOINT, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'X-API-Key': TRACKING_KEY,
      },
      body: JSON.stringify(payload),
    })
    .then(res => console.log('[AIS] Response:', res.status))
    .catch(err => console.error('[AIS] Error:', err.message))
  );
  
  return context.next();
}

export const config = { path: "/*" };

Configuration

Replace YOUR_BOT_TRACKING_KEY with your Bot Tracking Key from the dashboard.

VariableDescription
TRACKING_KEYYour Bot Tracking Key (e.g., bot_xxx...)
SKIP_PATHSArray of paths to exclude from tracking
SKIP_EXTRegex pattern for file extensions to skip

Deployment Steps

  1. 1

    Create Edge Functions Directory

    In your project root, create a folder named netlify/edge-functions/

  2. 2

    Add the Edge Function

    Create tracking.ts with the script above

  3. 3

    Update Your Tracking Key

    Replace YOUR_BOT_TRACKING_KEY with your actual key from the dashboard

  4. 4

    Deploy

    Push your changes to trigger a Netlify deployment. The Edge Function will be automatically detected.

Using Environment Variables (Recommended)

For better security, store your tracking key as an environment variable:

netlify/edge-functions/tracking.ts
// Use Deno.env to access environment variables
const TRACKING_KEY = Deno.env.get("AIS_BOT_TRACKING_KEY") || "";
const TRACKING_ENDPOINT = "https://aisearchindex.com/api/v1/logs/custom";

// ... rest of the script

Then set AIS_BOT_TRACKING_KEY in Netlify: Site settings → Environment variables → Add variable

Project Structure

your-project/
├── netlify/
│   └── edge-functions/
│       └── tracking.ts    ← Edge Function
├── src/                   ← Your site source
├── public/
└── netlify.toml           ← Optional config

Optional: netlify.toml Configuration

You can also configure the Edge Function path in netlify.toml:

netlify.toml
[[edge_functions]]
  path = "/*"
  function = "tracking"

Edge Functions vs Log Drains

FeatureEdge FunctionsLog Drains
Plan RequiredFree and abovePro and above
Setup ComplexityAdd code fileDashboard config
CustomizationFull controlLimited
Latency ImpactNone (async)None

Tip: If you're on a Netlify Pro plan or higher and prefer a no-code solution, you can also use Netlify Log Drains.

Need help?

If you run into issues, check our support resources or contact us.

Get Support