sendTransaction
DeprecatedThis 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| orderID | string | Yes | The unique order ID. |
| orderGrandTotal | NSNumber | Yes | Total payment for the order. Includes tax, shipping and discounts. Format: 1/100 of the base currency unit. Example: 100 is 1 USD. |
| orderSubTotal | NSNumber | No | Payment for the order without shipping. Format: 1/100 of the base currency unit. Example: 100 is 1 USD. |
| orderTax | NSNumber | No | Tax included in the order. Format: 1/100 of the base currency unit. Example: 100 is 1 USD. |
| orderShipping | NSNumber | No | Shipping costs for the order. Format: 1/100 of the base currency unit. Example: 100 is 1 USD. |
| orderDiscount | NSNumber | No | Discounts 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
PiwikTransactionBuilderAPI. Build aPiwikTransaction(optionally adding items withaddItem), then callsendTransaction(transaction:)to dispatch the order to Piwik PRO. - The
PiwikTransaction { ... }factory’sbuildcan returnnilif the order ID or grand total is missing, or if any line item is invalid. Do not callsendTransaction(transaction:)with aniltransaction — unwrap or validate the instance first (for example withif 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
PiwikTransactionyou create is independent and starts empty. - For new code, use
ecommerceOrder()with theEcommerceProductsbuilder instead.
Related methods
Updated 15 days ago