Siparis Takibi

Satin alma takibi

Sipariş takibi, Selwise'ın gelir ilişkilendirmesinin (attribution) temelidir. Kampanya, öneri ve arama gibi modüllerin gerçek gelire katkısını ölçebilmek için tamamlanan siparişleri Selwise'a bildirmeniz gerekir.

En güvenilir yöntem, teşekkür / sipariş onay sayfasında window.Selwise.trackOrder(...) çağırmaktır.

Temel kullanım

Sipariş onay sayfasına, gerçek sipariş verilerini doldurarak aşağıdaki bloğu ekleyin:

<script>
  window.Selwise?.trackOrder({
    orderId: 'ORDER_12345',
    currency: 'TRY', // ISO-4217 (örn. TRY / EUR / USD)
    total: 129.90,
    items: [
      {
        productItemCode: 'SKU-RED-XL',
        name: 'Tişört Kırmızı XL',
        quantity: 1,
        unitPrice: 129.90,
      },
    ],
  });
</script>

window.Selwise?. (opsiyonel zincir) kullanımı, script henüz yüklenmemişse hatayı önler.

Tüm alanlar

<script>
  window.Selwise?.trackOrder({
    // Zorunlu
    orderId: 'ORDER_12345',

    // Tutarlar
    currency: 'TRY',
    total: 129.90,
    subtotal: 119.90,
    discountTotal: 10.00,
    shippingTotal: 20.00,
    taxTotal: 0.00,

    // Bağlam (verilmezse otomatik doldurulur)
    placedAt: new Date().toISOString(),
    pageUrl: window.location.href,
    referrer: document.referrer,

    // Sipariş kalemleri
    items: [
      {
        productItemCode: 'SKU-001', // besleme SKU'su ile aynı olmalı
        productId: '12345',
        name: 'Ürün Adı',
        quantity: 2,
        unitPrice: 49.95,
      },
    ],

    // Opsiyonel meta veri
    metadata: {
      paymentMethod: 'credit_card',
      couponCode: 'SAVE10',
    },
  });
</script>

productItemCode besleme SKU'su ile aynı olmalı

items[].productItemCode, ürün beslemenizdeki stok koduyla birebir aynı olmalıdır. Aksi halde satırlar ürünlerle eşleşmez ve ürün bazlı gelir/öneri raporları boş kalır.

Alanların karşılıkları

trackOrder, verileri POST /api/v1/public/sites/:siteKey/orders endpoint'ine iletir. Alan karşılıkları:

trackOrder alanıTipZorunluAçıklama
orderIdstringEvetBenzersiz sipariş kimliği. Tekrarlı gönderimlerde tekilleştirme anahtarı.
currencystringHayırISO-4217 para birimi.
totalnumberHayırToplam tutar.
subtotal / discountTotal / shippingTotal / taxTotalnumberHayırTutar dökümü.
placedAtstringHayırISO tarih. Verilmezse sunucu zamanı kullanılır.
pageUrl / referrerstringHayırBağlam; otomatik doldurulur.
items[]arrayHayırSipariş kalemleri (aşağıda).
metadataobjectHayırSerbest anahtar-değer verisi.
skipPurchaseEventbooleanHayırtrue ise sunucu ayrı bir kanonik purchase event'i üretmez (çift sayımı önlemek için).

Kalem (items[]) alanları: productItemCode, productId, name, quantity, unitPrice, price, totalPrice, metadata.

Tekilleştirme ve çift sayım

  • Aynı orderId iki kez gönderilirse Selwise ikinci gönderimi yok sayar (aynı zaman penceresinde HTTP 409). Sayfa yenilenmesi kaynaklı çift kayıt böylece engellenir.
  • Hem veri katmanı purchase hem trackOrder kullanıyorsanız aynı satın alma iki kez sayılabilir. Bu durumda ya yalnızca birini kullanın ya da trackOrder çağrısında ilgili senaryoya göre skipPurchaseEvent davranışını göz önünde bulundurun. Öneri: tek kaynak olarak trackOrder'ı esas alın.

Nereye koymalı

trackOrder'ı yalnızca ödeme başarıyla tamamlandığında render edilen sipariş onay sayfasına koyun. Ara adımlara veya her sayfaya koymayın.

Platform örnekleri

Shopify

Sipariş durumu (Additional Scripts) alanına Liquid ile:

<script>
  var orderId = '{{ order.id }}';
  var total = {{ order.total_price | divided_by: 100.0 }};
  var currency = '{{ shop.currency }}';

  window.Selwise?.trackOrder({
    orderId: String(orderId),
    currency: currency,
    total: total,
    placedAt: new Date().toISOString(),
    items: [
      {% for line_item in order.line_items %}
      {
        productItemCode: '{{ line_item.sku }}',
        productId: '{{ line_item.product_id }}',
        name: '{{ line_item.title | escape }}',
        quantity: {{ line_item.quantity }},
        unitPrice: {{ line_item.price | divided_by: 100.0 }}
      }{% unless forloop.last %},{% endunless %}
      {% endfor %}
    ]
  });
</script>

WooCommerce

Temanızın functions.php dosyasına (veya bir snippet eklentisiyle):

add_action('woocommerce_thankyou', function($order_id) {
    $order = wc_get_order($order_id);
    if (!$order) return;

    $items = [];
    foreach ($order->get_items() as $item) {
        $product = $item->get_product();
        $items[] = [
            'productItemCode' => $product->get_sku(),
            'productId' => (string) $product->get_id(),
            'name' => $item->get_name(),
            'quantity' => $item->get_quantity(),
            'unitPrice' => (float) $order->get_item_total($item, false),
        ];
    }
    ?>
    <script>
      window.Selwise?.trackOrder({
        orderId: '<?php echo $order_id; ?>',
        currency: '<?php echo $order->get_currency(); ?>',
        total: <?php echo $order->get_total(); ?>,
        items: <?php echo json_encode($items); ?>
      });
    </script>
    <?php
});

Google Tag Manager (GA4 purchase üzerinden)

GTM'de bir "Custom HTML" tag'i oluşturup GA4 purchase event'inde tetikleyin:

<script>
  var ecommerce = window.dataLayer?.find(function (x) {
    return x && x.ecommerce;
  })?.ecommerce;

  if (ecommerce && ecommerce.transaction_id) {
    window.Selwise?.trackOrder({
      orderId: String(ecommerce.transaction_id),
      currency: ecommerce.currency || 'TRY',
      total: Number(ecommerce.value || 0),
      items: (ecommerce.items || []).map(function (item) {
        return {
          productItemCode: item.item_id || item.item_sku,
          name: item.item_name,
          quantity: Number(item.quantity || 1),
          unitPrice: Number(item.price || 0),
        };
      }),
    });
  }
</script>

Sunucu tarafı (headless) gönderim

Tarayıcıya güvenemeyeceğiniz durumlarda siparişi doğrudan sunucudan gönderebilirsiniz:

curl -X POST https://api.selwise.com/api/v1/public/sites/SITE_KEY/orders \
  -H "Content-Type: application/json" \
  -H "Origin: https://magaza.com" \
  -d '{
    "orderId": "ORDER_12345",
    "currency": "TRY",
    "total": 129.90,
    "items": [
      { "productItemCode": "SKU-RED-XL", "name": "Tişört", "quantity": 1, "unitPrice": 129.90 }
    ]
  }'

İstek, doğrulanmış domain'inizin Origin başlığını taşımalıdır. Endpoint IP başına dakikada 10 sipariş ile sınırlandırılmıştır. Ayrıntılar: Public API.

Son güncelleme: 1 Temmuz 2026

Bu makale yardimci oldu mu?