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

# Akamai EdgeWorkers

> Integrate with Akamai EdgeWorkers to send analytics data to Hall

Use Akamai EdgeWorkers to forward data to the [Log visit](api-reference/visit) endpoint.

Akamai EdgeWorkers allows you to run JavaScript code at Akamai edge locations, intercepting and modifying requests before they reach your origin server. Read the [official documentation](https://techdocs.akamai.com/edgeworkers/docs) for more details.

## Setup

1. Create an EdgeWorker function and deploy it to your Akamai property.
2. Configure the function as a client request trigger.
3. Store your `HALL_API_KEY` securely using EdgeKV with your [Hall API key](/authorization).

## Example

The example below demonstrates how to forward data from incoming requests using Akamai EdgeWorkers.

```js main.js theme={null}
import { httpRequest } from 'http-request';
import { EdgeKV } from './edgekv.js';

const edgeKv = new EdgeKV({ 
    namespace: 'hall-config', 
    group: 'credentials' 
});

export function onClientRequest(request) {
    const requestPath = request.path + (request.query ? '?' + request.query : '');
    const requestMethod = request.method;
    const requestIp = request.clientIp || '127.0.0.1';
    
    const requestHeaders = {
        'User-Agent': request.getHeader('User-Agent')?.[0] || '',
        'Host': request.getHeader('Host')?.[0] || '',
        'Referer': request.getHeader('Referer')?.[0] || '',
    };

    edgeKv.getText({ item: 'api_key' })
        .then((apiKey) => {
            if (apiKey) {
                httpRequest('https://analytics.usehall.com/visit', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': `Bearer ${apiKey}`,
                    },
                    body: JSON.stringify({
                        request_path: requestPath,
                        request_method: requestMethod,
                        request_ip: requestIp,
                        request_headers: requestHeaders,
                        request_timestamp: Date.now(),
                    }),
                }).catch(() => {
                    // Silent failure
                });
            }
        })
        .catch(() => {
            // Silent failure
        });

    return request;
}
```

## Deployment

To deploy this function to EdgeWorkers, follow the [Akamai EdgeWorkers deployment guide](https://techdocs.akamai.com/edgeworkers/docs) in the Akamai documentation.
