GuidesAI Visibility Installation Examples

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 setupWhere to collect
CloudflareHardal's generated Worker on your website route
Next.js / VercelHardal's generated Next.js Proxy on your page routes
Node.js / ExpressHardal's generated middleware on your application server
NetlifyA custom Edge Function that calls the Hardal HTTP API
AWS CloudFrontReal-time access logs with a custom Kinesis consumer
Azure Front DoorAccess logs with a custom Event Hubs consumer
ShopifyA 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

  1. Copy the Cloudflare example from Hardal. In Workers & Pages, create a Worker or add forwarding to your existing Worker handler.
  2. 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.
  3. Check the Worker logs for forwarding failures, then verify a crawler visit in Hardal.

Next.js on Vercel

  1. On Next.js 16 or later, copy the generated Next.js example into proxy.ts at the same level as app or pages. If you already use Proxy for routing or authentication, add forwarding to the existing handler and preserve its behavior.
  2. 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.
  3. Check a deployed route that matches your Proxy configuration, then verify a crawler visit in Hardal.

Node.js and Express

  1. Copy the generated Node.js example. Register app.use(hardalAgentEvents) before the public page routes you want to measure.
  2. If Express is behind a reverse proxy, configure trusted proxies to match your network. Verify that req.ip points to the original client rather than the proxy.
  3. 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

  1. 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.
  2. Add a Lambda consumer or use your existing consumer. In the log configuration, select x-host-header and cs-method along with the fields below. Filter to the intended website hostname and public page requests before sending one HTTP POST per eligible record.
  3. 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

  1. On an Azure Front Door Standard or Premium profile, open Monitoring → Diagnostic settings. Enable Front Door Access Log and send it to Event Hubs.
  2. In an Event Hubs-triggered Azure Function or your existing consumer, read the records array in the Azure Monitor payload. Filter access records to your public website hostname and page requests using RequestUri and HttpMethod. Send one HTTP POST per eligible record using the mapping below.
  3. Compare a real crawler request from the intended Front Door route with Hardal. Check Front Door's Cache Status if you are verifying a request served from the CDN.

Map access logs to Hardal fields

Hardal fieldCloudFront real-time logsAzure Front Door access logs
pathcs-uri-stemThe pathname from RequestUri
ipc-ip when the viewer connects directly to CloudFrontSocketIp when the viewer connects directly to Front Door
userAgentThe original header value from cs-user-agentUserAgent
eventTimeEdge log timestamp converted to ISO 8601The access log's UTC Time converted to ISO 8601
sourceIdSource ID from the website's Hardal SetupSource 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.