-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ecommerce example implementation (#458)
* Fixed sdkVersion property that is reported to the backend * Added example implementation of ecommerce order tracking * Removed old objective c implementation
- Loading branch information
Showing
6 changed files
with
179 additions
and
239 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// EcommerceViewController.swift | ||
// iOSExampleApp | ||
// | ||
// Created by Cornelius Horstmann on 05.09.24. | ||
// Copyright © 2024 Mattias Levin. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import MatomoTracker | ||
|
||
class EcommerceViewController: UIViewController { | ||
@IBOutlet weak var itemCountStepper: UIStepper! | ||
|
||
@IBOutlet weak var numberOfItemsTextField: UITextField! | ||
@IBOutlet weak var totalCostLabel: UILabel! | ||
@IBOutlet weak var taxLabel: UILabel! | ||
@IBOutlet weak var shippingCostLabel: UILabel! | ||
|
||
private var total: Double { | ||
itemCountStepper.value * 3.0 | ||
} | ||
private var tax: Double { | ||
total * 0.3 | ||
} | ||
private var shipping: Double { | ||
max(1, itemCountStepper.value / 3.0) * 0.1 | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
MatomoTracker.shared.track(view: ["menu","ecommerce"]) | ||
} | ||
|
||
@IBAction func itemCountValueChanged(_ stepper: UIStepper) { | ||
numberOfItemsTextField.text = String(format: "%.0f", stepper.value) | ||
|
||
totalCostLabel.text = String(format: "%.2f", total) | ||
taxLabel.text = String(format: "%.2f", tax) | ||
shippingCostLabel.text = String(format: "%.2f", shipping) | ||
} | ||
|
||
@IBAction func purchaseButtonTapped(_ sender: Any) { | ||
let orderItem = OrderItem(sku: "SKU123", name: "Cookies", category: "Food", price: 1.0, quantity: Int(itemCountStepper.value)) | ||
MatomoTracker.shared.trackOrder(id: "Trans-\(arc4random_uniform(1000))", items: [orderItem], revenue: Float(total)) | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.