addItem
DeprecatedThis method is no longer recommended. Use the ecommerceAddToCart() or ecommerceOrder() method with the
EcommerceProductsbuilder instead.
The addItem() method appends a line item to the in-memory PiwikTransactionBuilder used with the legacy sendTransaction() flow. A shorter overload takes only the SKU (addItem(sku:)).
Syntax
builder.addItem(
sku: "sku",
name: "name",
category: "category",
price: price,
quantity: quantity
)
builder.addItem(sku: "sku")[builder addItemWithSku:@"sku"
name:@"name"
category:@"category"
price:@(price)
quantity:@(quantity)];
[builder addItemWithSku:@"sku"];Parameters
- sku
string, required- The stock-keeping unit of the added product. Must be non-empty for the line item to be valid when you callbuild(). - name
string, optional- The name of the added product. - category
string, optional- The category of the added product (single string in the SDK). - price
number, optional- The price of the added product. - quantity
number, optional- The number of added items.
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)
}[[PiwikTracker sharedInstance] sendTransaction:[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];
}]];Notes
- The cart contents are not persisted by the SDK. Each
PiwikTransactionbuilder starts empty, so when you build a new transaction (for example after the app is restarted) you need to add all items again. - This method doesn't send any data to Piwik PRO on its own. It only adds an item to the in-memory
PiwikTransactionBuilder. CallsendTransaction()on the resulting transaction to actually send the order to Piwik PRO.
Related methods
Updated 15 days ago