2020-03-31 14:31:34 -07:00
|
|
|
//
|
|
|
|
|
// AnalyticsManager.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 3/31/20.
|
|
|
|
|
// Copyright © 2020 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
2020-09-03 16:39:08 -07:00
|
|
|
import AltStoreCore
|
|
|
|
|
|
2020-03-31 14:31:34 -07:00
|
|
|
import AppCenter
|
|
|
|
|
import AppCenterAnalytics
|
|
|
|
|
import AppCenterCrashes
|
|
|
|
|
|
2022-12-03 17:21:44 -05:00
|
|
|
private let appCenterAppSecret = "73532d3e-e573-4693-99a4-9f85840bbb44"
|
2020-04-09 12:18:17 -07:00
|
|
|
|
2020-03-31 14:31:34 -07:00
|
|
|
extension AnalyticsManager
|
|
|
|
|
{
|
|
|
|
|
enum EventProperty: String
|
|
|
|
|
{
|
|
|
|
|
case name
|
|
|
|
|
case bundleIdentifier
|
|
|
|
|
case developerName
|
|
|
|
|
case version
|
2023-05-18 14:51:26 -05:00
|
|
|
case buildVersion
|
2020-03-31 14:31:34 -07:00
|
|
|
case size
|
|
|
|
|
case tintColor
|
|
|
|
|
case sourceIdentifier
|
|
|
|
|
case sourceURL
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Event
|
|
|
|
|
{
|
|
|
|
|
case installedApp(InstalledApp)
|
|
|
|
|
case updatedApp(InstalledApp)
|
|
|
|
|
case refreshedApp(InstalledApp)
|
|
|
|
|
|
|
|
|
|
var name: String {
|
|
|
|
|
switch self
|
|
|
|
|
{
|
|
|
|
|
case .installedApp: return "installed_app"
|
|
|
|
|
case .updatedApp: return "updated_app"
|
|
|
|
|
case .refreshedApp: return "refreshed_app"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var properties: [EventProperty: String] {
|
|
|
|
|
let properties: [EventProperty: String?]
|
|
|
|
|
|
|
|
|
|
switch self
|
|
|
|
|
{
|
|
|
|
|
case .installedApp(let app), .updatedApp(let app), .refreshedApp(let app):
|
|
|
|
|
let appBundleURL = InstalledApp.fileURL(for: app)
|
|
|
|
|
let appBundleSize = FileManager.default.directorySize(at: appBundleURL)
|
|
|
|
|
|
|
|
|
|
properties = [
|
|
|
|
|
.name: app.name,
|
|
|
|
|
.bundleIdentifier: app.bundleIdentifier,
|
|
|
|
|
.developerName: app.storeApp?.developerName,
|
|
|
|
|
.version: app.version,
|
2023-05-18 14:51:26 -05:00
|
|
|
.buildVersion: app.buildVersion,
|
2020-03-31 14:31:34 -07:00
|
|
|
.size: appBundleSize?.description,
|
|
|
|
|
.tintColor: app.storeApp?.tintColor?.hexString,
|
|
|
|
|
.sourceIdentifier: app.storeApp?.sourceIdentifier,
|
|
|
|
|
.sourceURL: app.storeApp?.source?.sourceURL.absoluteString
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return properties.compactMapValues { $0 }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-04 09:52:12 -05:00
|
|
|
final class AnalyticsManager
|
2020-03-31 14:31:34 -07:00
|
|
|
{
|
|
|
|
|
static let shared = AnalyticsManager()
|
|
|
|
|
|
|
|
|
|
private init()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension AnalyticsManager
|
|
|
|
|
{
|
|
|
|
|
func start()
|
|
|
|
|
{
|
2021-07-21 13:20:14 -07:00
|
|
|
AppCenter.start(withAppSecret: appCenterAppSecret, services: [
|
|
|
|
|
Analytics.self,
|
|
|
|
|
Crashes.self
|
2020-03-31 14:31:34 -07:00
|
|
|
])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func trackEvent(_ event: Event)
|
|
|
|
|
{
|
|
|
|
|
let properties = event.properties.reduce(into: [:]) { (properties, item) in
|
|
|
|
|
properties[item.key.rawValue] = item.value
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 13:20:14 -07:00
|
|
|
Analytics.trackEvent(event.name, withProperties: properties)
|
2020-03-31 14:31:34 -07:00
|
|
|
}
|
|
|
|
|
}
|