Use Azure Functions to forward data to the Log visit endpoint.

Azure Functions allows you to run JavaScript (Node.js) code in a serverless environment that can be triggered by HTTP requests. Read the official documentation for more details.

Setup

  1. Create an Azure Function App in your preferred region.
  2. Create an HTTP triggered function.
  3. Set up the HALL_API_KEY application setting with your Hall API key.

Example

The example below demonstrates how to forward data from incoming requests using Azure Functions.

function.js
module.exports = async function (context, req) {
    const requestPath = req.originalUrl;
    const requestMethod = req.method;

    const headers = req.headers
    const requestIp = headers['x-forwarded-for']?.split(',')[0] || 
                     headers['x-azure-clientip'] || 
                     context.req.ip;

    const requestHeaders = {
        'User-Agent': headers['user-agent'] || '',
        'Host': headers['host'] || '',
        'Referer': headers['referer'] || '',
    }

    fetch('https://analytics.usehall.com/visit', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${process.env.HALL_API_KEY}`,
        },
        body: JSON.stringify({
            request_path: requestPath,
            request_method: requestMethod,
            request_ip: requestIp,
            request_headers: requestHeaders,
            request_timestamp: Date.now(),
        }),
    });

    return req;
};

Deployment

To deploy this function, follow the Azure Functions deployment guide in the Azure documentation.