Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ecommerce example implementation #458

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading