Skip to content

Commit

Permalink
Added ecommerce example implementation (#458)
Browse files Browse the repository at this point in the history
* Fixed sdkVersion property that is reported to the backend

* Added example implementation of ecommerce order tracking

* Removed old objective c implementation
  • Loading branch information
brototyp authored Sep 5, 2024
1 parent 6b86f84 commit 8f90664
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 239 deletions.
22 changes: 0 additions & 22 deletions Example/ios/iOS Example/EcommerceViewController.h

This file was deleted.

91 changes: 0 additions & 91 deletions Example/ios/iOS Example/EcommerceViewController.m

This file was deleted.

49 changes: 49 additions & 0 deletions Example/ios/iOS Example/EcommerceViewController.swift
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))
}

}

Loading

0 comments on commit 8f90664

Please sign in to comment.