Files
kolaytercih/src/lib/analitik-sunucu.ts
bilalgursen f05f3e0c69 fix: p7/p4 denetim bulguları — derin sayfa sıra yılı ve başlık uzunluğu, giriş sayacı, rybbit host
- derin /bolum ve /universite sayfalarında sıra aralığı hangi yıldan geldiğini
  söyler (2025 / 2024 / 2024–2025); 2024 sırası '2025 verisi' diye sunulmaz
- <title> yuvarlanmış rakamlarla ve şablon eki olmadan ≤~86 karakter
- giriş formunda tek geri sayım interval'i (çift sayaç butonu erken açıyordu)
- RYBBIT_HOST sonundaki '/' atılır

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-21 16:12:11 +03:00

56 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import "server-only";
/**
* Rybbit'e sunucudan olay gönderimi (POST /api/track). Yalnızca sunucu
* tarafından çağrılır (lib/odeme.ts, lib/auth.ts) — anahtar NEXT_PUBLIC_ değil.
*
* Neden sunucu tarafı: ödeme dönüşümü tarayıcıdan gönderilirse reklam
* engelleyiciler ve iyzico dönüşünde kapatılan sekmeler yüzünden kaybolur.
* Buradan giden kayıt gerçek geliri taşır ve her zaman düşer.
*
* Env yoksa (dev, self-host anahtarı tanımsız) hiçbir istek yapılmaz.
*/
// Sondaki "/" atılır: secret "https://…/" girilirse `//api/track` 404 olup
// olaylar sessizce kaybolmasın.
const HOST = process.env.RYBBIT_HOST?.replace(/\/+$/, "");
const SITE_ID = process.env.RYBBIT_SITE_ID;
const API_KEY = process.env.RYBBIT_API_KEY;
export type SunucuOlayAdi = "odeme_tamamlandi" | "giris_basarili";
export async function sunucuOlayi(
ad: SunucuOlayAdi,
{
kullaniciId,
pathname = "/",
ozellikler,
}: {
kullaniciId?: string;
pathname?: string;
ozellikler?: Record<string, string | number>;
} = {},
): Promise<void> {
if (!HOST || !SITE_ID || !API_KEY) return;
try {
await fetch(`${HOST}/api/track`, {
method: "POST",
headers: {
Authorization: `Bearer ${API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
site_id: SITE_ID,
type: "custom_event",
event_name: ad,
pathname,
...(kullaniciId ? { user_id: kullaniciId } : {}),
...(ozellikler ? { properties: JSON.stringify(ozellikler) } : {}),
}),
// Analitik ödeme akışını asla geciktirmesin/bloklamasın
signal: AbortSignal.timeout(3000),
});
} catch {
// Yut: analitik hatası ödeme sonucunu etkilemez
}
}