Skip to content

Commit

Permalink
Analytics accessibility (#1142)
Browse files Browse the repository at this point in the history
* Report isVoiceOverRunning

* Report fontScale

* Refactor rename
  • Loading branch information
ivan-magda authored Mar 31, 2022
1 parent 1b36899 commit 93ba06b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
39 changes: 30 additions & 9 deletions Stepic/Legacy/Analytics/AnalyticsUserProperties.swift
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
2 changes: 2 additions & 0 deletions Stepic/Legacy/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 93ba06b

Please sign in to comment.