From d9713f1e52a67183d0460952590b56abf4f7e2ae Mon Sep 17 00:00:00 2001 From: Valentina Iancu Date: Wed, 17 Apr 2024 17:48:34 +0200 Subject: [PATCH] feat(GiniCaptureSDK): Add help screen events - events added: `screen_shown`, `close_tapped`, `helpItemTapped` PP-393 --- .../HelpMenu/HelpMenuDataSource.swift | 14 +++++++------ .../HelpMenuViewController.swift | 21 ++++++++++++++++++- .../GiniScreenAPICoordinator+Analysis.swift | 3 +-- .../GiniScreenAPICoordinator.swift | 7 ++++++- .../Core/Tracking/AnalyticsEvent.swift | 3 +++ .../Core/Tracking/AnalyticsProperties.swift | 14 ++++++------- .../Core/Tracking/AnalyticsScreen.swift | 1 + 7 files changed, 45 insertions(+), 18 deletions(-) diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/DataSources/HelpMenu/HelpMenuDataSource.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/DataSources/HelpMenu/HelpMenuDataSource.swift index 28fc2f2f3..35b6db4e8 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/DataSources/HelpMenu/HelpMenuDataSource.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/DataSources/HelpMenu/HelpMenuDataSource.swift @@ -9,7 +9,7 @@ import UIKit protocol HelpMenuDataSourceDelegate: UIViewController { - func didSelectHelpItem(didSelect item: HelpMenuItem) + func didSelectHelpItem(at index: Int) } final class HelpMenuDataSource: HelpRoundedCornersDataSource { @@ -26,14 +26,17 @@ final class HelpMenuDataSource: HelpRoundedCornersDataSource CGFloat { diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift index 16a98a201..8a9d71a61 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Help/ViewControllers/HelpMenuViewController.swift @@ -58,6 +58,20 @@ final class HelpMenuViewController: UIViewController, HelpBottomBarEnabledViewCo setupView() } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + var eventProperties = [AnalyticsProperty(key: .hasCustomItems, + value: giniConfiguration.customMenuItems.isNotEmpty)] + + if dataSource.helpItemsAnalyticsValues.isNotEmpty { + eventProperties.append(AnalyticsProperty(key: .helpItems, + value: dataSource.helpItemsAnalyticsValues)) + } + AnalyticsManager.trackScreenShown(screenName: .help, + properties: eventProperties) + } + private func setupView() { configureMainView() configureTableView() @@ -135,7 +149,12 @@ final class HelpMenuViewController: UIViewController, HelpBottomBarEnabledViewCo // MARK: - HelpMenuDataSourceDelegate extension HelpMenuViewController: HelpMenuDataSourceDelegate { - func didSelectHelpItem(didSelect item: HelpMenuItem) { + func didSelectHelpItem(at index: Int) { + let item = dataSource.items[index] + AnalyticsManager.track(event: .helpItemTapped, + screenName: .help, + properties: [AnalyticsProperty(key: .itemTapped, + value: item.title)]) delegate?.help(self, didSelect: item) } } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator+Analysis.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator+Analysis.swift index 1c9f53e31..97e154678 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator+Analysis.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator+Analysis.swift @@ -140,8 +140,7 @@ extension GiniScreenAPICoordinator: AnalysisDelegate { let viewController = ErrorScreenViewController(giniConfiguration: giniConfiguration, type: errorType, documentType: pages.type ?? .pdf, - viewModel: viewModel, - errorAnalytics: ErrorAnalytics(type: "")) + viewModel: viewModel) screenAPINavigationController.pushViewController(viewController, animated: animated) } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator.swift index 431c37d7b..2433391b6 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Screens/Screen API Coordinator/GiniScreenAPICoordinator.swift @@ -249,7 +249,7 @@ extension GiniScreenAPICoordinator { let backButtonTitle = NSLocalizedStringPreferredFormat("ginicapture.navigationbar.help.backToCamera", comment: "Camera") let barButton = GiniBarButton(ofType: .back(title: backButtonTitle)) - barButton.addAction(self, #selector(back)) + barButton.addAction(self, #selector(backToCameraTapped)) helpMenuViewController.navigationItem.leftBarButtonItem = barButton.barButton // In case of 1 menu item it's better to show the item immediately without any selection @@ -264,6 +264,11 @@ extension GiniScreenAPICoordinator { } } + @objc func backToCameraTapped() { + AnalyticsManager.track(event: .closeTapped, screenName: .help) + back() + } + @objc func showAnalysisScreen() { if screenAPINavigationController.topViewController is ReviewViewController { trackingDelegate?.onReviewScreenEvent(event: Event(type: .next)) diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsEvent.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsEvent.swift index ab1f96e3b..755d3e565 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsEvent.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsEvent.swift @@ -32,4 +32,7 @@ enum AnalyticsEvent: String { case enterManuallyTapped = "enter_manually_tapped" case retakeImagesTapped = "retake_images_tapped" case backToCameraTapped = "back_to_camera_tapped" + + // MARK: - Help + case helpItemTapped = "help_item_tapped" } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsProperties.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsProperties.swift index 17236df8e..9f67b0db2 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsProperties.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsProperties.swift @@ -27,20 +27,14 @@ extension Int: AnalyticsPropertyValue { } } -extension UInt: AnalyticsPropertyValue { - func analyticsPropertyValue() -> UInt { - return self - } -} - extension Bool: AnalyticsPropertyValue { func analyticsPropertyValue() -> Bool { return self } } -extension Double: AnalyticsPropertyValue { - func analyticsPropertyValue() -> Double { +extension Array: AnalyticsPropertyValue where Element == String { + func analyticsPropertyValue() -> [String] { return self } } @@ -57,4 +51,8 @@ enum AnalyticsPropertyKey: String { case documentType = "document_type" case errorCode = "error_code" case errorType = "error_type" + + case hasCustomItems = "has_custom_items" + case helpItems = "help_items" + case itemTapped = "item_tapped" } diff --git a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsScreen.swift b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsScreen.swift index c6e1a4800..34686f897 100644 --- a/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsScreen.swift +++ b/CaptureSDK/GiniCaptureSDK/Sources/GiniCaptureSDK/Core/Tracking/AnalyticsScreen.swift @@ -13,4 +13,5 @@ enum AnalyticsScreen: String { case analysis case noResults = "no_results" case error + case help }