AI Visibility Installation Examples
Set up AI Visibility on Cloudflare, Next.js, Express, Netlify, AWS CloudFront, Azure Front Door, or a custom Shopify storefront.
See which AI agents and crawlers reach your public pages by forwarding request metadata from your CDN or server. Choose the example that matches the layer you can configure.
| Your setup | Where to collect |
|---|---|
| Cloudflare | Hardal's generated Worker on your website route |
| Next.js / Vercel | Hardal's generated Next.js Proxy on your page routes |
| Node.js / Express | Hardal's generated middleware on your application server |
| Netlify | A custom Edge Function that calls the Hardal HTTP API |
| AWS CloudFront | Real-time access logs with a custom Kinesis consumer |
| Azure Front Door | Access logs with a custom Event Hubs consumer |
| Shopify | A headless storefront's CDN or server, when it can read the original request |
Before you start
In the Hardal Dashboard, open Manage → Setup, find your source, and open its Setup page. Expand AI Visibility to copy your collection URL, Tenant ID, Source ID, and generated example. Choose one forwarding path for each website request to avoid counting the same visit twice. Scope collection to public page routes.
Use the original client IP from the platform or a trusted proxy. If a CDN serves a page without contacting your application server, middleware at the origin cannot record that request. Use AI Visibility Setup for the request fields and Send Agent Events for the HTTP API reference.
Cloudflare Workers
- Copy the Cloudflare example from Hardal. In Workers & Pages, create a Worker or add forwarding to your existing Worker handler.
- Add a Worker route on the proxied website hostname you control. For example, use
www.example.com/docs/*for documentation pages. Keep the collection hostname separate from the website route. - Check the Worker logs for forwarding failures, then verify a crawler visit in Hardal.
Next.js on Vercel
- On Next.js 16 or later, copy the generated Next.js example into
proxy.tsat the same level asapporpages. If you already use Proxy for routing or authentication, add forwarding to the existing handler and preserve its behavior. - Make sure the matcher includes your public page routes. On Vercel, check the client IP that reaches Proxy, especially if another reverse proxy sits in front of Vercel.
- Check a deployed route that matches your Proxy configuration, then verify a crawler visit in Hardal.
Node.js and Express
- Copy the generated Node.js example. Register
app.use(hardalAgentEvents)before the public page routes you want to measure. - If Express is behind a reverse proxy, configure trusted proxies to match your network. Verify that
req.ippoints to the original client rather than the proxy. - Check an incoming request that reached Express, then verify a crawler visit in Hardal. For page requests served entirely from a CDN cache, collect at the CDN.
Netlify Edge Functions
Create netlify/edge-functions/hardal-agent-events.js in your Edge Functions directory. Replace the collection URL and IDs and update config.path to match your public page routes. The function uses Netlify's request context to read the client IP and send the event in the background.
const endpoint = "https://analytics.example.com/agent-events";
const tenantId = "YOUR_TENANT_ID";
const sourceId = "YOUR_SOURCE_ID";
export const config = {
path: ["/", "/docs/getting-started", "/products/example"],
method: ["GET", "HEAD"],
};
export default function captureAgentRequest(request, context) {
const userAgent = request.headers.get("user-agent");
if (!context.ip || !userAgent) return;
const body = {
path: new URL(request.url).pathname,
ip: context.ip,
userAgent,
eventTime: new Date().toISOString(),
sourceId,
};
context.waitUntil(
fetch(endpoint, {
method: "POST",
headers: { "Content-Type": "application/json", "tenant-id": tenantId },
body: JSON.stringify(body),
signal: AbortSignal.timeout(3000),
}).then((response) => {
if (!response.ok) console.error("Hardal agent forwarding failed", response.status);
}).catch((error) => console.error("Hardal agent forwarding failed", error.message))
);
}
Deploy the function with your site. Check the Edge Function logs and verify a crawler visit on one of the configured routes in Hardal.
AWS CloudFront
- Configure CloudFront real-time access logs for the cache behaviors serving your public pages, and send them to Kinesis Data Streams. Set sampling to 100% if you intend to measure all requests in those behaviors.
- Add a Lambda consumer or use your existing consumer. In the log configuration, select
x-host-headerandcs-methodalong with the fields below. Filter to the intended website hostname and public page requests before sending one HTTP POST per eligible record. - Compare a real crawler request from the configured behavior with Hardal. A request that is served from the CloudFront cache can still appear in the access logs.
Azure Front Door
- On an Azure Front Door Standard or Premium profile, open Monitoring → Diagnostic settings. Enable Front Door Access Log and send it to Event Hubs.
- In an Event Hubs-triggered Azure Function or your existing consumer, read the
recordsarray in the Azure Monitor payload. Filter access records to your public website hostname and page requests usingRequestUriandHttpMethod. Send one HTTP POST per eligible record using the mapping below. - Compare a real crawler request from the intended Front Door route with Hardal. Check Front Door's
Cache Statusif you are verifying a request served from the CDN.
Map access logs to Hardal fields
| Hardal field | CloudFront real-time logs | Azure Front Door access logs |
|---|---|---|
path | cs-uri-stem | The pathname from RequestUri |
ip | c-ip when the viewer connects directly to CloudFront | SocketIp when the viewer connects directly to Front Door |
userAgent | The original header value from cs-user-agent | UserAgent |
eventTime | Edge log timestamp converted to ISO 8601 | The access log's UTC Time converted to ISO 8601 |
sourceId | Source ID from the website's Hardal Setup | Source ID from the website's Hardal Setup |
If another proxy sits in front of the CDN, use a client IP field only when that upstream proxy provides a trustworthy original address. Front Door's ClientIp may use a forwarded header. Skip records without a reliable client IP. Send each event to /agent-events using your collection URL and include the tenant-id header. Use the recorded request timestamp rather than the time your consumer processes the log.
Shopify storefronts
Shopify-hosted Online Store. Shopify web pixels collect customer events in the browser. Crawler collection needs the original page request. Hardal has no CDN integration for Shopify's managed Online Store edge. If Cloudflare hosts your domain's DNS, keep Shopify's records DNS only. Shopify does not support Cloudflare proxying for its hosted storefront.
Headless storefront. If you run your own Shopify frontend, use the example for the CDN or server that reads your original requests. For example, use the Next.js setup for a custom storefront hosted on Vercel. Coverage is limited to the routes you instrument.
Verify a crawler visit
Find a genuine crawler request in the server or CDN logs. In Hardal, open AI Visibility → Agents → Last Events and check the source, agent, and page path. A 202 Accepted response means the event was queued. A 204 No Content response means it was ignored. For a missing visit, follow Verify AI Bot Tracking in Hardal.