Skip to main content
Use a Netlify Edge Function to intercept requests at the edge and forward tracking data to Siteline using the @siteline/core SDK. The edge function proxies the request transparently, so there is zero impact on site performance.

Prerequisites

Netlify Edge Functions are available on all plans, including the free tier. See Netlify Edge Functions for details.

Setup

1

Add the edge function

Create an edge-functions directory in the root of your Netlify project and copy siteline.ts into it:
your-project/
├── edge-functions/
│   └── siteline.ts
└── netlify.toml
The function imports @siteline/core via an ESM URL (https://esm.sh/@siteline/[email protected]) — no npm install is needed since Netlify Edge Functions run on Deno.
2

Set your website key

Open edge-functions/siteline.ts and set the SITELINE_WEBSITE_KEY constant at the top of the file:
const SITELINE_WEBSITE_KEY = 'secret_key_...';
Optionally configure SITELINE_ENDPOINT and SITELINE_DEBUG.
3

Configure Netlify routes

Create or update netlify.toml in your project root:
netlify.toml
[build]
  edge_functions = "edge-functions"

[[edge_functions]]
  path = "/*"
  function = "siteline"
This routes every incoming request through the Siteline edge function.
4

Deploy

Deploy your site as usual. The edge function will begin tracking requests immediately.

How it works

The edge function runs as middleware on every matched request:
  1. A visitor (or AI bot) makes a request to your Netlify site
  2. The edge function calls context.next() to forward the request to your origin
  3. Tracking data (url, method, status, duration, userAgent, ref, ip, acceptHeader) is sent to Siteline asynchronously via fire-and-forget
  4. The response is returned to the visitor unmodified
If the downstream request fails, the function still tracks the request with status 500 before re-throwing the error. The SDK initializes lazily on the first request and reuses the instance for subsequent calls. View the full source on GitHub.

Configuration

SITELINE_WEBSITE_KEY
string
required
Your Siteline website key. If empty, tracking is disabled and a warning is logged to the console.
SITELINE_ENDPOINT
string
Siteline intake endpoint. Defaults to https://api.siteline.ai/v1/intake/pageview.
SITELINE_DEBUG
boolean
Enables debug logging. When true, errors in the edge function are logged to the console.

Troubleshooting

Verify SITELINE_WEBSITE_KEY is set to a valid key in edge-functions/siteline.ts. Confirm netlify.toml routes /* to function = "siteline".
Ensure [build] edge_functions = "edge-functions" is present in netlify.toml and that the file exists at edge-functions/siteline.ts.
No. Tracking is fire-and-forget — the tracking call is not awaited and never blocks the response.
No. The edge function imports @siteline/core via an ESM URL, which Netlify’s Deno-based runtime resolves automatically.
Need help? Book a setup call and we’ll walk you through it.