Facebook Pixel & Conversions API

Kurulum ve Güncelleme Raporu

Muzibu.com için Facebook Pixel ve Conversions API (CAPI) entegrasyonu tamamlandı. Kayıt ve abonelik işlemlerinde otomatik event tracking aktif.

Backend

3 dosya güncellendi

CAPI Aktif

Frontend

3 dosya güncellendi

Pixel Aktif

Entegrasyon

Deduplication

eventID

Basit Anlatım (Herkes İçin)

Ne Yapıldı?

Facebook'un reklam sistemine Muzibu'daki kullanıcı hareketlerini otomatik olarak bildiren bir sistem kuruldu. Bu sayede Facebook, hangi reklamların işe yaradığını daha iyi anlayacak ve reklam bütçeniz daha verimli kullanılacak.

Örnek: Bir kullanıcı Facebook reklamından gelip Muzibu'ya kayıt olduğunda, bu bilgi otomatik olarak Facebook'a gönderiliyor. Facebook bu sayede "bu reklam işe yaradı" diye anlıyor ve benzer kişilere daha fazla reklam gösteriyor.

Hangi Olaylar Takip Ediliyor?

Kayıt (Lead)

Yeni bir kullanıcı ücretsiz hesap oluşturduğunda Facebook'a "Lead" (potansiyel müşteri) olayı gönderiliyor.

Abonelik (Subscribe)

Bir kullanıcı premium üyelik satın aldığında Facebook'a "Subscribe" (abone olma) olayı gönderiliyor.

Neden Önemli?

Daha Az Reklam Bütçesi:

Facebook doğru kişileri bulduğu için aynı sonuç için daha az para harcanıyor.

Daha Fazla Müşteri:

Facebook benzer özelliklere sahip kişileri bulup onlara da reklam gösteriyor.

AdBlock Bypass:

Kullanıcının reklam engelleyicisi olsa bile veriler sunucudan gönderiliyor (CAPI).

Çift Koruma:

Hem tarayıcıdan (Pixel) hem sunucudan (CAPI) gönderiliyor, birisi başarısız olsa diğeri çalışıyor.

Güvenlik ve Gizlilik

Kullanıcı verileri (email, isim) Facebook'a göndermeden önce SHA256 ile şifreleniyor (hash). Bu sayede Facebook sadece "bu kullanıcıyı tanıyorum" diyor ama gerçek bilgileri görmüyor.

Not: Access Token gibi gizli bilgiler sadece sunucuda tutuluyor, tarayıcıya asla gönderilmiyor. Pixel ID ise halka açık bir bilgi (sorun değil).

Teknik Detaylar (Geliştiriciler İçin)

Sistem Mimarisi

┌─────────────────────────────────────────────────────────────┐
│                    KULLANICI KAYIT AKIŞI                     │
└─────────────────────────────────────────────────────────────┘
                              │
                   1. Kayıt formu submit
                              ▼
        ┌─────────────────────────────────────────┐
        │  TrackUserRegistration Listener         │
        │  (Backend - Server-Side)                │
        ├─────────────────────────────────────────┤
        │  • Lead event → Facebook CAPI           │
        │  • eventID = lead_[time]_[uniqid]       │
        │  • Session'a kaydet: fb_lead_event_id   │
        │  • User data: email, name (hashed)      │
        └─────────────────────────────────────────┘
                              │
                   2. Redirect sonrası
                              ▼
        ┌─────────────────────────────────────────┐
        │  facebook-lead-tracker.blade.php        │
        │  (Frontend - Client-Side)               │
        ├─────────────────────────────────────────┤
        │  • Session'dan eventID al               │
        │  • fbq('track', 'Lead', {...}, {        │
        │      eventID: 'lead_xxx'                │
        │    })                                   │
        │  • dataLayer.push({                     │
        │      event: 'generate_lead',            │
        │      event_id: 'lead_xxx'               │
        │    })                                   │
        │  • Cookie'lerden _fbp, _fbc extract     │
        └─────────────────────────────────────────┘
                              │
                              ▼
        ┌─────────────────────────────────────────┐
        │      Facebook Events Manager            │
        │  (Deduplication - eventID ile)          │
        ├─────────────────────────────────────────┤
        │  Backend + Frontend = Tek Event         │
        │  (Aynı eventID sayesinde)               │
        └─────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────┐
