Skip to content

Commit

Permalink
feat(GiniCaptureSDK): Add help screen events
Browse files Browse the repository at this point in the history
- events added: `screen_shown`, `close_tapped`, `helpItemTapped`

PP-393
  • Loading branch information
ValentinaIancu-Gini committed Apr 17, 2024
1 parent 1c1b5d1 commit d9713f1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit

protocol HelpMenuDataSourceDelegate: UIViewController {
func didSelectHelpItem(didSelect item: HelpMenuItem)
func didSelectHelpItem(at index: Int)
}

final class HelpMenuDataSource: HelpRoundedCornersDataSource<HelpMenuItem, HelpMenuCell> {
Expand All @@ -26,14 +26,17 @@ final class HelpMenuDataSource: HelpRoundedCornersDataSource<HelpMenuItem, HelpM
return defaultItems
}()

var helpItemsAnalyticsValues = [String]()
weak var delegate: HelpMenuDataSourceDelegate?

required init(
configuration: GiniConfiguration
) {
required init(configuration: GiniConfiguration) {
super.init()
self.items.append(contentsOf: defaultItems)
self.items.append(contentsOf: configuration.customMenuItems)

items.forEach { item in
helpItemsAnalyticsValues.append(item.title)
}
}

override func configureCell(cell: HelpMenuCell, indexPath: IndexPath) {
Expand Down Expand Up @@ -63,8 +66,7 @@ final class HelpMenuDataSource: HelpRoundedCornersDataSource<HelpMenuItem, HelpM

// MARK: - UITableViewDelegate
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let item = items[indexPath.row]
self.delegate?.didSelectHelpItem(didSelect: item)
self.delegate?.didSelectHelpItem(at: indexPath.row)
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ enum AnalyticsScreen: String {
case analysis
case noResults = "no_results"
case error
case help
}

0 comments on commit d9713f1

Please sign in to comment.