Destek/Proxy Kılavuzları
Proxy Kılavuzları

Flowsery Analytics'i Flask ile proxy'leme

Reklam engelleyicilerin müdahalesini önlemek ve daha doğru ziyaretçi verisi toplamak için Flowsery Analytics'i Flask uygulamanız üzerinden yönlendirin.

1. Bağımlılıkları kurun

pip install flask requests

2. Proxy'yi kurun

Aşağıdaki rotaları ve yardımcı fonksiyonu Flask uygulamanıza ekleyin:

from flask import Flask, request, Response
import requests
 
app = Flask(__name__)
 
 
def get_client_ip():
    """
    Determine the actual visitor IP address.
    When behind Cloudflare, prefer CF-Connecting-IP. Then X-Real-IP.
    Then X-Forwarded-For's first entry. Finally fall back to request.remote_addr.
    """
    cf_ip = request.headers.get("CF-Connecting-IP")
    if cf_ip:
        return cf_ip
    real_ip = request.headers.get("X-Real-IP")
    if real_ip:
        return real_ip
    xff = request.headers.get("X-Forwarded-For")
    if xff:
        # Comma-separated list: "client, proxy1, proxy2"
        parts = [ip.strip() for ip in xff.split(",")]
        if parts:
            return parts[0]  # the leftmost entry is the original client
    return request.remote_addr
 
 
@app.route("/js/main.js")
def proxy_script():
    response = requests.get("https://cdn.flowsery.com/main.js")
    return Response(
        response.content,
        content_type="application/javascript",
        headers={"Cache-Control": "public, max-age=31536000"},
    )
 
 
@app.route("/api/track", methods=["POST"])
def proxy_events():
    # Copy incoming headers but omit those that should match the target
    excluded = {"host", "content-length"}
    headers = {
        key: value
        for key, value in request.headers.items()
        if key.lower() not in excluded
    }
 
    # The Origin header is required by the Flowsery Analytics API
    if "Origin" not in headers:
        scheme = request.scheme
        host = request.host
        headers["Origin"] = f"{scheme}://{host}"
 
    # Attach the real visitor IP for accurate geolocation
    client_ip = get_client_ip()
    headers["x-forwarded-for"] = client_ip
    if client_ip:
        # CRITICAL: Flowsery reads this as the authoritative visitor IP. Without it, every visitor resolves to your server's region.
        headers["x-flowsery-real-ip"] = client_ip
 
    # Forward the request body and headers to Flowsery Analytics
    response = requests.post(
        "https://analytics.flowsery.com/analytics/events",
        data=request.get_data(),
        headers=headers,
        timeout=5,
    )
 
    # Return the upstream response to the browser
    return Response(
        response.content,
        status=response.status_code,
        content_type=response.headers.get("Content-Type", "application/json"),
    )

Not: Uygulamanızda zaten bir /api/track uç noktası varsa, olayları farklı bir yola göndermek için Flowsery Analytics betik etiketinde data-api özniteliğini kullanın. Örneğin data-api="/flowsery-events", verileri /flowsery-events adresine yönlendirir.

Önemli: Panelinizde tüm ziyaretçiler aynı konumda görünüyorsa, istekleri Flowsery Analytics /events uç noktasına iletirken x-flowsery-real-ip başlığının proxy sunucusunun IP'sine değil gerçek ziyaretçi IP'sine ayarlandığını doğrulayın.

3. Betik etiketini değiştirin

Orijinal Flowsery Analytics kodunu proxy'lenmiş sürümle değiştirin:

<script defer data-fl-website-id="flid_******" src="/js/main.js"></script>

4. Yayına alın

Sunucunuzu yayına aldıktan sonra proxy yapılandırması otomatik olarak etkinleşir.

Çalıştığını doğrulama

Proxy'nin doğru çalıştığını doğrulamak için:

  1. Web sitenize gidin
  2. Tarayıcınızın geliştirici araçlarını açın ve Network sekmesine geçin
  3. Analitik isteklerinin analytics.flowsery.com yerine kendi alan adınızdan sunulduğunu doğrulayın

Sorun giderme

Tüm ziyaretçiler aynı konumdan görünüyor

Tüm ziyaretçiler sunucunuzun bölgesi gibi tek bir coğrafi konumda görünüyorsa, proxy gerçek ziyaretçi IP'lerini doğru iletmiyor demektir.

Çözüm:

  1. İstekleri Flowsery Analytics /events uç noktasına iletirken proxy'nizin, sunucu IP'sini değil gerçek ziyaretçi IP adresini içeren x-flowsery-real-ip başlığını eklediğinden emin olun
  2. Flask başka bir proxy'nin (Cloudflare, Vercel vb.) arkasındaysa request.remote_addr o üst proxy olur; bunun yerine doğrudan request.headers.get('CF-Connecting-IP') veya request.headers.get('X-Real-IP') değerini okuyun