│                   ABONELİK SATIN ALMA AKIŞI                  │
└─────────────────────────────────────────────────────────────┘
                              │
                   1. Ödeme tamamlandı
                              ▼
        ┌─────────────────────────────────────────┐
        │  PaymentObserver (Backend)              │
        │  Status: completed olunca tetiklenir    │
        ├─────────────────────────────────────────┤
        │  • Subscribe event → Facebook CAPI      │
        │  • eventID = sub_[time]_[uniqid]        │
        │  • Payment metadata'ya kaydet           │
        │  • predicted_ltv hesapla:               │
        │    - Aylık: amount * 6                  │
        │    - Yıllık: amount * 3                 │
        │  • Subscription period tespit et        │
        └─────────────────────────────────────────┘
                              │
                   2. Success page
                              ▼
        ┌─────────────────────────────────────────┐
        │  payment-success.blade.php              │
        │  (Frontend)                             │
        ├─────────────────────────────────────────┤
        │  • Payment metadata'dan eventID al      │
        │  • fbq('track', 'Subscribe', {...}, {   │
        │      eventID: 'sub_xxx'                 │
        │    })                                   │
        │  • dataLayer.push({                     │
        │      event: 'subscribe',                │
        │      event_id: 'sub_xxx'                │
        │    })                                   │
        └─────────────────────────────────────────┘
                        

Güncellenen Dosyalar

Backend (Server-Side)

app/Services/FacebookConversionAPIService.php
  • trackEvent() metoduna eventID parametresi eklendi
  • buildEventData() içinde event_id payload'a ekleniyor
  • • Deduplication desteği aktif
app/Listeners/TrackUserRegistration.php
  • • ❌ CompleteRegistration → ✅ Lead event
  • • EventID oluşturma: lead_{time}_{uniqid}
  • • Session'a kaydetme: session(['fb_lead_event_id' => $eventID])
  • • Custom data: content_name, status, lead_type
app/Observers/PaymentObserver.php
  • • ❌ Purchase → ✅ Subscribe event
  • • EventID oluşturma: sub_{time}_{uniqid}
  • • Payment metadata'ya kaydetme: $payment->update(['metadata' => [..., 'fb_event_id' => $eventID]])
  • calculatePredictedLTV() metodu eklendi (monthly: 6x, yearly: 3x)
  • extractSubscriptionData() metodu eklendi (period detection)

Frontend (Client-Side)

resources/views/components/marketing/facebook-lead-tracker.blade.php YENİ
  • • Session'da fb_lead_event_id varsa tetikleniyor
  • fbq('track', 'Lead', {...}, {eventID})
  • dataLayer.push({event: 'generate_lead'})
  • • Cookie extraction: _fbp, _fbc
resources/views/themes/muzibu/layouts/app.blade.php
  • • Line 220: <x-marketing.facebook-lead-tracker /> eklendi
  • • GTM Body Snippet'ın hemen altında
Modules/Payment/.../payment-success.blade.php
  • • ❌ Purchase → ✅ Subscribe event
  • • Payment metadata'dan eventID alınıyor
  • predicted_ltv hesaplama (PHP tarafında da yapılıyor)
  • dataLayer.push({event: 'subscribe'})
  • • Cookie extraction: _fbp, _fbc

Konfigürasyon

.env
  • FACEBOOK_PIXEL_ID=1350880453347156
  • FACEBOOK_ACCESS_TOKEN=EAAK0y... (GİZLİ)
  • FACEBOOK_API_VERSION=v19.0
config/services.php
  • 'facebook' => [...] service config eklendi
  • • Lines 153-171
settings table
  • • Record ID: 259
  • key: marketing_fb_pixel_id
  • value: 1350880453347156
  • tenant_id: 1001 (Muzibu)

eventID Deduplication Mekanizması

Aynı event'in hem backend (CAPI) hem frontend (Pixel) tarafından gönderilmesi durumunda Facebook'ta çift sayılmasını engellemek için eventID kullanılıyor.

