Skip to content

Track an order with the .NET SDK

This tutorial demonstrates how to submit an OrderCreated event when a customer completes a purchase in the webshop.

Before you start

Set up the .NET client as described in the developer overview.

Step 1: Capture the order data

When a customer completes checkout, collect the order details from your commerce system:

var orderId = "ORD-20240315-001";
var orderTotal = 299.98;
var currency = "EUR";
var lineItems = new[]
{
    new OrderLineItemModel
    {
        ProductId = "PROD-001",
        SkuId = "SKU-001-BLK-M",
        Quantity = 2,
        UnitPrice = 99.99
    },
    new OrderLineItemModel
    {
        ProductId = "PROD-042",
        SkuId = "SKU-042-WHT-L",
        Quantity = 1,
        UnitPrice = 100.00
    }
};

Step 2: Submit the order event

await client.EventsAsync(new TrackedEventBatchModel
{
    InstrumentationKey = "your-instrumentation-key",
    Events = new[]
    {
        new TrackedEventModel
        {
            EventType = "OrderCreated",
            SessionId = "session-abc-123",
            UserId = "user-456",
            OrderId = orderId,
            OrderTotal = orderTotal,
            Currency = currency,
            LineItems = lineItems
        }
    }
});

Step 3: Verify

The Event Receiver responds with 202 Accepted once the event batch is received. Events are processed asynchronously.

Complete example

using Bizzkit.Sdk.EventTracking.EventReceiver;

var factory = new EventReceiverClientFactory(
    new EventReceiverConnectionOptions
    {
        BaseUrl = "https://event-tracking-eventreceiver.bizzkit.biz"
    },
    new HttpClient());

var client = await factory.CreateUnauthenticatedClientAsync();

await client.EventsAsync(new TrackedEventBatchModel
{
    InstrumentationKey = "your-instrumentation-key",
    Events = new[]
    {
        new TrackedEventModel
        {
            EventType = "OrderCreated",
            SessionId = "session-abc-123",
            UserId = "user-456",
            OrderId = "ORD-20240315-001",
            OrderTotal = 299.98,
            Currency = "EUR",
            LineItems = new[]
            {
                new OrderLineItemModel
                {
                    ProductId = "PROD-001",
                    SkuId = "SKU-001-BLK-M",
                    Quantity = 2,
                    UnitPrice = 99.99
                },
                new OrderLineItemModel
                {
                    ProductId = "PROD-042",
                    SkuId = "SKU-042-WHT-L",
                    Quantity = 1,
                    UnitPrice = 100.00
                }
            }
        }
    }
});

Console.WriteLine("Order event submitted successfully.");

Warning

Please keep in mind that all examples provided are for illustrative purposes only. They are not intended to represent best practices and should not be used in production without a thorough code review.