Skip to content

Commit

Permalink
refactor: move analytics abstractions to shared (#658)
Browse files Browse the repository at this point in the history
* refactor: move analytics abstractions to shared

* remove unnecessary class_name parameter
  • Loading branch information
boringcactus authored Jan 17, 2025
1 parent e73cff1 commit ac5fdb3
Show file tree
Hide file tree
Showing 38 changed files with 319 additions and 468 deletions.
44 changes: 4 additions & 40 deletions iosApp/iosApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

39 changes: 0 additions & 39 deletions iosApp/iosApp/Analytics/AlertDetailsAnalytics.swift

This file was deleted.

36 changes: 36 additions & 0 deletions iosApp/iosApp/Analytics/AnalyticsExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AnalyticsExtensions.swift
// iosApp
//
// Created by Horn, Melody on 2025-01-14.
// Copyright © 2025 MBTA. All rights reserved.
//

import CoreLocation
import shared
import SwiftUI

extension Analytics {
func recordSession(colorScheme: ColorScheme) {
let analyticsColorScheme: AnalyticsColorScheme = switch colorScheme {
case .light: .light
case .dark: .dark
@unknown default: .unknown
}
recordSession(colorScheme: analyticsColorScheme)
}

func recordSession(locationAccess: CLAuthorizationStatus, locationAccuracy: CLAccuracyAuthorization) {
let locationAllowed = switch locationAccess {
case .authorizedAlways, .authorizedWhenInUse: true
case .notDetermined, .denied, .restricted: false
@unknown default: false
}
let locationAccess: AnalyticsLocationAccess = switch (locationAllowed, locationAccuracy) {
case (true, .fullAccuracy): .precise
case (true, _): .approximate
case (false, _): .off
}
recordSession(locationAccess: locationAccess)
}
}
17 changes: 8 additions & 9 deletions iosApp/iosApp/Analytics/AnalyticsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@

import FirebaseAnalytics
import Foundation
import shared

class AnalyticsProvider {
class AnalyticsProvider: shared.Analytics {
static let shared = AnalyticsProvider()

/**
* The `file` param is automatically populated with the call sites file path which we parse the class name from.
* e.g.: `NearbyTransitAnalytics`
*/
func logEvent(_ name: String, parameters: [String: Any] = [:], file: String = #file) {
var params = parameters
params["class_name"] = URL(string: file)?.deletingPathExtension().lastPathComponent
Analytics.logEvent(name, parameters: params)
override func logEvent(name: String, parameters: [String: String]) {
FirebaseAnalytics.Analytics.logEvent(name, parameters: parameters)
}

override func setUserProperty(name: String, value: String) {
FirebaseAnalytics.Analytics.setUserProperty(value, forName: name)
}
}
57 changes: 0 additions & 57 deletions iosApp/iosApp/Analytics/DestinationRowAnalytics.swift

This file was deleted.

27 changes: 0 additions & 27 deletions iosApp/iosApp/Analytics/MapAnalytics.swift

This file was deleted.

30 changes: 0 additions & 30 deletions iosApp/iosApp/Analytics/NearbyTransitAnalytics.swift

This file was deleted.

33 changes: 0 additions & 33 deletions iosApp/iosApp/Analytics/ScreenTracker.swift

This file was deleted.

19 changes: 0 additions & 19 deletions iosApp/iosApp/Analytics/SearchAnalytics.swift

This file was deleted.

59 changes: 0 additions & 59 deletions iosApp/iosApp/Analytics/SessionAnalytics.swift

This file was deleted.

38 changes: 0 additions & 38 deletions iosApp/iosApp/Analytics/StopDetailsAnalytics.swift

This file was deleted.

Loading

0 comments on commit ac5fdb3

Please sign in to comment.