From f79c56088e757ec41171e36166222e97003fb3a1 Mon Sep 17 00:00:00 2001 From: risto Date: Thu, 19 Sep 2024 06:35:54 +0200 Subject: [PATCH] feat: add tracking endpoint and IP address service Introduce a new tracking endpoint in `com_tracardi/endpoint/track.py` to handle tracking events. Add IP address extraction logic in `tracardi/service/ip_address.py` to support tracking from reverse proxy headers. Integrate the tracking endpoint into the application in `app/main.py`. Update `app/api/track/event_server_endpoint.py` to use the new IP address service. --- tracardi/service/ip_address.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tracardi/service/ip_address.py diff --git a/tracardi/service/ip_address.py b/tracardi/service/ip_address.py new file mode 100644 index 00000000..1b19e330 --- /dev/null +++ b/tracardi/service/ip_address.py @@ -0,0 +1,13 @@ +from tracardi.config import server + + +def get_ip_address(request) -> str: + + """ + Returns IP address - if address is forwarded from reverse proxy it takes USE_X_FORWARDED_IP env to figure out + where the forwarded ip is stored in headers. + """ + + if server.x_forwarded_ip_header is not None and server.x_forwarded_ip_header in request.headers: + return request.headers[server.x_forwarded_ip_header] + return request.client.host