From 93ba06b91529f7c552c3610eb6e4f0a9ed34d679 Mon Sep 17 00:00:00 2001 From: Ivan Magda Date: Thu, 31 Mar 2022 10:22:32 +0300 Subject: [PATCH] Analytics accessibility (#1142) * Report isVoiceOverRunning * Report fontScale * Refactor rename --- .../Analytics/AnalyticsUserProperties.swift | 39 ++++++++++++++----- Stepic/Legacy/AppDelegate.swift | 2 + 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Stepic/Legacy/Analytics/AnalyticsUserProperties.swift b/Stepic/Legacy/Analytics/AnalyticsUserProperties.swift index 9236218998..2fa9079950 100644 --- a/Stepic/Legacy/Analytics/AnalyticsUserProperties.swift +++ b/Stepic/Legacy/Analytics/AnalyticsUserProperties.swift @@ -1,15 +1,7 @@ -// -// AnalyticsUserProperties.swift -// Stepic -// -// Created by Ostrenkiy on 20.06.2018. -// Copyright © 2018 Alex Karpov. All rights reserved. -// - import Amplitude import FirebaseAnalytics import FirebaseCrashlytics -import Foundation +import UIKit import YandexMobileMetrica final class AnalyticsUserProperties: ABAnalyticsServiceProtocol { @@ -110,6 +102,33 @@ final class AnalyticsUserProperties: ABAnalyticsServiceProtocol { self.setAmplitudeProperty(key: UserPropertyKey.isNightModeEnabled.rawValue, value: "\(isEnabled)") } + func updateAccessibilityIsVoiceOverRunning() { + self.setAmplitudeProperty( + key: UserPropertyKey.isAccessibilityScreenReaderEnabled.rawValue, + value: UIAccessibility.isVoiceOverRunning + ) + } + + func updateAccessibilityFontScale() { + guard #available(iOS 13.0, *) else { + return + } + + let defaultBodyFont = UIFont.preferredFont( + forTextStyle: .body, + compatibleWith: UITraitCollection(preferredContentSizeCategory: .large) + ) + + let currentBodyFont = UIFont.preferredFont( + forTextStyle: .body, + compatibleWith: UITraitCollection.current + ) + + let fontScale = currentBodyFont.pointSize / defaultBodyFont.pointSize + + self.setAmplitudeProperty(key: UserPropertyKey.accessibilityFontScale.rawValue, value: fontScale) + } + func setRemoteConfigUserProperties(_ keysAndValues: [String: Any]) { Amplitude.instance().setUserProperties(keysAndValues) Crashlytics.crashlytics().setCustomKeysAndValues(keysAndValues) @@ -167,5 +186,7 @@ final class AnalyticsUserProperties: ABAnalyticsServiceProtocol { case screenOrientation = "screen_orientation" case applicationID = "application_id" case isNightModeEnabled = "is_night_mode_enabled" + case isAccessibilityScreenReaderEnabled = "accessibility_screen_reader_enabled" + case accessibilityFontScale = "accessibility_font_scale" } } diff --git a/Stepic/Legacy/AppDelegate.swift b/Stepic/Legacy/AppDelegate.swift index 716d286e52..0c1199c3bd 100644 --- a/Stepic/Legacy/AppDelegate.swift +++ b/Stepic/Legacy/AppDelegate.swift @@ -60,6 +60,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { AnalyticsUserProperties.shared.setApplicationID(id: Bundle.main.bundleIdentifier!) AnalyticsUserProperties.shared.updateUserID() AnalyticsUserProperties.shared.updateIsDarkModeEnabled() + AnalyticsUserProperties.shared.updateAccessibilityFontScale() + AnalyticsUserProperties.shared.updateAccessibilityIsVoiceOverRunning() NotificationsBadgesManager.shared.setup()