Use Akamai EdgeWorkers to forward data to the Log 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 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.

Example

The example below demonstrates how to forward data from incoming requests using Akamai EdgeWorkers.
main.js
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 in the Akamai documentation.