diff --git a/Example/ios/iOS Example/EcommerceViewController.h b/Example/ios/iOS Example/EcommerceViewController.h deleted file mode 100644 index aebdded4..00000000 --- a/Example/ios/iOS Example/EcommerceViewController.h +++ /dev/null @@ -1,22 +0,0 @@ -// -// EcommerceViewController.h -// PiwikTracker -// -// Created by Mattias Levin on 26/01/14. -// Copyright (c) 2014 Mattias Levin. All rights reserved. -// - -#import - -@interface EcommerceViewController : UIViewController - -@property (weak, nonatomic) IBOutlet UITextField *numberOfItemsTextField; -@property (weak, nonatomic) IBOutlet UILabel *totalCostLabel; -@property (weak, nonatomic) IBOutlet UILabel *taxLabel; -@property (weak, nonatomic) IBOutlet UILabel *shippingCostLabel; - - -- (IBAction)stepNumberOfItemsAction:(UIStepper *)sender; -- (IBAction)purchaseAction:(id)sender; - -@end diff --git a/Example/ios/iOS Example/EcommerceViewController.m b/Example/ios/iOS Example/EcommerceViewController.m deleted file mode 100644 index 64163387..00000000 --- a/Example/ios/iOS Example/EcommerceViewController.m +++ /dev/null @@ -1,91 +0,0 @@ -// -// EcommerceViewController.m -// PiwikTracker -// -// Created by Mattias Levin on 26/01/14. -// Copyright (c) 2014 Mattias Levin. All rights reserved. -// - -#import "EcommerceViewController.h" -#import "PiwikTransaction.h" -#import "PiwikTransactionBuilder.h" -#import "PiwikTracker.h" - - -static NSUInteger const ItemPrice = 1; - - -@implementation EcommerceViewController - -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; -} - - -- (void)viewDidLoad { - [super viewDidLoad]; - - [[PiwikTracker sharedInstance] sendViews:@"menu", @"transaction", nil]; - - // Start with one items - self.numberOfItemsTextField.text = @"1"; - - [self calculateCost]; - -} - - -- (IBAction)stepNumberOfItemsAction:(UIStepper *)sender { - - self.numberOfItemsTextField.text = [NSString stringWithFormat:@"%.0f", sender.value]; - - [self calculateCost]; - -} - - -- (IBAction)purchaseAction:(id)sender { - - PiwikTransaction *transaction = [PiwikTransaction transactionWithBuilder:^(PiwikTransactionBuilder *builder) { - - builder.identifier = [NSString stringWithFormat:@"Trans-%d", arc4random_uniform(1000)]; - builder.grandTotal = @([self.totalCostLabel.text floatValue]); - builder.tax = @([self.taxLabel.text floatValue]); - builder.shippingCost = @([self.shippingCostLabel.text floatValue]); - builder.discount = nil; - builder.subTotal = @([builder.grandTotal floatValue] - [builder.shippingCost floatValue]); - - //[builder addItemWithSku:@"SKU123"]; - - - [builder addItemWithSku:@"SKU123" - name:@"Cookies" - category:@"Food" - price:1.0 - quantity:[self.numberOfItemsTextField.text integerValue]]; - - }]; - - [[PiwikTracker sharedInstance] sendTransaction:transaction]; -} - - -- (void)calculateCost { - - int numberOfItems = (int)[self.numberOfItemsTextField.text integerValue]; - - int totalCost = numberOfItems * ItemPrice; - - self.totalCostLabel.text = [NSString stringWithFormat:@"%d", totalCost]; - self.taxLabel.text = [NSString stringWithFormat:@"%.1f", totalCost * 0.3]; - self.shippingCostLabel.text = [NSString stringWithFormat:@"%.1f", MAX(1, (numberOfItems / 3)) * 0.1]; - -} - - - -@end diff --git a/Example/ios/iOS Example/EcommerceViewController.swift b/Example/ios/iOS Example/EcommerceViewController.swift new file mode 100644 index 00000000..22720ce2 --- /dev/null +++ b/Example/ios/iOS Example/EcommerceViewController.swift @@ -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)) + } + +} + diff --git a/Example/ios/iOS Example/en.lproj/MainStoryboard.storyboard b/Example/ios/iOS Example/en.lproj/MainStoryboard.storyboard index 47eac3f3..a4edf1e4 100644 --- a/Example/ios/iOS Example/en.lproj/MainStoryboard.storyboard +++ b/Example/ios/iOS Example/en.lproj/MainStoryboard.storyboard @@ -1,11 +1,9 @@ - - - - + + - + @@ -28,11 +26,11 @@ - + - + @@ -40,14 +38,14 @@ - + @@ -60,14 +58,14 @@ - + @@ -80,14 +78,14 @@ - + @@ -100,14 +98,14 @@ - + @@ -120,14 +118,14 @@ - + @@ -140,14 +138,14 @@ - + @@ -160,14 +158,14 @@ - + @@ -184,14 +182,14 @@ - + @@ -208,14 +206,14 @@ - + @@ -224,18 +222,18 @@ -