sendTransaction

❗️

Deprecated

This method is no longer recommended. Use the ecommerceOrder() method instead.

The sendTransaction() method tracks a confirmed order.

Syntax

let transaction = PiwikTransaction { builder in
    builder.identifier = "orderID"
    builder.grandTotal = orderGrandTotal
    builder.subTotal = orderSubTotal
    builder.tax = orderTax
    builder.shippingCost = orderShipping
    builder.discount = orderDiscount
}

if let transaction {
    PiwikTracker.sharedInstance()?.sendTransaction(transaction: transaction)
}
PiwikTransaction *transaction = [PiwikTransaction transactionWithBlock:^(PiwikTransactionBuilder *builder) {
    builder.identifier = @"orderID";
    builder.grandTotal = @(orderGrandTotal);
    builder.subTotal = @(orderSubTotal);
    builder.tax = @(orderTax);
    builder.shippingCost = @(orderShipping);
    builder.discount = @(orderDiscount);
}];
if (transaction) {
    [[PiwikTracker sharedInstance] sendTransaction:transaction];
}

Parameters

ParameterTypeRequiredDescription
orderIDstringYesThe unique order ID.
orderGrandTotalNSNumberYesTotal payment for the order. Includes tax, shipping and discounts. Format: 1/100 of the base currency unit. Example: 100 is 1 USD.
orderSubTotalNSNumberNoPayment for the order without shipping. Format: 1/100 of the base currency unit. Example: 100 is 1 USD.
orderTaxNSNumberNoTax included in the order. Format: 1/100 of the base currency unit. Example: 100 is 1 USD.
orderShippingNSNumberNoShipping costs for the order. Format: 1/100 of the base currency unit. Example: 100 is 1 USD.
orderDiscountNSNumberNoDiscounts included in the order. Format: 1/100 of the base currency unit. Example: 100 is 1 USD.

Examples

To track a confirmed order:

let transaction = PiwikTransaction { builder in
    builder.identifier = "43967392"
    builder.grandTotal = 525000
    builder.subTotal = 520000
    builder.tax = 97000
    builder.shippingCost = 15000
    builder.discount = 10000

    builder.addItem(
        sku: "584340",
        name: "Specialized Stumpjumper",
        category: "Mountain bike",
        price: 500000,
        quantity: 1
    )

    builder.addItem(
        sku: "460923",
        name: "Specialized Chamonix",
        category: "Helmets",
        price: 20000,
        quantity: 1
    )
}

if let transaction {
    PiwikTracker.sharedInstance()?.sendTransaction(transaction: transaction)
}
PiwikTransaction *transaction = [PiwikTransaction transactionWithBlock:^(PiwikTransactionBuilder *builder) {
    builder.identifier = @"43967392";
    builder.grandTotal = @525000;
    builder.subTotal = @520000;
    builder.tax = @97000;
    builder.shippingCost = @15000;
    builder.discount = @10000;

    [builder addItemWithSku:@"584340"
                       name:@"Specialized Stumpjumper"
                   category:@"Mountain bike"
                      price:@500000
                   quantity:@1];

    [builder addItemWithSku:@"460923"
                       name:@"Specialized Chamonix"
                   category:@"Helmets"
                      price:@20000
                   quantity:@1];
}];
if (transaction) {
    [[PiwikTracker sharedInstance] sendTransaction:transaction];
}

Notes

  • This method works with the legacy PiwikTransactionBuilder API. Build a PiwikTransaction (optionally adding items with addItem), then call sendTransaction(transaction:) to dispatch the order to Piwik PRO.
  • The PiwikTransaction { ... } factory’s build can return nil if the order ID or grand total is missing, or if any line item is invalid. Do not call sendTransaction(transaction:) with a nil transaction — unwrap or validate the instance first (for example with if let).
  • If you add line items, each item must have a non-empty SKU or the transaction will not build.
  • The transaction builder does not persist any state between calls. Each PiwikTransaction you create is independent and starts empty.
  • For new code, use ecommerceOrder() with the EcommerceProducts builder instead.

Related methods