Lead Event (Kayıt)

1. Backend (TrackUserRegistration):

$eventID = 'lead_' . time() . '_' . uniqid();
session(['fb_lead_event_id' => $eventID]);
$this->facebookService->trackEvent('Lead', $userData, $customData, null, $eventID);

2. Frontend (facebook-lead-tracker.blade.php):

const eventID = '{{ session('fb_lead_event_id') }}';
fbq('track', 'Lead', {...}, { eventID: eventID });

Sonuç: Facebook aynı eventID'ye sahip 2 olayı tek event olarak sayar

Subscribe Event (Abonelik)

1. Backend (PaymentObserver):

$eventID = 'sub_' . time() . '_' . uniqid();
$metadata['fb_event_id'] = $eventID;
$payment->update(['metadata' => $metadata]);
$this->facebookService->trackEvent('Subscribe', $userData, $customData, null, $eventID);

2. Frontend (payment-success.blade.php):

const eventID = '{{ $payment->metadata['fb_event_id'] ?? '' }}';
fbq('track', 'Subscribe', {...}, { eventID: eventID });

Sonuç: Backend + Frontend = Tek event (deduplication)

Predicted LTV Hesaplama

Facebook'a gönderilen Subscribe event'inde, kullanıcının tahmini yaşam boyu değeri (Lifetime Value) hesaplanıyor.

protected function calculatePredictedLTV(Payment $payment, array $subscriptionData): float
{
    $amount = (float) $payment->amount;

    if ($subscriptionData['period'] === 'yearly') {
        // Yıllık plan: 3 yıl retention varsayımı
        return round($amount * 3, 2);
    }

    // Aylık plan: 6 ay retention varsayımı
    return round($amount * 6, 2);
}

Aylık Abonelik

Varsayım: 6 ay tutma oranı

LTV = Tutar × 6

Yıllık Abonelik

Varsayım: 3 yıl tutma oranı

LTV = Tutar × 3

Facebook API Endpoint

POST Endpoint:

https://graph.facebook.com/v19.0/1350880453347156/events

Access Token:

EAAK0yoAlg5kBQxkRZAYp8FedcOIZBypEGkOFtTZAa2yUSOpZAmHKFhNnM33CM7c...

Pixel ID:

1350880453347156

Test Checklist

Kayıt (Lead) Testi

Yeni kullanıcı kaydı oluştur

Kayıt formunu doldur ve submit et

Browser console kontrol

Facebook Pixel: Lead event tracked with eventID: lead_xxx
DataLayer: generate_lead event pushed

Laravel log kontrol

Facebook CAPI: Lead event tracked (storage/logs/laravel.log)

Facebook Events Manager

Event: Lead, eventID ile deduplication kontrolü

Abonelik (Subscribe) Testi

Subscription satın al

Test ödeme yaparak abonelik satın al

Payment success sayfası console

Facebook Pixel: Subscribe event tracked with eventID: sub_xxx
DataLayer: subscribe event pushed

Laravel log kontrol

Facebook CAPI: Subscribe event tracked
predicted_ltv: [hesaplanan değer]

Facebook Events Manager

Event: Subscribe, predicted_ltv değeri, eventID kontrolü

Payment metadata kontrol

Database: payments tablosu, metadata kolonu → fb_event_id mevcut mu?

Google Tag Manager Testi

GTM Preview Mode

Google Tag Manager'ı preview modunda aç

DataLayer events kontrol

generate_lead ve subscribe event'lerinin görünmesi

Önemli Notlar

  • Access Token: .env dosyasında saklanıyor ve asla frontend'e gönderilmiyor (güvenlik)
  • Pixel ID: Settings tablosunda ve frontend'de kullanılıyor (public bilgi, sorun değil)
  • User Data Hashing: Email, isim gibi veriler SHA256 ile hashlenip gönderiliyor
  • Cookie Extraction: _fbp ve _fbc cookie'leri otomatik extract ediliyor
  • Cache: View ve config cache temizlendi, değişiklikler aktif

4 Mart 2026 • Muzibu.com