Files
kolaytercih/src/lib/analitik-sunucu.ts
bilalgursen 0b92f999bc
All checks were successful
Deploy / deploy (push) Successful in 16m7s
Integrate Rybbit analytics and enhance user tracking features
- Added Rybbit analytics configuration in .mcp.json for improved data collection.
- Updated layout.tsx to conditionally load the Rybbit analytics script in production.
- Enhanced user interaction tracking in various components, including GirisForm, RevizyonKutusu, and SatinAlForm, by logging specific events.
- Updated privacy policy page to reflect new data handling practices and added a section on service providers and data transfer.
- Improved user navigation and experience by integrating Rybbit's live visitor widget in the site footer.
2026-08-02 19:29:42 +03:00

54 lines
1.6 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.
/**
* Rybbit'e sunucudan olay gönderimi (POST /api/track). Yalnızca sunucu
* tarafından çağrılır (lib/odeme.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.
*/
const HOST = process.env.RYBBIT_HOST;
const SITE_ID = process.env.RYBBIT_SITE_ID;
const API_KEY = process.env.RYBBIT_API_KEY;
export type SunucuOlayAdi = "odeme_tamamlandi";
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
}
}