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

# Proxy Trfyx through Flask

> Proxy Trfyx analytics through Flask.

Use Flask to expose same-origin routes for the Trfyx script and event collection.

<Steps>
  <Step title="Install dependencies">
    ```bash Terminal theme={"dark"}
    pip install flask requests
    ```
  </Step>

  <Step title="Add proxy routes">
    ```python app.py theme={"dark"}
    from flask import Flask, request, Response
    import requests

    app = Flask(__name__)

    @app.get("/script.js")
    def script():
        r = requests.get("https://app.trfyx.com/script.js", timeout=5)
        return Response(r.content, status=r.status_code, content_type="application/javascript")

    @app.post("/api/events")
    def events():
        headers = dict(request.headers)
        headers["Origin"] = request.host_url.rstrip("/")
        headers["X-Forwarded-For"] = request.headers.get("X-Forwarded-For", request.remote_addr)

        r = requests.post(
            "https://app.trfyx.com/api/events",
            data=request.get_data(),
            headers=headers,
            timeout=5,
        )

        return Response(r.content, status=r.status_code, content_type=r.headers.get("Content-Type", "application/json"))
    ```
  </Step>

  <Step title="Update your tracker">
    ```html index.html theme={"dark"}
    <script
      defer
      data-website-id="YOUR_TRFYX_PROJECT_ID"
      data-domain="yourdomain.com"
      src="/script.js"
    ></script>
    ```
  </Step>

  <Step title="Verify installation">
    Confirm the browser uses your `/script.js` and `/api/events` endpoints and that activity appears in Trfyx.

    <Warning>
      Do not trust an arbitrary client-supplied `X-Forwarded-For` header in a public deployment. Configure your trusted proxy/load-balancer chain correctly so the forwarded IP represents the real visitor.
    </Warning>
  </Step>
</Steps>

## Next steps

<CardGroup cols={2}>
  <Card title="Goals" icon="bullseye" href="/goals" />

  <Card title="Funnels" icon="filter" href="/funnels" />

  <Card title="Managed Proxy" icon="shield-halved" href="/managed-proxy" />

  <Card title="Troubleshooting" icon="life-ring" href="/troubleshooting" />
</CardGroup>


## Related topics

- [Proxy Trfyx through your domain](/proxy-guide.md)
- [Proxy Trfyx through Nginx](/nginx-proxy.md)
- [Proxy Trfyx through PHP](/php-proxy.md)
- [Proxy Trfyx through Express](/express-proxy.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.