Skip to content

Commit f958e4f

Browse files
committed
extract POSCollectOrderPaymentAnalytics to file
1 parent da2729f commit f958e4f

File tree

4 files changed

+43
-37
lines changed

4 files changed

+43
-37
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Yosemite
2+
3+
final class POSCollectOrderPaymentAnalytics: CollectOrderPaymentAnalyticsTracking {
4+
var connectedReaderModel: String?
5+
6+
private var customerInteractionStarted: Double = 0
7+
8+
func preflightResultReceived(_ result: CardReaderPreflightResult?) { }
9+
func trackProcessingCompletion(intent: Yosemite.PaymentIntent) { }
10+
11+
func trackSuccessfulPayment(capturedPaymentData: CardPresentCapturedPaymentData) {
12+
let elapsedTime = calculateElapsedTimeInMilliseconds(start: customerInteractionStarted, end: Date().timeIntervalSince1970)
13+
ServiceLocator.analytics.track(event:
14+
.PointOfSale.cardPresentCollectPaymentSuccess(millisecondsSinceCustomerIteractionStated: elapsedTime))
15+
}
16+
17+
func trackPaymentFailure(with error: any Error) { }
18+
func trackPaymentCancelation(cancelationSource: WooAnalyticsEvent.InPersonPayments.CancellationSource) { }
19+
func trackEmailTapped() { }
20+
func trackReceiptPrintTapped() { }
21+
func trackReceiptPrintSuccess() { }
22+
func trackReceiptPrintCanceled() { }
23+
func trackReceiptPrintFailed(error: any Error) { }
24+
25+
func trackCustomerInteractionStarted() {
26+
customerInteractionStarted = Date().timeIntervalSince1970
27+
}
28+
29+
private func calculateElapsedTimeInMilliseconds(start: Double, end: Double) -> Double {
30+
(end - start) * 1000
31+
}
32+
}
33+
34+
// Protocol conformance. These events are not needed for IPP, only for POS.
35+
extension CollectOrderPaymentAnalytics {
36+
func trackCustomerInteractionStarted() { }
37+
}

WooCommerce/Classes/POS/Analytics/WooAnalyticsEvent+PointOfSale.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension WooAnalyticsEvent {
3535

3636
static func cardPresentCollectPaymentSuccess(millisecondsSinceCustomerIteractionStated: Double) -> WooAnalyticsEvent {
3737
WooAnalyticsEvent(statName: .collectPaymentSuccess, properties: [
38-
Key.millisecondsSinceCustomerInteractionStarted : "\(millisecondsSinceCustomerIteractionStated)"]
38+
Key.millisecondsSinceCustomerInteractionStarted: "\(millisecondsSinceCustomerIteractionStated)"]
3939
)
4040
}
4141
}

WooCommerce/Classes/ViewRelated/Orders/Collect Payments/CollectOrderPaymentAnalytics.swift

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,8 @@ protocol CollectOrderPaymentAnalyticsTracking {
2424
func trackReceiptPrintCanceled()
2525

2626
func trackReceiptPrintFailed(error: Error)
27-
28-
func trackCustomerInteractionStarted()
29-
}
30-
31-
final class POSCollectOrderPaymentAnalytics: CollectOrderPaymentAnalyticsTracking {
32-
var connectedReaderModel: String?
33-
34-
private var customerInteractionStarted: Double = 0
35-
36-
func preflightResultReceived(_ result: CardReaderPreflightResult?) { }
37-
func trackProcessingCompletion(intent: Yosemite.PaymentIntent) { }
38-
39-
func trackSuccessfulPayment(capturedPaymentData: CardPresentCapturedPaymentData) {
40-
let elapsedTime = calculateElapsedTimeInMilliseconds(start: customerInteractionStarted, end: Date().timeIntervalSince1970)
41-
ServiceLocator.analytics.track(event: WooAnalyticsEvent.PointOfSale.cardPresentCollectPaymentSuccess(millisecondsSinceCustomerIteractionStated: elapsedTime))
42-
}
4327

44-
func trackPaymentFailure(with error: any Error) { }
45-
func trackPaymentCancelation(cancelationSource: WooAnalyticsEvent.InPersonPayments.CancellationSource) { }
46-
func trackEmailTapped() { }
47-
func trackReceiptPrintTapped() { }
48-
func trackReceiptPrintSuccess() { }
49-
func trackReceiptPrintCanceled() { }
50-
func trackReceiptPrintFailed(error: any Error) { }
51-
52-
func trackCustomerInteractionStarted() {
53-
customerInteractionStarted = Date().timeIntervalSince1970
54-
}
55-
56-
private func calculateElapsedTimeInMilliseconds(start: Double, end: Double) -> Double {
57-
(end - start) * 1000
58-
}
59-
}
60-
61-
// Protocol conformance. These events are not needed for IPP, only for POS.
62-
extension CollectOrderPaymentAnalytics {
63-
func trackCustomerInteractionStarted() { }
28+
func trackCustomerInteractionStarted()
6429
}
6530

