> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sightlineanalytics.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Netlify

> Integrate Siteline with Netlify Edge Functions

Use a [Netlify Edge Function](https://docs.netlify.com/edge-functions/overview/) 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

* A [Siteline website key](https://docs.sightlineanalytics.io/authorization.md)
* A Netlify site with [Edge Functions](https://docs.netlify.com/edge-functions/overview/) enabled

> [!NOTE]
>
> Netlify Edge Functions are available on all plans, including the **free tier**. See [Netlify Edge Functions](https://docs.netlify.com/edge-functions/overview/) for details.

## Setup

**1. Add the edge function**

Create an `edge-functions` directory in the root of your Netlify project and copy [`siteline.ts`](https://github.com/siteline-ai/siteline-js-sdk/blob/main/examples/netlify/edge-functions/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/core@1.0.9`) — 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:

```typescript theme={null}
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:

```toml netlify.toml theme={null}
[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](https://github.com/siteline-ai/siteline-js-sdk/blob/main/examples/netlify/edge-functions/siteline.ts).

## 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

> [accordion] No visits appearing in Siteline
>
> Verify `SITELINE_WEBSITE_KEY` is set to a valid key in `edge-functions/siteline.ts`. Confirm `netlify.toml` routes `/*` to `function = "siteline"`.

> [accordion] Edge function does not run on requests
>
> Ensure `[build] edge_functions = "edge-functions"` is present in `netlify.toml` and that the file exists at `edge-functions/siteline.ts`.

> [accordion] Will this slow down my site?
>
> No. Tracking is fire-and-forget — the tracking call is not awaited and never blocks the response.

> [accordion] Do I need to install any npm packages?
>
> No. The edge function imports `@siteline/core` via an ESM URL, which Netlify's Deno-based runtime resolves automatically.

> [!TIP]
>
> **Need help?** [Book a setup call](https://cal.com/team/siteline/tech-set-up) and we'll walk you through it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.