> ## 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.

# Microsoft Azure

> Integrate with Azure to send analytics data to Hall

Use Azure Functions to forward data to the [Log visit](api-reference/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](https://docs.microsoft.com/en-us/azure/azure-functions/) 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](/authorization).

## Example

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

```js function.js theme={null}
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](https://docs.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies) in the Azure documentation.
