@@ -505,6 +505,8 @@ extension WooAnalyticsEvent {
505505 }
506506}
507507
508+
509+
508510// MARK: - Jetpack Benefits Banner
509511//
510512extension WooAnalyticsEvent {
@@ -535,3 +537,203 @@ extension WooAnalyticsEvent {
535537 WooAnalyticsEvent ( statName: . jetpackInstallButtonTapped, properties: [ " source " : source. rawValue] )
536538 }
537539}
540+
541+ // MARK: - In Person Payments
542+ //
543+ extension WooAnalyticsEvent {
544+
545+ enum InPersonPayments {
546+
547+ enum Keys {
548+ static let batteryLevel = " battery_level "
549+ static let gatewayID = " plugin_slug "
550+ static let errorDescription = " error_description "
551+ static let softwareUpdateType = " software_update_type "
552+ }
553+
554+ static let unknownGatewayID = " unknown "
555+
556+ static func gatewayID( forGatewayID gatewayID: String ? ) -> String {
557+ gatewayID ?? unknownGatewayID
558+ }
559+
560+ /// Tracked when card reader discovery fails
561+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
562+ /// `error` is the error to be included in the event properties.
563+ ///
564+ static func cardReaderDiscoveryFailed( forGatewayID: String ? , error: Error ) -> WooAnalyticsEvent {
565+ WooAnalyticsEvent ( statName: . cardReaderDiscoveryFailed,
566+ properties: [
567+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
568+ Keys . errorDescription: error. localizedDescription
569+ ]
570+ )
571+ }
572+
573+ /// Tracked when connecting to a card reader
574+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
575+ /// `batteryLevel` is the battery level (if available) to be included in the event properties in Tracks, e.g. 0.75 = 75%.
576+ ///
577+ static func cardReaderConnectionSuccess( forGatewayID: String ? , batteryLevel: Float ? ) -> WooAnalyticsEvent {
578+ var properties = [
579+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID)
580+ ]
581+
582+ if let batteryLevel = batteryLevel {
583+ properties [ Keys . batteryLevel] = String ( format: " %.2f " , batteryLevel)
584+ }
585+
586+ return WooAnalyticsEvent ( statName: . cardReaderConnectionSuccess, properties: properties)
587+ }
588+
589+ /// Tracked when connecting to a card reader fails
590+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
591+ /// `error` is the error to be included in the event properties.
592+ ///
593+ static func cardReaderConnectionFailed( forGatewayID: String ? , error: Error ) -> WooAnalyticsEvent {
594+ WooAnalyticsEvent ( statName: . cardReaderConnectionFailed,
595+ properties: [
596+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
597+ Keys . errorDescription: error. localizedDescription
598+ ]
599+ )
600+ }
601+
602+
603+ /// Tracked when disconnecting from a card reader
604+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
605+ ///
606+ static func cardReaderDisconnectTapped( forGatewayID: String ? ) -> WooAnalyticsEvent {
607+ WooAnalyticsEvent ( statName: . cardReaderDisconnectTapped,
608+ properties: [
609+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID)
610+ ]
611+ )
612+ }
613+ /// Tracksed when a software update is initiated manually
614+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
615+ /// `updateType` is `.required` or `.optional`
616+ ///
617+ static func cardReaderSoftwareUpdateTapped( forGatewayID: String ? , updateType: SoftwareUpdateTypeProperty ) -> WooAnalyticsEvent {
618+ WooAnalyticsEvent ( statName: . cardReaderSoftwareUpdateTapped,
619+ properties: [
620+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
621+ Keys . softwareUpdateType: updateType. rawValue
622+ ]
623+ )
624+ }
625+
626+ /// Tracked when a card reader update starts
627+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
628+ /// `updateType` is `.required` or `.optional`
629+ ///
630+ static func cardReaderSoftwareUpdateStarted( forGatewayID: String ? , updateType: SoftwareUpdateTypeProperty ) -> WooAnalyticsEvent {
631+ WooAnalyticsEvent ( statName: . cardReaderSoftwareUpdateStarted,
632+ properties: [
633+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
634+ Keys . softwareUpdateType: updateType. rawValue
635+ ]
636+ )
637+ }
638+
639+ /// Tracked when a card reader update fails
640+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
641+ /// `updateType` is `.required` or `.optional`
642+ /// `error` is the error to be included in the event properties.
643+ ///
644+ static func cardReaderSoftwareUpdateFailed(
645+ forGatewayID: String ? , updateType: SoftwareUpdateTypeProperty , error: Error
646+ ) -> WooAnalyticsEvent {
647+ WooAnalyticsEvent ( statName: . cardReaderSoftwareUpdateFailed,
648+ properties: [
649+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
650+ Keys . softwareUpdateType: updateType. rawValue,
651+ Keys . errorDescription: error. localizedDescription
652+ ]
653+ )
654+ }
655+
656+ /// Tracksed when a software update completes successfully
657+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
658+ /// `updateType` is `.required` or `.optional`
659+ ///
660+ static func cardReaderSoftwareUpdateSuccess( forGatewayID: String ? , updateType: SoftwareUpdateTypeProperty ) -> WooAnalyticsEvent {
661+ WooAnalyticsEvent ( statName: . cardReaderSoftwareUpdateSuccess,
662+ properties: [
663+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
664+ Keys . softwareUpdateType: updateType. rawValue
665+ ]
666+ )
667+ }
668+
669+ /// Tracked when an update cancel button is tapped
670+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
671+ ///
672+ static func cardReaderSoftwareUpdateCancelTapped( forGatewayID: String ? , updateType: SoftwareUpdateTypeProperty ) -> WooAnalyticsEvent {
673+ WooAnalyticsEvent ( statName: . cardReaderSoftwareUpdateCancelTapped,
674+ properties: [
675+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
676+ Keys . softwareUpdateType: updateType. rawValue
677+ ]
678+ )
679+ }
680+
681+ /// Tracked when an update is cancelled
682+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
683+ ///
684+ static func cardReaderSoftwareUpdateCanceled( forGatewayID: String ? , updateType: SoftwareUpdateTypeProperty ) -> WooAnalyticsEvent {
685+ WooAnalyticsEvent ( statName: . cardReaderSoftwareUpdateCanceled,
686+ properties: [
687+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
688+ Keys . softwareUpdateType: updateType. rawValue
689+ ]
690+ )
691+ }
692+
693+ /// Tracked when the user taps to collect a payment
694+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
695+ ///
696+ static func collectPaymentTapped( forGatewayID: String ? ) -> WooAnalyticsEvent {
697+ WooAnalyticsEvent ( statName: . collectPaymentTapped,
698+ properties: [
699+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID)
700+ ]
701+ )
702+ }
703+
704+ /// Tracked when the payment collection fails
705+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
706+ /// `error` is the error to be included in the event properties.
707+ ///
708+ static func collectPaymentFailed( forGatewayID: String ? , error: Error ) -> WooAnalyticsEvent {
709+ WooAnalyticsEvent ( statName: . collectPaymentFailed,
710+ properties: [
711+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID) ,
712+ Keys . errorDescription: error. localizedDescription
713+ ]
714+ )
715+ }
716+
717+ /// Tracked when the payment collection is cancelled
718+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
719+ ///
720+ static func collectPaymentCanceled( forGatewayID: String ? ) -> WooAnalyticsEvent {
721+ WooAnalyticsEvent ( statName: . collectPaymentCanceled,
722+ properties: [
723+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID)
724+ ]
725+ )
726+ }
727+
728+ /// Tracked when payment collection succeeds
729+ /// `forGatewayID` is the plugin (e.g. "woocommerce-payments" or "woocommerce-gateway-stripe") to be included in the event properties in Tracks.
730+ ///
731+ static func collectPaymentSuccess( forGatewayID: String ? ) -> WooAnalyticsEvent {
732+ WooAnalyticsEvent ( statName: . collectPaymentSuccess,
733+ properties: [
734+ Keys . gatewayID: gatewayID ( forGatewayID: forGatewayID)
735+ ]
736+ )
737+ }
738+ }
739+ }
0 commit comments