forked from woocommerce/woocommerce-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWooAnalyticsEvent.swift
741 lines (638 loc) · 31.1 KB
/
WooAnalyticsEvent.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
import Foundation
import Yosemite
/// This struct represents an analytics event. It is a combination of `WooAnalyticsStat` and
/// its properties.
///
/// This was mostly created to promote static-typing via constructors.
///
/// ## Adding New Events
///
/// 1. Add the event name (`String`) to `WooAnalyticsStat`.
/// 2. Create an `extension` of `WooAnalyticsStat` if necessary for grouping.
/// 3. Add a `static func` constructor.
///
/// Here is an example:
///
/// ~~~
/// extension WooAnalyticsEvent {
/// enum LoginStep: String {
/// case start
/// case success
/// }
///
/// static func login(step: LoginStep) -> WooAnalyticsEvent {
/// let properties = [
/// "step": step.rawValue
/// ]
///
/// return WooAnalyticsEvent(name: "login", properties: properties)
/// }
/// }
/// ~~~
///
/// Examples of tracking calls (in the client App or Pod):
///
/// ~~~
/// Analytics.track(event: .login(step: .start))
/// Analytics.track(event: .loginStart)
/// ~~~
///
public struct WooAnalyticsEvent {
let statName: WooAnalyticsStat
let properties: [String: WooAnalyticsEventPropertyType]
}
// MARK: - In-app Feedback and Survey
extension WooAnalyticsEvent {
/// The action performed on the In-app Feedback Card.
public enum AppFeedbackPromptAction: String {
case shown
case liked
case didntLike = "didnt_like"
}
/// Where the feedback was shown. This is shared by a couple of events.
public enum FeedbackContext: String {
/// Shown in Stats but is for asking general feedback.
case general
/// Shown in products banner for Variations release.
case productsVariations = "products_variations"
/// Shown in shipping labels banner for Milestone 3 features.
case shippingLabelsRelease3 = "shipping_labels_m3"
/// Shown in beta feature banner for order add-ons.
case addOnsI1 = "add-ons_i1"
/// Shown in beta feature banner for simple payments prototype.
case simplePaymentsPrototype = "simple_payments_prototype"
/// Shown in beta feature banner for coupon management.
case couponManagement = "coupon_management"
}
/// The action performed on the survey screen.
public enum SurveyScreenAction: String {
case opened
case canceled
case completed
}
/// The action performed on "New Features" banners like in Products.
public enum FeatureFeedbackBannerAction: String {
case gaveFeedback = "gave_feedback"
case dismissed
}
/// The action performed on a shipment tracking number like in a shipping label card in order details.
public enum ShipmentTrackingMenuAction: String {
case track
case copy
}
/// The result of a shipping labels API GET request.
public enum ShippingLabelsAPIRequestResult {
case success
case failed(error: Error)
fileprivate var rawValue: String {
switch self {
case .success:
return "success"
case .failed:
return "failed"
}
}
}
static func appFeedbackPrompt(action: AppFeedbackPromptAction) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .appFeedbackPrompt, properties: ["action": action.rawValue])
}
static func surveyScreen(context: FeedbackContext, action: SurveyScreenAction) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .surveyScreen, properties: ["context": context.rawValue, "action": action.rawValue])
}
static func featureFeedbackBanner(context: FeedbackContext, action: FeatureFeedbackBannerAction) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .featureFeedbackBanner, properties: ["context": context.rawValue, "action": action.rawValue])
}
static func shipmentTrackingMenu(action: ShipmentTrackingMenuAction) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .shipmentTrackingMenuAction, properties: ["action": action.rawValue])
}
static func shippingLabelsAPIRequest(result: ShippingLabelsAPIRequestResult) -> WooAnalyticsEvent {
switch result {
case .success:
return WooAnalyticsEvent(statName: .shippingLabelsAPIRequest, properties: ["action": result.rawValue])
case .failed(let error):
return WooAnalyticsEvent(statName: .shippingLabelsAPIRequest, properties: [
"action": result.rawValue,
"error": error.localizedDescription
])
}
}
static func ordersListLoaded(totalDuration: TimeInterval, pageNumber: Int, filters: FilterOrderListViewModel.Filters?) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .ordersListLoaded, properties: [
"status": (filters?.orderStatus ?? []).map { $0.rawValue }.joined(separator: ","),
"page_number": Int64(pageNumber),
"total_duration": Double(totalDuration),
"date_range": filters?.dateRange?.analyticsDescription ?? String()
])
}
}
// MARK: - Issue Refund
//
extension WooAnalyticsEvent {
// Namespace
enum IssueRefund {
/// The state of the "refund shipping" button
enum ShippingSwitchState: String {
case on
case off
}
// The method used for the refund
enum RefundMethod: String {
case items = "ITEMS"
case amount = "AMOUNT"
}
static func createRefund(orderID: Int64, fullyRefunded: Bool, method: RefundMethod, gateway: String, amount: String) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .refundCreate, properties: [
"order_id": "\(orderID)",
"is_full": "\(fullyRefunded)",
"method": method.rawValue,
"gateway": gateway,
"amount": amount
])
}
static func createRefundSuccess(orderID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .refundCreateSuccess, properties: ["order_id": "\(orderID)"])
}
static func createRefundFailed(orderID: Int64, error: Error) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .refundCreateFailed, properties: [
"order_id": "\(orderID)",
"error_description": error.localizedDescription,
])
}
static func selectAllButtonTapped(orderID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createOrderRefundSelectAllItemsButtonTapped, properties: ["order_id": "\(orderID)"])
}
static func quantityDialogOpened(orderID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createOrderRefundItemQuantityDialogOpened, properties: ["order_id": "\(orderID)"])
}
static func nextButtonTapped(orderID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createOrderRefundNextButtonTapped, properties: ["order_id": "\(orderID)"])
}
static func summaryButtonTapped(orderID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createOrderRefundSummaryRefundButtonTapped, properties: ["order_id": "\(orderID)"])
}
static func shippingSwitchTapped(orderID: Int64, state: ShippingSwitchState) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createOrderRefundShippingOptionTapped, properties: ["order_id": "\(orderID)", "action": state.rawValue])
}
}
}
// MARK: - Variations
//
extension WooAnalyticsEvent {
// Namespace
enum Variations {
/// Common event keys
///
private enum Keys {
static let productID = "product_id"
static let variationID = "product_variation_id"
static let serverTime = "time"
static let errorDescription = "error_description"
}
static func addFirstVariationButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .addFirstVariationButtonTapped, properties: [Keys.productID: "\(productID)"])
}
static func addMoreVariationsButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .addMoreVariationsButtonTapped, properties: [Keys.productID: "\(productID)"])
}
static func createVariation(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createProductVariation, properties: [Keys.productID: "\(productID)"])
}
static func createVariationSuccess(productID: Int64, time: Double) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createProductVariationSuccess, properties: [Keys.productID: "\(productID)", Keys.serverTime: "\(time)"])
}
static func createVariationFail(productID: Int64, time: Double, error: Error) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .createProductVariationFailed, properties: [Keys.productID: "\(productID)",
Keys.serverTime: "\(time)",
Keys.errorDescription: error.localizedDescription])
}
static func removeVariationButtonTapped(productID: Int64, variationID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .removeProductVariationButtonTapped, properties: [Keys.productID: "\(productID)", Keys.variationID: "\(variationID)"])
}
static func editAttributesButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .editProductAttributesButtonTapped, properties: [Keys.productID: "\(productID)"])
}
static func addAttributeButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .addProductAttributeButtonTapped, properties: [Keys.productID: "\(productID)"])
}
static func updateAttribute(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .updateProductAttribute, properties: [Keys.productID: "\(productID)"])
}
static func updateAttributeSuccess(productID: Int64, time: Double) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .updateProductAttributeSuccess, properties: [Keys.productID: "\(productID)", Keys.serverTime: "\(time)"])
}
static func updateAttributeFail(productID: Int64, time: Double, error: Error) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .updateProductAttributeFail, properties: [Keys.productID: "\(productID)",
Keys.serverTime: "\(time)",
Keys.errorDescription: error.localizedDescription])
}
static func renameAttributeButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .renameProductAttributeButtonTapped, properties: [Keys.productID: "\(productID)"])
}
static func removeAttributeButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .removeProductAttributeButtonTapped, properties: [Keys.productID: "\(productID)"])
}
static func editVariationAttributeOptionsRowTapped(productID: Int64, variationID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .editProductVariationAttributeOptionsRowTapped, properties: [Keys.productID: "\(productID)",
Keys.variationID: "\(variationID)"])
}
static func editVariationAttributeOptionsDoneButtonTapped(productID: Int64, variationID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .editProductVariationAttributeOptionsDoneButtonTapped, properties: [Keys.productID: "\(productID)",
Keys.variationID: "\(variationID)"])
}
}
}
// MARK: - Order Detail Add-ons
//
extension WooAnalyticsEvent {
// Namespace
enum OrderDetailAddOns {
/// Common event keys
///
private enum Keys {
static let state = "state"
static let addOns = "add_ons"
}
static func betaFeaturesSwitchToggled(isOn: Bool) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .settingsBetaFeaturesOrderAddOnsToggled, properties: [Keys.state: isOn ? "on" : "off"])
}
static func orderAddOnsViewed(addOnNames: [String]) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderDetailAddOnsViewed, properties: [Keys.addOns: addOnNames.joined(separator: ",")])
}
}
}
// MARK: - Product Detail Add-ons
//
extension WooAnalyticsEvent {
/// Common event keys
///
private enum Keys {
static let productID = "product_id"
}
// Namespace
enum ProductDetailAddOns {
static func productAddOnsButtonTapped(productID: Int64) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .productDetailViewProductAddOnsTapped, properties: [Keys.productID: "\(productID)"])
}
}
}
// MARK: - Order General
//
extension WooAnalyticsEvent {
// Namespace
enum Orders {
/// Possible Order Flows
///
enum Flow: String {
case creation
case editing
}
private enum Keys {
static let flow = "flow"
static let hasDifferentShippingDetails = "has_different_shipping_details"
static let orderStatus = "order_status"
static let productCount = "product_count"
static let hasCustomerDetails = "has_customer_details"
static let errorContext = "error_context"
static let errorDescription = "error_description"
static let to = "to"
static let from = "from"
static let orderID = "id"
}
static func orderAddNew() -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderAddNew, properties: [:])
}
static func orderProductAdd(flow: Flow) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderProductAdd, properties: [Keys.flow: flow.rawValue])
}
static func orderCustomerAdd(flow: Flow, hasDifferentShippingDetails: Bool) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderCustomerAdd, properties: [
Keys.flow: flow.rawValue,
Keys.hasDifferentShippingDetails: hasDifferentShippingDetails
])
}
static func orderStatusChange(flow: Flow, orderID: Int64?, from oldStatus: OrderStatusEnum, to newStatus: OrderStatusEnum) -> WooAnalyticsEvent {
let properties: [String: WooAnalyticsEventPropertyType?] = [
Keys.flow: flow.rawValue,
Keys.orderID: orderID,
Keys.from: oldStatus.rawValue,
Keys.to: newStatus.rawValue
]
return WooAnalyticsEvent(statName: .orderStatusChange, properties: properties.compactMapValues { $0 })
}
static func orderCreateButtonTapped(status: OrderStatusEnum,
productCount: Int,
hasCustomerDetails: Bool) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderCreateButtonTapped, properties: [
Keys.orderStatus: status.rawValue,
Keys.productCount: Int64(productCount),
Keys.hasCustomerDetails: hasCustomerDetails
])
}
static func orderCreationSuccess() -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderCreationSuccess, properties: [:])
}
static func orderCreationFailed(errorContext: String, errorDescription: String) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderCreationFailed, properties: [
Keys.errorContext: errorContext,
Keys.errorDescription: errorDescription
])
}
}
}
// MARK: - Order Details Edit
//
extension WooAnalyticsEvent {
// Namespace
enum OrderDetailsEdit {
/// Possible types of edit
///
enum Subject: String {
fileprivate static let key = "subject"
case customerNote = "customer_note"
case shippingAddress = "shipping_address"
case billingAddress = "billing_address"
}
static func orderDetailEditFlowStarted(subject: Subject) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderDetailEditFlowStarted, properties: [Subject.key: subject.rawValue])
}
static func orderDetailEditFlowCompleted(subject: Subject) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderDetailEditFlowCompleted, properties: [Subject.key: subject.rawValue])
}
static func orderDetailEditFlowFailed(subject: Subject) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderDetailEditFlowFailed, properties: [Subject.key: subject.rawValue])
}
static func orderDetailEditFlowCanceled(subject: Subject) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .orderDetailEditFlowCanceled, properties: [Subject.key: subject.rawValue])
}
}
}
// MARK: - What's New Component
//
extension WooAnalyticsEvent {
/// Possible sources for the What's New component
///
enum Source: String {
fileprivate static let key = "source"
case appUpgrade = "app_upgrade"
case appSettings = "app_settings"
}
static func featureAnnouncementShown(source: Source) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .featureAnnouncementShown, properties: [Source.key: source.rawValue])
}
}
// MARK: - Simple Payments
//
extension WooAnalyticsEvent {
// Namespace
enum SimplePayments {
/// Possible Payment Methods
///
enum PaymentMethod: String {
case card
case cash
case paymentLink = "payment_link"
}
/// Possible view sources
///
enum Source: String {
case amount
case summary
case paymentMethod = "payment_method"
}
/// Common event keys
///
private enum Keys {
static let state = "state"
static let amount = "amount"
static let paymentMethod = "payment_method"
static let source = "source"
}
static func simplePaymentsFlowStarted() -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowStarted, properties: [:])
}
static func simplePaymentsFlowCompleted(amount: String, method: PaymentMethod) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowCompleted, properties: [Keys.amount: amount, Keys.paymentMethod: method.rawValue])
}
static func simplePaymentsFlowCanceled() -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowCanceled, properties: [:])
}
static func simplePaymentsFlowFailed(source: Source) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowFailed, properties: [Keys.source: source.rawValue])
}
static func simplePaymentsFlowNoteAdded() -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowNoteAdded, properties: [:])
}
static func simplePaymentsFlowTaxesToggled(isOn: Bool) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowTaxesToggled, properties: [Keys.state: isOn ? "on" : "off"])
}
static func simplePaymentsFlowCollect(method: PaymentMethod) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .simplePaymentsFlowCollect, properties: [Keys.paymentMethod: method.rawValue])
}
}
}
// MARK: - Jetpack Benefits Banner
//
extension WooAnalyticsEvent {
/// The action performed on the Jetpack benefits banner.
enum JetpackBenefitsBannerAction: String {
case shown
case dismissed
case tapped
}
/// Tracked on various states of the Jetpack benefits banner in dashboard.
static func jetpackBenefitsBanner(action: JetpackBenefitsBannerAction) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .jetpackBenefitsBanner, properties: ["action": action.rawValue])
}
}
// MARK: - Jetpack Install
//
extension WooAnalyticsEvent {
/// The source that presents the Jetpack install screen.
enum JetpackInstallSource: String {
case settings
case benefitsModal = "benefits_modal"
}
/// Tracked when the user taps to install Jetpack.
static func jetpackInstallButtonTapped(source: JetpackInstallSource) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .jetpackInstallButtonTapped, properties: ["source": source.rawValue])
}
}
// MARK: - In Person Payments
//
extension WooAnalyticsEvent {
enum InPersonPayments {
enum Keys {
static let batteryLevel = "battery_level"
static let gatewayID = "plugin_slug"
static let errorDescription = "error_description"
static let softwareUpdateType = "software_update_type"
}
static let unknownGatewayID = "unknown"
static func gatewayID(forGatewayID gatewayID: String?) -> String {
gatewayID ?? unknownGatewayID
}
/// Tracked when card reader discovery fails
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `error` is the error to be included in the event properties.
///
static func cardReaderDiscoveryFailed(forGatewayID: String?, error: Error) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderDiscoveryFailed,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.errorDescription: error.localizedDescription
]
)
}
/// Tracked when connecting to a card reader
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `batteryLevel` is the battery level (if available) to be included in the event properties in Tracks, e.g. 0.75 = 75%.
///
static func cardReaderConnectionSuccess(forGatewayID: String?, batteryLevel: Float?) -> WooAnalyticsEvent {
var properties = [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID)
]
if let batteryLevel = batteryLevel {
properties[Keys.batteryLevel] = String(format: "%.2f", batteryLevel)
}
return WooAnalyticsEvent(statName: .cardReaderConnectionSuccess, properties: properties)
}
/// Tracked when connecting to a card reader fails
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `error` is the error to be included in the event properties.
///
static func cardReaderConnectionFailed(forGatewayID: String?, error: Error) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderConnectionFailed,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.errorDescription: error.localizedDescription
]
)
}
/// Tracked when disconnecting from a card reader
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
///
static func cardReaderDisconnectTapped(forGatewayID: String?) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderDisconnectTapped,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID)
]
)
}
/// Tracksed when a software update is initiated manually
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `updateType` is `.required` or `.optional`
///
static func cardReaderSoftwareUpdateTapped(forGatewayID: String?, updateType: SoftwareUpdateTypeProperty) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderSoftwareUpdateTapped,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.softwareUpdateType: updateType.rawValue
]
)
}
/// Tracked when a card reader update starts
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `updateType` is `.required` or `.optional`
///
static func cardReaderSoftwareUpdateStarted(forGatewayID: String?, updateType: SoftwareUpdateTypeProperty) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderSoftwareUpdateStarted,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.softwareUpdateType: updateType.rawValue
]
)
}
/// Tracked when a card reader update fails
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `updateType` is `.required` or `.optional`
/// `error` is the error to be included in the event properties.
///
static func cardReaderSoftwareUpdateFailed(
forGatewayID: String?, updateType: SoftwareUpdateTypeProperty, error: Error
) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderSoftwareUpdateFailed,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.softwareUpdateType: updateType.rawValue,
Keys.errorDescription: error.localizedDescription
]
)
}
/// Tracksed when a software update completes successfully
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `updateType` is `.required` or `.optional`
///
static func cardReaderSoftwareUpdateSuccess(forGatewayID: String?, updateType: SoftwareUpdateTypeProperty) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderSoftwareUpdateSuccess,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.softwareUpdateType: updateType.rawValue
]
)
}
/// Tracked when an update cancel button is tapped
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
///
static func cardReaderSoftwareUpdateCancelTapped(forGatewayID: String?, updateType: SoftwareUpdateTypeProperty) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderSoftwareUpdateCancelTapped,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.softwareUpdateType: updateType.rawValue
]
)
}
/// Tracked when an update is cancelled
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
///
static func cardReaderSoftwareUpdateCanceled(forGatewayID: String?, updateType: SoftwareUpdateTypeProperty) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .cardReaderSoftwareUpdateCanceled,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.softwareUpdateType: updateType.rawValue
]
)
}
/// Tracked when the user taps to collect a payment
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
///
static func collectPaymentTapped(forGatewayID: String?) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .collectPaymentTapped,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID)
]
)
}
/// Tracked when the payment collection fails
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
/// `error` is the error to be included in the event properties.
///
static func collectPaymentFailed(forGatewayID: String?, error: Error) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .collectPaymentFailed,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID),
Keys.errorDescription: error.localizedDescription
]
)
}
/// Tracked when the payment collection is cancelled
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
///
static func collectPaymentCanceled(forGatewayID: String?) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .collectPaymentCanceled,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID)
]
)
}
/// Tracked when payment collection succeeds
/// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
///
static func collectPaymentSuccess(forGatewayID: String?) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .collectPaymentSuccess,
properties: [
Keys.gatewayID: gatewayID(forGatewayID: forGatewayID)
]
)
}
}
}