# Domain Proxy

This guide explains how to set up a proxy server using your own domain and use it with the Hackle SDK.\
This is useful for reducing the impact of ad blockers on user behavior tracking.

![](/files/1qT4tIe2EDDdwFPM6qUd)

To configure and apply the proxy server, you need to complete the following two steps.

1. **Configure the proxy server**
2. **Configure the SDK to point to the proxy server**

***

## 1. Configure the Proxy Server

#### Configuration via Cloud

Most major cloud providers make it easy to develop and deploy proxy services.

The following is an example of setting up a proxy service using AWS CloudFront.

* Go to [AWS CloudFront Console](https://us-east-1.console.aws.amazon.com/cloudfront)
* Click Create distribution
* In the Origin section:
  * Origin domain: set to `event.hackle.io`
  * Protocol: set to `HTTPS Only`

![](/files/XC6m3cZlZXAXOcAslhIc)

* In the Default cache behavior section:
  * Viewer protocol policy: set to `Redirect HTTP to HTTPS`
  * Allowed HTTP methods: set to `GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE`
  * Cache key and origin requests: Allow all Headers and Parameters to be forwarded to the Origin, and allow CORS requests to the Origin.

![](/files/AQYiea79NtI9ersNYQs4)

* In the Function associations section:
  * Origin request: Add a Lambda\@Edge Function to change the `Host` header to `event.hackle.io`.\
    Reference: [Tutorial: Creating a simple Lambda@Edge function](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-how-it-works-tutorial.html)

![](/files/ktJUO7tC6bev3sm3X1tT)

Use the following code in the Lambda\@Edge Function.

```javascript
export const handler = (event, context, callback) => {
  const request = event.Records[0].cf.request;
  request.headers.host[0].value = 'event.hackle.io';
  return callback(null, request);
};
```

* Click Create distribution at the bottom of the page.

#### Building a Proxy Server

You can also build your own proxy server.

Here is an [example of building a proxy server using NGINX](https://github.com/hackle-io/hackle-event-proxy). The configuration below redirects all calls to the proxy server to Hackle.

```
events {}
http {
    server {
        listen 80;
        listen [::]:80;

        location / {
            proxy_set_header Host event.hackle.io;
            proxy_set_header X-Real-IP $http_x_forwarded_for;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host $server_name;
            proxy_pass https://event.hackle.io/;
        }
    }
}
```

## 2. SDK Configuration

You need to configure the SDK to point to the proxy server. You can set this using the `eventUrl` option during SDK initialization.

```javascript
const config = {
  eventUrl: "https://<YOUR_PROXY_DOMAIN>"
};

createInstance(YOUR_SDK_KEY, config);
```

```java
HackleConfig config = HackleConfig.builder()
  .eventUri("https://<YOUR_PROXY_DOMAIN>")
  .build();

HackleApp.initializeApp(getApplicationContext(), YOUR_SDK_KEY, config)
```

```swift
let config = HackleConfigBuilder()
  .eventUrl(URL(string: "https://<YOUR_PROXY_DOMAIN>")!)
  .build()

Hackle.initialize(sdkKey: YOUR_SDK_KEY, config: config)
```

```javascript
HackleConfig config = HackleConfigBuilder()
  .eventUrl("https://<YOUR_PROXY_DOMAIN>")
  .build();

await HackleApp.initialize(YOUR_SDK_KEY, hackleConfig: config);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/troubleshooting/domain-proxy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