6631
final class CollectOrderPaymentAnalytics: CollectOrderPaymentAnalyticsTracking {

WooCommerce/WooCommerce.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,7 @@
16271627
68E952D22875A44B0095A23D /* CardReaderType+Manual.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68E952D12875A44B0095A23D /* CardReaderType+Manual.swift */; };
16281628
68ED2BD62ADD2C8C00ECA88D /* LineDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68ED2BD52ADD2C8C00ECA88D /* LineDetailView.swift */; };
16291629
68F151E12C0DA7910082AEC8 /* CartItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68F151E02C0DA7910082AEC8 /* CartItem.swift */; };
1630+
68F896422D5E4323000B308B /* POSCollectOrderPaymentAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68F896412D5E4321000B308B /* POSCollectOrderPaymentAnalytics.swift */; };
16301631
740382DB2267D94100A627F4 /* LargeImageTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740382D92267D94100A627F4 /* LargeImageTableViewCell.swift */; };
16311632
740382DC2267D94100A627F4 /* LargeImageTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 740382DA2267D94100A627F4 /* LargeImageTableViewCell.xib */; };
16321633
740987B321B87760000E4C80 /* FancyAnimatedButton+Woo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 740987B221B87760000E4C80 /* FancyAnimatedButton+Woo.swift */; };
@@ -4773,6 +4774,7 @@
47734774
68E952D12875A44B0095A23D /* CardReaderType+Manual.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CardReaderType+Manual.swift"; sourceTree = "<group>"; };
47744775
68ED2BD52ADD2C8C00ECA88D /* LineDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineDetailView.swift; sourceTree = "<group>"; };
47754776
68F151E02C0DA7910082AEC8 /* CartItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CartItem.swift; sourceTree = "<group>"; };
4777+
68F896412D5E4321000B308B /* POSCollectOrderPaymentAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSCollectOrderPaymentAnalytics.swift; sourceTree = "<group>"; };
47764778
6A58DEEBCA91CDE69F439754 /* Pods_Woo_Watch_App.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Woo_Watch_App.framework; sourceTree = BUILT_PRODUCTS_DIR; };
47774779
6DC4526F9A7357761197EBF0 /* Pods_WooCommerceTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WooCommerceTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
47784780
72E1A3B02BE650CC82F2DA14 /* Pods-NotificationExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NotificationExtension.release.xcconfig"; path = "../Pods/Target Support Files/Pods-NotificationExtension/Pods-NotificationExtension.release.xcconfig"; sourceTree = "<group>"; };
@@ -7733,6 +7735,7 @@
77337735
02D1D2D82CD3CD710069A93F /* Analytics */ = {
77347736
isa = PBXGroup;
77357737
children = (
7738+
68F896412D5E4321000B308B /* POSCollectOrderPaymentAnalytics.swift */,
77367739
02D1D2D92CD3CD8D0069A93F /* WooAnalyticsEvent+PointOfSale.swift */,
77377740
);
77387741
path = Analytics;
@@ -16110,6 +16113,7 @@
1611016113
026826C02BF59E410036F959 /* PointOfSaleCardPresentPaymentConnectingFailedView.swift in Sources */,
1611116114
B586906621A5F4B1001F1EFC /* UINavigationController+Woo.swift in Sources */,
1611216115
45FBDF3A238D3F8B00127F77 /* ExtendedAddProductImageCollectionViewCell.swift in Sources */,
16116+
68F896422D5E4323000B308B /* POSCollectOrderPaymentAnalytics.swift in Sources */,
1611316117
029F53182BEB33BC00E31A10 /* CollapsibleCustomerCardAddressView.swift in Sources */,
1611416118
CE606D832BE14010001CB424 /* ShippingLineSelectionDetailsViewModel.swift in Sources */,
1611516119
02C7EE8A2B21B951008B7DF8 /* ProductWithQuantityStepperViewModel.swift in Sources */,

0 commit comments

Comments
 (0)